aboutsummaryrefslogtreecommitdiff
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
parent19760d58ea09b9c345a0c845e89143ddcc5d6507 (diff)
Improve the win screen.
-rw-r--r--animation.c15
-rw-r--r--animation.h3
-rw-r--r--game.c137
-rw-r--r--game.h4
-rw-r--r--intermediate/usr.bmpbin75378 -> 75378 bytes
5 files changed, 146 insertions, 13 deletions
diff --git a/animation.c b/animation.c
index 1912934..a134b5d 100644
--- a/animation.c
+++ b/animation.c
@@ -94,6 +94,21 @@ static const Animation animations[] = {
},
8,
5
+ },
+ /* animation_fade */
+ {
+ {
+ { 0, 60, 10, 10 },
+ { 10, 60, 10, 10 },
+ { 20, 60, 10, 10 },
+ { 30, 60, 10, 10 },
+ { 40, 60, 10, 10 },
+ { 50, 60, 10, 10 },
+ { 60, 60, 10, 10 },
+ { 70, 60, 10, 10 }
+ },
+ 8,
+ 5
}
};
diff --git a/animation.h b/animation.h
index 27eadb8..1b877b4 100644
--- a/animation.h
+++ b/animation.h
@@ -12,7 +12,8 @@ typedef enum {
animation_enemy_bullet_explode,
animation_player_bullet_explode,
animation_heart_break,
- animation_spawn
+ animation_spawn,
+ animation_fade
} Animation_ID;
typedef struct {
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
}
};
diff --git a/game.h b/game.h
index 66d9574..b67ec3c 100644
--- a/game.h
+++ b/game.h
@@ -8,7 +8,8 @@ typedef enum {
game_state_menu = 0,
game_state_game,
game_state_credits,
- game_state_dead
+ game_state_dead,
+ game_state_win
} Game_State;
typedef struct Game Game;
@@ -26,6 +27,7 @@ struct Game {
World world;
int wave_timer, want_next, display_wave_text;
+ int wait_timer, wait_timer2, fading, fade_timer, fade_frame;
};
void game_init(Game* game, Game_State state);
diff --git a/intermediate/usr.bmp b/intermediate/usr.bmp
index c0eecc2..78da8d8 100644
--- a/intermediate/usr.bmp
+++ b/intermediate/usr.bmp
Binary files differ