diff options
author | quou <quou@disroot.org> | 2023-05-06 14:36:07 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2023-05-06 14:36:07 +1000 |
commit | 9e28af25b8fb5c9474ccbec2bd4dff26f1871075 (patch) | |
tree | 5f8e04e8af059aecaad8b44a08ad4a509d9e8d38 | |
parent | 937edea9599718e959f8ed135e97c68728855975 (diff) |
Add a logo and HUD.
-rw-r--r-- | game.c | 72 | ||||
-rw-r--r-- | intermediate/usr.bmp | bin | 68178 -> 75378 bytes | |||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | sprite.c | 25 | ||||
-rw-r--r-- | sprite.h | 7 | ||||
-rw-r--r-- | world.h | 4 |
6 files changed, 94 insertions, 16 deletions
@@ -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) { diff --git a/intermediate/usr.bmp b/intermediate/usr.bmp Binary files differindex 7735e60..b8bcd09 100644 --- a/intermediate/usr.bmp +++ b/intermediate/usr.bmp @@ -4,8 +4,6 @@ Game game; void on_init(int argc, char** argv) { - seed_rng(500); - init_renderer(); load_assets(); @@ -80,6 +80,31 @@ static const Sprite sprites[] = { { asset_id_map, { 16, 0, 16, 16 } + }, + /* sprite_heart_empty */ + { + asset_id_usr, + { 90, 60, 7, 6 } + }, + /* sprite_heart_full */ + { + asset_id_usr, + { 98, 60, 7, 6 } + }, + /* sprite_ram_empty */ + { + asset_id_usr, + { 105, 60, 14, 14 } + }, + /* sprite_ram_full */ + { + asset_id_usr, + { 119, 60, 14, 14 } + }, + /* sprite_logo */ + { + asset_id_usr, + { 1, 94, 153, 16 } } }; @@ -21,7 +21,12 @@ typedef enum { sprite_author, sprite_free, sprite_floor_tile, - sprite_bricks + sprite_bricks, + sprite_heart_empty, + sprite_heart_full, + sprite_ram_empty, + sprite_ram_full, + sprite_logo } Sprite_ID; typedef struct { @@ -24,10 +24,10 @@ struct World { CEnemy enemies [max_entities]; CCollider colliders [max_entities]; - int cam_x, cam_y; - Player player; Map map; + + int cam_x, cam_y; }; void init_world(World* world); |