A retro platform game
git clone git://soophie.de/freezo
Binary file
55
}57
void game_update(game_t *game) {58
bool do_toggle_mute = false;59
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) {60
pos_t mouse_pos = GetMousePosition();61
rect_t mouse_rect = {62
.x = mouse_pos.x,63
.y = mouse_pos.y,64
.width = 1,65
.height = 1,66
};67
rect_t mute_button_rect = {68
.x = TILE_WIDTH / 2.0,69
.y = WINDOW_HEIGHT - TILE_HEIGHT - TILE_HEIGHT / 2.0,70
.width = TILE_WIDTH,71
.height = TILE_HEIGHT,72
};73
rect_t pause_button_rect = {74
.x = WINDOW_WIDTH - TILE_WIDTH - TILE_WIDTH / 2.0,75
.y = WINDOW_HEIGHT - TILE_HEIGHT - TILE_HEIGHT / 2.0,76
.width = TILE_WIDTH,77
.height = TILE_HEIGHT,78
};79
if (rect_collide(mouse_rect, mute_button_rect)) {80
do_toggle_mute = true;81
}82
if (!game->victory && !game->defeat) {83
if (rect_collide(mouse_rect, pause_button_rect)) {84
switch (game->state) {85
case STATE_GAME:86
game->state = STATE_MENU;87
break;88
case STATE_MENU:89
game->state = STATE_GAME;90
break;91
}92
}93
}94
}95
if (IsKeyPressed(KEY_M)) {96
do_toggle_mute = true;97
}98
if (do_toggle_mute) {99
game->is_muted = !game->is_muted;100
if (game->is_muted) {101
SetSoundVolume(game->assets.track, 0.0f);
280
for (; i < game->player->max_health / 2; i++) {281
DrawTextureRec(game->assets.tiles, texture_rect(2, 1, TILE_WIDTH, TILE_HEIGHT), (pos_t) { TILE_WIDTH / 2.0 + i * (TILE_WIDTH + TILE_WIDTH / 4.0), TILE_WIDTH / 2.0 }, WHITE);282
}243
if (game->is_muted) {244
DrawTextureRec(game->assets.tiles, texture_rect(5, 1, TILE_WIDTH, TILE_HEIGHT), (pos_t) { TILE_WIDTH / 2.0, WINDOW_HEIGHT - TILE_HEIGHT - TILE_HEIGHT / 2.0 }, WHITE);245
}246
else {247
DrawTextureRec(game->assets.tiles, texture_rect(4, 1, TILE_WIDTH, TILE_HEIGHT), (pos_t) { TILE_WIDTH / 2.0, WINDOW_HEIGHT - TILE_HEIGHT - TILE_HEIGHT / 2.0 }, WHITE);248
}283
char xp_text[10];284
snprintf(xp_text, 10, "%dXP", game->xp);285
pos_t xp_pos = (pos_t) {
298
if (game->state == STATE_MENU) {299
menu_draw(game->menu, game);300
}301
if (game->is_muted) {302
DrawTextureRec(game->assets.tiles, texture_rect(5, 1, TILE_WIDTH, TILE_HEIGHT), (pos_t) { TILE_WIDTH / 2.0, WINDOW_HEIGHT - TILE_HEIGHT - TILE_HEIGHT / 2.0 }, WHITE);303
}304
else {305
DrawTextureRec(game->assets.tiles, texture_rect(4, 1, TILE_WIDTH, TILE_HEIGHT), (pos_t) { TILE_WIDTH / 2.0, WINDOW_HEIGHT - TILE_HEIGHT - TILE_HEIGHT / 2.0 }, WHITE);306
}307
if (game->state == STATE_GAME) {308
if (game->victory || game->defeat) {309
DrawTextureRec(game->assets.tiles, texture_rect(8, 1, TILE_WIDTH, TILE_HEIGHT), (pos_t) { WINDOW_WIDTH - TILE_WIDTH - TILE_WIDTH / 2.0, WINDOW_HEIGHT - TILE_HEIGHT - TILE_HEIGHT / 2.0 }, WHITE);310
}311
else {312
DrawTextureRec(game->assets.tiles, texture_rect(6, 1, TILE_WIDTH, TILE_HEIGHT), (pos_t) { WINDOW_WIDTH - TILE_WIDTH - TILE_WIDTH / 2.0, WINDOW_HEIGHT - TILE_HEIGHT - TILE_HEIGHT / 2.0 }, WHITE);313
}314
}315
else {316
DrawTextureRec(game->assets.tiles, texture_rect(7, 1, TILE_WIDTH, TILE_HEIGHT), (pos_t) { WINDOW_WIDTH - TILE_WIDTH - TILE_WIDTH / 2.0, WINDOW_HEIGHT - TILE_HEIGHT - TILE_HEIGHT / 2.0 }, WHITE);317
}318
EndDrawing();319
}
14
}16
void menu_update(menu_t *menu, game_t *game) {17
UNUSED(menu);18
UNUSED(game);17
(void) menu;18
if (IsKeyPressed(KEY_ESCAPE)) {19
game->state = STATE_GAME;20
}22
if (IsKeyPressed(KEY_W)) {23
if (menu->idx > 0) {24
menu->idx--;25
}26
}27
if (IsKeyPressed(KEY_S)) {28
if (menu->idx < 2) {29
menu->idx++;30
}31
}32
if (IsKeyPressed(KEY_ENTER)) {33
switch (menu->idx) {34
case 0:35
game->state = STATE_GAME;36
break;37
case 1: {38
if (game->level != LEVEL_NULL) {39
level_e level = game->level->type;40
level_unload(game);41
level_load(game, level);42
game->victory = false;43
game->defeat = false;44
}45
game->state = STATE_GAME;46
break;47
}48
case 2:49
game->quit = true;50
break;51
default:52
break;53
}21
if (IsKeyPressed(KEY_Q)) {22
game->quit = true;23
}24
// if (IsKeyPressed(KEY_W)) {25
// if (menu->idx > 0) {26
// menu->idx--;27
// }28
// }29
// if (IsKeyPressed(KEY_S)) {30
// if (menu->idx < 2) {31
// menu->idx++;32
// }33
// }34
// if (IsKeyPressed(KEY_ENTER)) {35
// switch (menu->idx) {36
// case 0:37
// game->state = STATE_GAME;38
// break;39
// case 1: {40
// if (game->level != LEVEL_NULL) {41
// level_e level = game->level->type;42
// int max_health = game->player->max_health;43
// level_unload(game);44
// level_load(game, level);45
// game->player->max_health = max_health;46
// game->player->health = max_health;47
// game->victory = false;48
// game->defeat = false;49
// }50
// game->state = STATE_GAME;51
// break;52
// }53
// case 2:54
// game->quit = true;55
// break;56
// default:57
// break;58
// }59
// }60
}62
void menu_draw(menu_t *menu, game_t *game) {58
UNUSED(menu);59
UNUSED(game);60
int shift = 20;63
(void) menu;64
(void) game;65
DrawRectangle(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, (Color) { 0, 0, 0, 125 });62
DrawRectangle(WINDOW_WIDTH / 2.0 - 100, WINDOW_HEIGHT / 2.0 - 75 + shift - 10, 200, 150, (Color) { 50, 50, 50, 255 });63
DrawTextureRec(64
game->assets.images,65
(rect_t) { 0, 0, 56 * SCALE, 28 * SCALE },66
pos_snap((pos_t) { WINDOW_WIDTH / 2.0 - 3.5 * TILE_WIDTH, WINDOW_HEIGHT / 2.0 - 115 }),67
WHITE68
);69
text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 - 30 + shift }, "RESUME", TEXT_ALIGNMENT_CENTER, game);70
text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 + shift }, "RESTART", TEXT_ALIGNMENT_CENTER, game);71
text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 + 30 + shift }, "QUIT", TEXT_ALIGNMENT_CENTER, game);72
pos_t cursor_pos = (pos_t) {73
.x = WINDOW_WIDTH / 2.0 - 70,74
.y = WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 - 30 + menu->idx * 30 + shift,75
};76
DrawTextureRec(77
game->assets.font,78
texture_rect(0, 4, FONT_WIDTH, FONT_HEIGHT),79
pos_snap(cursor_pos),80
WHITE81
);66
// int shift = 20;67
// DrawRectangle(WINDOW_WIDTH / 2.0 - 100, WINDOW_HEIGHT / 2.0 - 75 + shift - 10, 200, 150, (Color) { 50, 50, 50, 255 });68
// DrawTextureRec(69
// game->assets.images,70
// (rect_t) { 0, 0, 56 * SCALE, 28 * SCALE },71
// pos_snap((pos_t) { WINDOW_WIDTH / 2.0 - 3.5 * TILE_WIDTH, WINDOW_HEIGHT / 2.0 - 115 }),72
// WHITE73
// );74
// text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 - 30 + shift }, "RESUME", TEXT_ALIGNMENT_CENTER, game);75
// text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 + shift }, "RESTART", TEXT_ALIGNMENT_CENTER, game);76
// text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 + 30 + shift }, "QUIT", TEXT_ALIGNMENT_CENTER, game);77
// pos_t cursor_pos = (pos_t) {78
// .x = WINDOW_WIDTH / 2.0 - 70,79
// .y = WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 - 30 + menu->idx * 30 + shift,80
// };81
// DrawTextureRec(82
// game->assets.font,83
// texture_rect(0, 4, FONT_WIDTH, FONT_HEIGHT),84
// pos_snap(cursor_pos),85
// WHITE86
// );87
}89
void menu_free(menu_t *menu) {