aboutsummaryrefslogtreecommitdiff
path: root/game.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2023-05-07 21:30:46 +1000
committerquou <quou@disroot.org>2023-05-07 21:30:46 +1000
commitee2ecd8da2b66e0a819f59491ac176fd3efaa92a (patch)
treeede346c6aadc38e986002ca17991156ed65d42d8 /game.c
parent19760d58ea09b9c345a0c845e89143ddcc5d6507 (diff)
Improve the win screen.
Diffstat (limited to 'game.c')
-rw-r--r--game.c137
1 files changed, 126 insertions, 11 deletions
diff --git a/game.c b/game.c
index e741687..dfe83b9 100644
--- a/game.c
+++ b/game.c
@@ -211,8 +211,7 @@ static void gameplay_update(Game* game) {
!game->want_next
) {
if (waver->idx >= get_wave_count() - 1) {
- world->oom = -1;
- game_change_state(game, game_state_dead);
+ game_change_state(game, game_state_win);
}
game->wave_timer = 0;
@@ -322,21 +321,13 @@ static void dead_update(Game* game) {
sprite_system(&game->world);
render_hud(game);
- if (world->oom == 1) {
+ if (world->oom) {
rfont_text(
font,
renderer_w / 2 - 65,
game->menu.y - 15,
"Out of Memory"
);
- } else if (world->oom == -1) {
- rfont_text_col(
- font,
- renderer_w / 2 - 35,
- game->menu.y - 15,
- "YOU WIN",
- make_colour(0xc00000, 255)
- );
} else {
rfont_text(
font,
@@ -352,6 +343,125 @@ static void dead_deinit(Game* game) {
}
+static void win_init(Game* game) {
+ const BM_Font* font;
+ Menu* menu;
+
+ set_song(song_win);
+
+ menu = &game->menu;
+ font = get_default_font();
+ init_menu(menu, game);
+ menu_add(menu, "Main Menu", menu_main_menu, font);
+
+ game->fading = 0;
+ game->fade_frame = 0;
+ game->fade_timer = 0;
+ game->wait_timer = 50;
+ game->wait_timer2 = 20;
+}
+
+static void update_fade(Game* game) {
+ int x, y, w, h, w0, h0;
+ const Bitmap* bitmap;
+ const Animation* animation;
+ const Rectangle* rect;
+
+ bitmap = get_bitmap(asset_id_usr);
+ animation = get_animation(animation_fade);
+ rect = &animation->frames[game->fade_frame];
+
+ w0 = rect->w;
+ h0 = rect->h;
+
+ w = renderer_w / w0;
+ h = renderer_h / h0;
+
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < w; x++) {
+ render_bitmap(bitmap, x * w0, y * h0, rect);
+ }
+ }
+
+ game->fade_timer++;
+ if (game->fade_timer >= animation->slowness) {
+ game->fade_frame++;
+ game->fade_timer = 0;
+ if (game->fade_frame >= animation->frame_count) {
+ game->fading = 0;
+ game->wait_timer2 = 20;
+ }
+ }
+}
+
+static void win_update(Game* game) {
+ const BM_Font* font;
+ Menu* menu;
+ int cx, cy;
+ World* world;
+ Colour col;
+
+ font = get_default_font();
+ world = &game->world;
+ menu = &game->menu;
+
+ cx = game->world.cam_x;
+ cy = game->world.cam_y;
+
+ if (game->fading) {
+ render_map(&game->world.map, cx, cy);
+ sprite_system(&game->world);
+ render_hud(game);
+ update_fade(game);
+ } else if (game->wait_timer > 0) {
+ render_map(&game->world.map, cx, cy);
+ sprite_system(&game->world);
+ render_hud(game);
+ } else {
+ game->wait_timer2--;
+ }
+
+ col = make_colour(0xc00000, 255);
+ rfont_text_col(
+ font,
+ renderer_w / 2 - 40,
+ menu->y - 15,
+ "YOU WIN",
+ col
+ );
+
+ if (game->wait_timer2 < 0) {
+ rfont_text(
+ font,
+ renderer_w / 2 - 118,
+ menu->y + menu->h + 15,
+ "Thank-you for playing \177"
+ );
+
+ col = make_colour(0x767593, 255);
+ rfont_text_col(
+ font,
+ renderer_w / 2 - 70,
+ menu->y + menu->h + 25,
+ " ~ quou - quou.xyz",
+ col
+ );
+
+ update_menu(menu);
+ render_menu(menu, font);
+ }
+
+ game->wait_timer--;
+ if (game->wait_timer == 0) {
+ game->fading = 1;
+ game->wait_timer = -1;
+ }
+}
+
+static void win_deinit(Game* game) {
+
+}
+
static const Game_State_Fns game_state_fns[] = {
/* game_state_menu */
{
@@ -376,6 +486,11 @@ static const Game_State_Fns game_state_fns[] = {
dead_init,
dead_update,
dead_deinit
+ },
+ {
+ win_init,
+ win_update,
+ win_deinit
}
};