-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.c
54 lines (45 loc) · 973 Bytes
/
game.c
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
// Filename: game.c
#include "game.h"
#include "game_ext.h"
#define BOX_SIZE 10
struct Game {
int width;
int height;
int x;
int y;
};
static struct Game game = {0};
void game_init(int width, int height) {
ext_log("Game initialized");
// Let's initialize the box position into the middle of the screen
game.x = width / 2;
game.y = height / 2;
game.width = width;
game.height = height;
}
// For testing just draw a box of 10x10 at x,y
void game_render(void) {
// https://www.nordtheme.com/
int bckg = 0x2E3440FF; // 0xRRGGBBAA
int forg = 0xD8DEE9FF;
// Clean background
ext_draw_rectangle(0, 0, game.width, game.height, bckg);
// And draw a box
ext_draw_rectangle(game.x, game.y, BOX_SIZE, BOX_SIZE, forg);
}
void game_keydown(int keycode) {
switch (keycode) {
case Left:
game.x -= 1;
break;
case Up:
game.y -= 1;
break;
case Right:
game.x += 1;
break;
case Down:
game.y += 1;
break;
}
}