[ADD] player gameover check
This commit is contained in:
31
src/main.c
31
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 &&
|
||||
|
||||
Reference in New Issue
Block a user