-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
62 lines (54 loc) · 1.48 KB
/
utils.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
55
56
57
58
59
60
61
62
#include "utils.h"
bool is_block(uint8_t tile) {
return (tile > 0) && (tile != WALL_TILE);
}
uint8_t cap_x(uint8_t coord) {
return MIN(MAX(0, coord), (SIZE_X - 1));
}
uint8_t cap_y(uint8_t coord) {
return MIN(MAX(0, coord), (SIZE_Y - 1));
}
bool is_state_pause(State gameState) {
return ((gameState < ABOUT) || (gameState >= PAUSED));
}
void copy_level(PlayGround target, PlayGround source) {
memcpy(target, source, sizeof(uint8_t) * SIZE_X * SIZE_Y);
}
void clear_board(PlayGround* ani) {
memset(ani, '\0', sizeof(uint8_t) * SIZE_X * SIZE_Y);
}
void randomize_bg(BackGround* bg) {
memset(bg, 0, sizeof(uint8_t) * SIZE_X_BG * SIZE_Y_BG);
int r;
uint8_t ra, x, y;
for(y = 0; y < SIZE_Y_BG; y++) {
for(x = 0; x < SIZE_X_BG; x++) {
do {
r = rand();
ra = (r % 7) + 1;
if(y > 0) {
if((*bg)[y - 1][x] == ra) {
ra = 0;
}
}
if(x > 0) {
if((*bg)[y][x - 1] == ra) {
ra = 0;
}
}
} while(ra == 0);
(*bg)[y][x] = ra;
}
}
}
const char* game_mode_label(GameMode mode) {
switch(mode) {
case CONTINUE:
return "Continue";
case CUSTOM:
return "Custom";
default:
case NEW_GAME:
return "New Game";
}
}