commit df47a034427994de8c0e81748bf6c53b0931b203
parent 064789f536b44856af8db1738ba863cd894aa419
Author: bsandro <email@bsandro.tech>
Date: Wed, 23 Nov 2022 00:28:02 +0200
Fixed the bug when you can penetrate the ceiling and fly over to the Moon.
Diffstat:
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/main.c b/main.c
@@ -22,6 +22,7 @@
#define GAME_COLUMN_WIDTH 90
#define GAME_COLUMN_HEIGHT 200
#define GAME_BOOST_ACCEL -500
+#define GAME_CEILING 20
static float s_dpi_scale;
@@ -89,7 +90,7 @@ void draw_game(uint64_t ftime, struct game_t *game) {
}
// top border
- if (game->ship.rect.y < 50 && game->ship.velocity < 0) {
+ if (game->ship.rect.y < GAME_CEILING * s_dpi_scale && game->ship.velocity < 0) {
game->ship.velocity = 0;
}
@@ -270,7 +271,9 @@ int main(int argc, char *argv[]) {
}
if (event.key.keysym.sym == SDLK_SPACE) {
if (game.state == GAME_STATE_RUNNING) {
- game.ship.velocity = GAME_BOOST_ACCEL * s_dpi_scale;
+ if (game.ship.rect.y >= GAME_CEILING * s_dpi_scale) {
+ game.ship.velocity = GAME_BOOST_ACCEL * s_dpi_scale;
+ }
} else { // reset game
game.state = GAME_STATE_RUNNING;
game.ship.velocity = 0;