A retro platform game
git clone git://soophie.de/freezo
diff --git a/assets/tiles.png b/assets/tiles.png
index a3474b3..8f3d977 100644
Binary files a/assets/tiles.png and b/assets/tiles.png differ
diff --git a/src/game.c b/src/game.c
index 9f4ae24..9edf71d 100644
--- a/src/game.c
+++ b/src/game.c
1
@@ -55,7 +55,47 @@ game_t *game_create(void) {2
}4
void game_update(game_t *game) {5
+ bool do_toggle_mute = false;6
+ if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) {7
+ pos_t mouse_pos = GetMousePosition();8
+ rect_t mouse_rect = {9
+ .x = mouse_pos.x,10
+ .y = mouse_pos.y,11
+ .width = 1,12
+ .height = 1,13
+ };14
+ rect_t mute_button_rect = {15
+ .x = TILE_WIDTH / 2.0,16
+ .y = WINDOW_HEIGHT - TILE_HEIGHT - TILE_HEIGHT / 2.0,17
+ .width = TILE_WIDTH,18
+ .height = TILE_HEIGHT,19
+ };20
+ rect_t pause_button_rect = {21
+ .x = WINDOW_WIDTH - TILE_WIDTH - TILE_WIDTH / 2.0,22
+ .y = WINDOW_HEIGHT - TILE_HEIGHT - TILE_HEIGHT / 2.0,23
+ .width = TILE_WIDTH,24
+ .height = TILE_HEIGHT,25
+ };26
+ if (rect_collide(mouse_rect, mute_button_rect)) {27
+ do_toggle_mute = true;28
+ }29
+ if (!game->victory && !game->defeat) {30
+ if (rect_collide(mouse_rect, pause_button_rect)) {31
+ switch (game->state) {32
+ case STATE_GAME:33
+ game->state = STATE_MENU;34
+ break;35
+ case STATE_MENU:36
+ game->state = STATE_GAME;37
+ break;38
+ }39
+ }40
+ }41
+ }42
if (IsKeyPressed(KEY_M)) {43
+ do_toggle_mute = true;44
+ }45
+ if (do_toggle_mute) {46
game->is_muted = !game->is_muted;47
if (game->is_muted) {48
SetSoundVolume(game->assets.track, 0.0f);49
@@ -240,12 +280,6 @@ void game_draw(game_t *game) {50
for (; i < game->player->max_health / 2; i++) {51
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);52
}53
- if (game->is_muted) {54
- 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);55
- }56
- else {57
- 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);58
- }59
char xp_text[10];60
snprintf(xp_text, 10, "%dXP", game->xp);61
pos_t xp_pos = (pos_t) {62
@@ -264,6 +298,23 @@ void game_draw(game_t *game) {63
if (game->state == STATE_MENU) {64
menu_draw(game->menu, game);65
}66
+ if (game->is_muted) {67
+ 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);68
+ }69
+ else {70
+ 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);71
+ }72
+ if (game->state == STATE_GAME) {73
+ if (game->victory || game->defeat) {74
+ 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);75
+ }76
+ else {77
+ 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);78
+ }79
+ }80
+ else {81
+ 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);82
+ }83
EndDrawing();84
}
diff --git a/src/menu.c b/src/menu.c
index 09f6716..01e27f7 100644
--- a/src/menu.c
+++ b/src/menu.c
1
@@ -14,71 +14,76 @@ menu_t *menu_create(void) {2
}4
void menu_update(menu_t *menu, game_t *game) {5
- UNUSED(menu);6
- UNUSED(game);7
+ (void) menu;8
if (IsKeyPressed(KEY_ESCAPE)) {9
game->state = STATE_GAME;10
}11
- if (IsKeyPressed(KEY_W)) {12
- if (menu->idx > 0) {13
- menu->idx--;14
- }15
- }16
- if (IsKeyPressed(KEY_S)) {17
- if (menu->idx < 2) {18
- menu->idx++;19
- }20
- }21
- if (IsKeyPressed(KEY_ENTER)) {22
- switch (menu->idx) {23
- case 0:24
- game->state = STATE_GAME;25
- break;26
- case 1: {27
- if (game->level != LEVEL_NULL) {28
- level_e level = game->level->type;29
- level_unload(game);30
- level_load(game, level);31
- game->victory = false;32
- game->defeat = false;33
- }34
- game->state = STATE_GAME;35
- break;36
- }37
- case 2:38
- game->quit = true;39
- break;40
- default:41
- break;42
- }43
+ if (IsKeyPressed(KEY_Q)) {44
+ game->quit = true;45
}46
+ // if (IsKeyPressed(KEY_W)) {47
+ // if (menu->idx > 0) {48
+ // menu->idx--;49
+ // }50
+ // }51
+ // if (IsKeyPressed(KEY_S)) {52
+ // if (menu->idx < 2) {53
+ // menu->idx++;54
+ // }55
+ // }56
+ // if (IsKeyPressed(KEY_ENTER)) {57
+ // switch (menu->idx) {58
+ // case 0:59
+ // game->state = STATE_GAME;60
+ // break;61
+ // case 1: {62
+ // if (game->level != LEVEL_NULL) {63
+ // level_e level = game->level->type;64
+ // int max_health = game->player->max_health;65
+ // level_unload(game);66
+ // level_load(game, level);67
+ // game->player->max_health = max_health;68
+ // game->player->health = max_health;69
+ // game->victory = false;70
+ // game->defeat = false;71
+ // }72
+ // game->state = STATE_GAME;73
+ // break;74
+ // }75
+ // case 2:76
+ // game->quit = true;77
+ // break;78
+ // default:79
+ // break;80
+ // }81
+ // }82
}84
void menu_draw(menu_t *menu, game_t *game) {85
- UNUSED(menu);86
- UNUSED(game);87
- int shift = 20;88
+ (void) menu;89
+ (void) game;90
DrawRectangle(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, (Color) { 0, 0, 0, 125 });91
- DrawRectangle(WINDOW_WIDTH / 2.0 - 100, WINDOW_HEIGHT / 2.0 - 75 + shift - 10, 200, 150, (Color) { 50, 50, 50, 255 });92
- DrawTextureRec(93
- game->assets.images,94
- (rect_t) { 0, 0, 56 * SCALE, 28 * SCALE },95
- pos_snap((pos_t) { WINDOW_WIDTH / 2.0 - 3.5 * TILE_WIDTH, WINDOW_HEIGHT / 2.0 - 115 }),96
- WHITE97
- );98
- text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 - 30 + shift }, "RESUME", TEXT_ALIGNMENT_CENTER, game);99
- text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 + shift }, "RESTART", TEXT_ALIGNMENT_CENTER, game);100
- text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 + 30 + shift }, "QUIT", TEXT_ALIGNMENT_CENTER, game);101
- pos_t cursor_pos = (pos_t) {102
- .x = WINDOW_WIDTH / 2.0 - 70,103
- .y = WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 - 30 + menu->idx * 30 + shift,104
- };105
- DrawTextureRec(106
- game->assets.font,107
- texture_rect(0, 4, FONT_WIDTH, FONT_HEIGHT),108
- pos_snap(cursor_pos),109
- WHITE110
- );111
+ // int shift = 20;112
+ // DrawRectangle(WINDOW_WIDTH / 2.0 - 100, WINDOW_HEIGHT / 2.0 - 75 + shift - 10, 200, 150, (Color) { 50, 50, 50, 255 });113
+ // DrawTextureRec(114
+ // game->assets.images,115
+ // (rect_t) { 0, 0, 56 * SCALE, 28 * SCALE },116
+ // pos_snap((pos_t) { WINDOW_WIDTH / 2.0 - 3.5 * TILE_WIDTH, WINDOW_HEIGHT / 2.0 - 115 }),117
+ // WHITE118
+ // );119
+ // text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 - 30 + shift }, "RESUME", TEXT_ALIGNMENT_CENTER, game);120
+ // text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 + shift }, "RESTART", TEXT_ALIGNMENT_CENTER, game);121
+ // text_draw((pos_t) { WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 + 30 + shift }, "QUIT", TEXT_ALIGNMENT_CENTER, game);122
+ // pos_t cursor_pos = (pos_t) {123
+ // .x = WINDOW_WIDTH / 2.0 - 70,124
+ // .y = WINDOW_HEIGHT / 2.0 - FONT_HEIGHT / 2.0 - 30 + menu->idx * 30 + shift,125
+ // };126
+ // DrawTextureRec(127
+ // game->assets.font,128
+ // texture_rect(0, 4, FONT_WIDTH, FONT_HEIGHT),129
+ // pos_snap(cursor_pos),130
+ // WHITE131
+ // );132
}134
void menu_free(menu_t *menu) {