summaryrefslogtreecommitdiff
path: root/catch.c
diff options
context:
space:
mode:
authorVictor Gamper <victor@wenzeslaus.de>2020-01-27 19:06:50 +0100
committerVictor Gamper <victor@wenzeslaus.de>2020-01-27 19:06:50 +0100
commit562df1c63ab343aedd0249a0af391541c3890899 (patch)
tree2be34c103dfd7be543eb95000253780876bbd338 /catch.c
parent6562a7be49070454f426f52845f77165a93a4a02 (diff)
downloadc-catch-562df1c63ab343aedd0249a0af391541c3890899.tar.gz
c-catch-562df1c63ab343aedd0249a0af391541c3890899.zip
Added a game over screen
Diffstat (limited to 'catch.c')
-rw-r--r--catch.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/catch.c b/catch.c
index 4e3d232..667a5b6 100644
--- a/catch.c
+++ b/catch.c
@@ -189,6 +189,16 @@ int main(int argc, char* argv[]) {
length = strlen(score_s) + 1;
Font_DrawString(screen, screen->w - length * 8, 15, score_s);
}
+ else if(state == STATE_GAME_OVER) {
+ Font_DrawString(screen, screen->w/2-36, 150, "GAME OVER");
+ Font_DrawString(screen, screen->w/2-96, 200, "Press Return to continue");
+
+ // draw the score
+ char score_s[50]; // TODO this could create a buffer overflow
+ sprintf(score_s, "Score: %d", score);
+ int length = strlen(score_s) + 1;
+ Font_DrawString(screen, screen->w /2 - length * 4, 180, score_s);
+ }
//Font_DrawString(screen, 0,5, "ABCDEFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstufwxyz\n 01234567890: +");
Font_DrawString(screen, screen->h-10, 5, "");
@@ -217,7 +227,6 @@ int main(int argc, char* argv[]) {
}
void gameRoutine() {
- if(keyPressed[SDLK_BACKSPACE]) state = STATE_MAIN_MENU;
bool charge = keyPressed[SDLK_SPACE] && (state == STATE_GAME);
// do the physics calculation
@@ -283,7 +292,7 @@ void gameRoutine() {
ticks_to_next_second = TICKS_PER_SECOND;
time_left--;
if(time_left<0)
- state = STATE_MAIN_MENU;
+ state = STATE_GAME_OVER;
}
for(int i = 0; i<BIRD_COUNT; i++) {
@@ -322,6 +331,15 @@ void gameRoutine() {
}
}
}
+
+ // the game over state
+ else
+ if(state == STATE_GAME_OVER) {
+ if(keyPressed[SDLK_RETURN]) {
+ state = STATE_MAIN_MENU;
+ keyPressed[SDLK_RETURN] = false;
+ }
+ }
}
bool checkCollision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) {