aboutsummaryrefslogtreecommitdiff
path: root/game.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-10-05 17:11:53 +1000
committerquou <quou@disroot.org>2024-10-05 17:11:53 +1000
commite95936bb0e68479864a86e121a749d45ee7b0a78 (patch)
tree1a9ab2d8f31dc0138fb07de7c370cafecb80836a /game.c
parent964dfd035bf2eb458a549c7fca84d60cd6f71c9d (diff)
game over
Diffstat (limited to 'game.c')
-rw-r--r--game.c58
1 files changed, 56 insertions, 2 deletions
diff --git a/game.c b/game.c
index 07b0264..f37473d 100644
--- a/game.c
+++ b/game.c
@@ -27,6 +27,20 @@ void update_menu(Game* g, App* a) {
}
}
+void update_gameover(Game* g, App* a) {
+ int i;
+ for (i = 0; i < btn_count; i++)
+ if (a->btn_states[i] & btn_state_pressed) {
+ queue_gs(g, game_state_fade_out);
+ queue_gs(g, game_state_reset);
+ queue_gs(g, game_state_generate);
+ queue_gs(g, game_state_fade_in);
+ queue_gs(g, game_state_play);
+ g->want_next = 1;
+ return;
+ }
+}
+
void queue_gs(Game* g, Game_State s) {
assert(g->qt < game_max_state_queue);
g->sq[g->qt++] = s;
@@ -45,7 +59,7 @@ void next_gs(Game* g) {
on_transition(g);
}
-void detect_next(Game* g, const World* w) {
+int detect_next(Game* g, const World* w) {
const Player* p = &w->player;
if (p->y < 0) /* next level */ {
queue_gs(g, game_state_fade_out);
@@ -53,7 +67,22 @@ void detect_next(Game* g, const World* w) {
queue_gs(g, game_state_fade_in);
queue_gs(g, game_state_play);
g->want_next = 1;
+ return 1;
+ }
+ return 0;
+}
+
+int detect_gameover(Game* g, const World* w) {
+ const Player* p = &w->player;
+ if (p->hp <= 0) {
+ queue_gs(g, game_state_fade_out);
+ queue_gs(g, game_state_generate);
+ queue_gs(g, game_state_fade_in);
+ queue_gs(g, game_state_over);
+ g->want_next = 1;
+ return 1;
}
+ return 0;
}
void update_game(Game* g, App* a) {
@@ -67,6 +96,7 @@ void update_game(Game* g, App* a) {
update_menu(g, a);
break;
case game_state_over:
+ update_gameover(g, a);
break;
case game_state_fade_in:
fa = get_animation(asset_id_fade_in_anm);
@@ -82,13 +112,18 @@ void update_game(Game* g, App* a) {
else
g->want_next = 1;
break;
+ case game_state_reset:
+ init_world(&g->w);
+ g->want_next = 1;
+ break;
case game_state_generate:
generate_floor(&g->w.map, &g->w);
g->want_next = 1;
break;
case game_state_play:
update_world(&g->w, a);
- detect_next(g, &g->w);
+ if (detect_next(g, &g->w)) break;
+ detect_gameover(g, &g->w);
break;
}
g->frame++;
@@ -131,12 +166,31 @@ void ren_menu(const Game* g, Renderer* r) {
);
}
+void ren_gameover(const Game* g, Renderer* r) {
+ const Bitmap* bm = get_bitmap(asset_id_hud_img);
+ const int hv = viewport_w >> 1;
+ ren_text(
+ r,
+ hv - 32,
+ 100,
+ "G A M E O V E R"
+ );
+ if (g->frame & 3)
+ ren_text(
+ r,
+ hv - 38,
+ 155,
+ "ANY BUTTON TO RESET"
+ );
+}
+
void ren_state(const Game* g, Game_State s, Renderer* r) {
switch (s) {
case game_state_menu:
ren_menu(g, r);
break;
case game_state_over:
+ ren_gameover(g, r);
break;
case game_state_generate:
break;