-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
63 lines (44 loc) · 1.21 KB
/
Source.cpp
File metadata and controls
63 lines (44 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "dependencies/MiniFB.h"
#include "Definitions.h"
GameMap* gm;// this object will handle most of the game
void keypress(struct mfb_window* window, mfb_key key, mfb_key_mod mod, bool isPressed)
{
if (key == KB_KEY_ESCAPE) {
mfb_close(window);
}
//This will handle the keypress for the movement of player
if (key == KB_KEY_UP || key == KB_KEY_W) {
//for move up
gm->movePlayer(Direction::UP);
}
else if (key == KB_KEY_DOWN || key == KB_KEY_S){
//for move down
gm->movePlayer(Direction::DOWN);
}
else if (key == KB_KEY_RIGHT || key == KB_KEY_D) {
//for move right
gm->movePlayer(Direction::RIGHT);
}
else if (key == KB_KEY_LEFT || key == KB_KEY_A) {
//for move left
gm->movePlayer(Direction::LEFT);
}
//this will handle the keypress for attack
else if (key == KB_KEY_SPACE) {
gm->attackPlayer();
}
}
int main()
{
struct mfb_window* window = mfb_open("Orpheus", WIDTH, HEIGHT);
mfb_set_keyboard_callback(window, keypress); // the bind the keypress callback
uint32_t* framebuffer = (uint32_t*)malloc(HEIGHT * WIDTH * 4);
gm = new GameMap(framebuffer);
if (!window)
return -1;
do
{
mfb_update(window, framebuffer);
} while (mfb_wait_sync(window));
return 0;
}