From e938165647de1c775b17cc4f8f61968ada3a61a5 Mon Sep 17 00:00:00 2001 From: SemvdH Date: Mon, 23 Aug 2021 18:12:07 +0200 Subject: [PATCH] [ADD] player gameover check --- src/main.c | 31 ++++++++++++++++++++++++++++--- src/toolbox/toolbox.c | 1 - 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index 5808b8c..de9a440 100644 --- a/src/main.c +++ b/src/main.c @@ -27,7 +27,8 @@ typedef enum { START, MENU, - GAME + GAME, + GAMEOVER } game_state; uint8_t running = 1, drawing_circle = 0; @@ -137,8 +138,7 @@ uint8_t bullet_hit_enemy(BULLET *bullet, ENEMY_SPRITE *enemy) } /** - * @brief checks the collision for all bullets, also checks for: - * - enemies + * @brief checks the collision for all bullets * */ void check_bullet_collisions() @@ -166,6 +166,18 @@ void check_bullet_collisions() } } +/** + * @brief checks the collision for all enemies with the player + * + * @returns true if there was a collision + */ +SceBool check_player_collisions() +{ + SceBool res = SCE_FALSE; + + +} + // ################################################################ // ------------------------ END COLLISION ------------------ // ################################################################ @@ -262,6 +274,12 @@ void update_game() if (player_y >= SCREEN_HEIGTH) player_y = SCREEN_HEIGTH - 1; + SceBool player_collision = check_player_collisions(); + if (player_collision == SCE_TRUE) + { + current_state = GAMEOVER; + return; + } check_bullet_collisions(); for (int i = 0; i < 255; i++) @@ -283,6 +301,10 @@ void update_game() } } +void update_gameover() +{ +} + void update() { deltaTime = timing_get_deltatime(&sysclock); @@ -314,6 +336,9 @@ void update() case GAME: update_game(); break; + case GAMEOVER: + update_gameover(); + break; } } diff --git a/src/toolbox/toolbox.c b/src/toolbox/toolbox.c index 39520bc..fdfaa63 100644 --- a/src/toolbox/toolbox.c +++ b/src/toolbox/toolbox.c @@ -11,7 +11,6 @@ float toolbox_random_float(float a, float b) uint8_t toolbox_is_collision(float x1, float y1, float width1, float heigth1, float x2, float y2, float width2, float height2) { - //TODO make it work? return x1 - width1 / 2 < x2 + width2 / 2 && x1 + width1 / 2 > x2 - width2 / 2 && y1 - heigth1 / 2 < y2 + height2 / 2 &&