From 9e28af25b8fb5c9474ccbec2bd4dff26f1871075 Mon Sep 17 00:00:00 2001 From: quou Date: Sat, 6 May 2023 14:36:07 +1000 Subject: Add a logo and HUD. --- game.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 11 deletions(-) (limited to 'game.c') diff --git a/game.c b/game.c index b3d40fb..2cba35c 100644 --- a/game.c +++ b/game.c @@ -3,6 +3,7 @@ #include "game.h" #include "platform.h" #include "sprite.h" +#include "standard.h" #include "systems.h" static void menu_new(Menu* menu) { @@ -53,11 +54,10 @@ static void menu_init(Game* game) { static void menu_update(Game* game) { const Sprite* msg; const Bitmap* bmp; - int h, y; + int y; update_menu(&game->menu); - h = game->menu.h; y = game->menu.y; msg = get_sprite(sprite_author); @@ -78,6 +78,16 @@ static void menu_update(Game* game) { &msg->rect ); + /* Logo. */ + msg = get_sprite(sprite_logo); + bmp = get_bitmap(msg->bitmap); + render_bitmap( + bmp, + renderer_w / 2 - msg->rect.w / 2, + y - msg->rect.h - 8, + &msg->rect + ); + render_menu(&game->menu, get_default_font()); } @@ -86,25 +96,65 @@ static void menu_deinit(Game* game) { } static void gameplay_init(Game* game) { + seed_rng(500); init_world(&game->world); init_map(&game->world.map, &game->world); init_player(&game->world.player, &game->world); new_skull(&game->world, 0, 0); } +static void render_hud(Game* game) { + int i; + const Sprite* heart_sprite; + const Bitmap* heart_bitmap; + World* world; + Player* player; + + world = &game->world; + player = &world->player; + + heart_sprite = get_sprite(sprite_heart_full); + heart_bitmap = get_bitmap(heart_sprite->bitmap); + for (i = 0; i < player->hp; i++) { + render_bitmap( + heart_bitmap, + 1 + i * (heart_sprite->rect.w + 1), + 1, + &heart_sprite->rect + ); + } + heart_sprite = get_sprite(sprite_heart_empty); + heart_bitmap = get_bitmap(heart_sprite->bitmap); + for (; i < player_max_hp; i++) { + render_bitmap( + heart_bitmap, + 1 + i * (heart_sprite->rect.w + 1), + 1, + &heart_sprite->rect + ); + } +} + static void gameplay_update(Game* game) { - int cx, cy; + int cx, cy, i; + World* world; + Player* player; cx = game->world.cam_x; cy = game->world.cam_y; - update_player(&game->world.player, &game->world); - enemy_system(&game->world); - bullet_system(&game->world); - collision_system(&game->world); - animation_system(&game->world); - render_map(&game->world.map, cx, cy); - update_camera(&game->world.player, &game->world); - sprite_system(&game->world); + world = &game->world; + player = &world->player; + + update_player(player, world); + enemy_system(world); + bullet_system(world); + collision_system(world); + animation_system(world); + render_map(&world->map, cx, cy); + update_camera(player, world); + sprite_system(world); + + render_hud(game); } static void gameplay_deinit(Game* game) { -- cgit v1.2.3-54-g00ecf