Skip to content

Commit

Permalink
Add Game Over screen. Fix reload ammo logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketGod-git committed Aug 24, 2024
1 parent 7d2fe20 commit 430da4a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 15 deletions.
Binary file modified fap/laser_tag.fap
Binary file not shown.
1 change: 1 addition & 0 deletions game_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ typedef enum {
LaserTagStateSplashScreen,
LaserTagStateTeamSelect,
LaserTagStateGame,
LaserTagStateGameOver,
} LaserTagState;

typedef struct GameState GameState;
Expand Down
75 changes: 61 additions & 14 deletions laser_tag_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,27 @@ static void laser_tag_app_draw_callback(Canvas* canvas, void* context) {
canvas_draw_circle(canvas, 60, 32, 5);
canvas_draw_circle(canvas, 60, 32, 2);

} else if(app->state == LaserTagStateGameOver) {
canvas_clear(canvas);

canvas_set_font(canvas, FontPrimary);

// Display "GAME OVER!" centered on the screen
canvas_draw_str_aligned(canvas, 64, 25, AlignCenter, AlignCenter, "GAME OVER!");

// Add a solid block border around the screen
for(int x = 0; x < 128; x += 8) {
canvas_draw_box(canvas, x, 0, 8, 8);
canvas_draw_box(canvas, x, 56, 8, 8);
}
for(int y = 8; y < 56; y += 8) {
canvas_draw_box(canvas, 0, y, 8, 8);
canvas_draw_box(canvas, 120, y, 8, 8);
}

canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 64, 50, AlignCenter, AlignCenter, "Press OK to Restart");

} else if(app->view) {
FURI_LOG_D(TAG, "Drawing game view");
laser_tag_view_draw(laser_tag_view_get_view(app->view), canvas);
Expand Down Expand Up @@ -222,10 +243,11 @@ void laser_tag_app_handle_hit(LaserTagApp* app) {
FURI_LOG_I(TAG, "Notifying user with vibration");

if(game_state_is_game_over(app->game_state)) {
FURI_LOG_I(TAG, "Game over, playing game over sound");
FURI_LOG_I(TAG, "Game over, switching to Game Over screen");

notification_message(app->notifications, &sequence_error);

app->state = LaserTagStateGameOver;
app->need_redraw = true;
}
}
Expand Down Expand Up @@ -298,18 +320,34 @@ int32_t laser_tag_app(void* p) {
default:
break;
}
} else {
switch(event.key) {
case InputKeyBack:
FURI_LOG_I(TAG, "Back key pressed, exiting");
running = false;
break;
case InputKeyOk:
FURI_LOG_I(TAG, "OK key pressed, firing laser");
laser_tag_app_fire(app);
break;
default:
break;
} else if(app->state == LaserTagStateGameOver) {
if(event.key == InputKeyOk) {
FURI_LOG_I(TAG, "OK key pressed, restarting game");

// Restart game by resetting game state and transitioning to splash screen
game_state_reset(app->game_state);
app->state = LaserTagStateSplashScreen;
app->need_redraw = true;
}
} else if(app->state == LaserTagStateGame) {
if(event.key == InputKeyDown && game_state_get_ammo(app->game_state) == 0) {
// Reload ammo when Down button is pressed and ammo is depleted
FURI_LOG_I(TAG, "Down key pressed, reloading ammo");
game_state_increase_ammo(app->game_state, INITIAL_AMMO);
app->need_redraw = true;
} else {
switch(event.key) {
case InputKeyBack:
FURI_LOG_I(TAG, "Back key pressed, exiting");
running = false;
break;
case InputKeyOk:
FURI_LOG_I(TAG, "OK key pressed, firing laser");
laser_tag_app_fire(app);
break;
default:
break;
}
}
}
}
Expand All @@ -328,7 +366,16 @@ int32_t laser_tag_app(void* p) {
if(game_state_is_game_over(app->game_state)) {
FURI_LOG_I(TAG, "Game over, notifying user with error sequence");
notification_message(app->notifications, &sequence_error);
running = false;
// Stop game logic after game over
app->state = LaserTagStateGameOver;
app->need_redraw = true;
}
} else if(app->state == LaserTagStateGameOver) {
if(event.key == InputKeyOk) {
FURI_LOG_I(TAG, "OK key pressed, restarting game");
game_state_reset(app->game_state);
app->state = LaserTagStateSplashScreen;
app->need_redraw = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion laser_tag_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void laser_tag_view_draw_callback(Canvas* canvas, void* model) {
canvas_draw_box(canvas, 56, 36, (58 * m->ammo) / 100, 8);

if(m->ammo == 0) {
canvas_draw_str_aligned(canvas, 5, 55, AlignLeft, AlignBottom, "Press 'X' to Reload");
canvas_draw_str_aligned(canvas, 5, 55, AlignLeft, AlignBottom, "Press 'Down' to Reload");
}

uint32_t minutes = m->game_time / 60;
Expand Down

0 comments on commit 430da4a

Please sign in to comment.