From 61d70551166de46cfda7ee5d6212817859153335 Mon Sep 17 00:00:00 2001 From: quou Date: Tue, 1 Oct 2024 20:40:29 +1000 Subject: hud --- Makefile | 4 +- hud.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++ intermediate/hud.bmp | Bin 0 -> 5022 bytes obj.h | 2 + world.c | 1 + 5 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 hud.c create mode 100644 intermediate/hud.bmp diff --git a/Makefile b/Makefile index ef3f82b..3f107ed 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,7 @@ sources = \ asset.c \ deathzone.c \ enemy.c \ + hud.c \ map.c \ maths.c \ memory.c \ @@ -61,10 +62,11 @@ sources = \ image_sources = \ $(int_dir)/arms.bmp \ - $(int_dir)/npc.bmp \ $(int_dir)/guy.bmp \ + $(int_dir)/hud.bmp \ $(int_dir)/map.bmp \ $(int_dir)/mask.bmp \ + $(int_dir)/npc.bmp \ anim_sources = \ $(int_dir)/demon_fly_left.anm \ diff --git a/hud.c b/hud.c new file mode 100644 index 0000000..1e014cb --- /dev/null +++ b/hud.c @@ -0,0 +1,124 @@ +#include "asset.h" +#include "config.h" +#include "render.h" +#include "world.h" + +const Rect heart_empty_rect = { 0, 0, 7, 6 }; +const Rect heart_half_rect = { 7, 0, 7, 6 }; +const Rect heart_full_rect = { 14, 0, 7, 6 }; +const Rect charge_empty_rect = { 0, 6, 7, 7 }; +const Rect charge_full_rect = { 7, 6, 7, 7 }; +const Rect background_rect = { 0, 13, 37, 20 }; + +const int hud_offset_x = 4; +const int hud_offset_y = 4; + +void hud_clip(Renderer* r) { + Rect clip; + clip.x = hud_offset_x; + clip.y = hud_offset_y; + clip.w = background_rect.w; + clip.h = background_rect.h; + ren_clip(r, &clip); +} + +void hud_background(Renderer* r, const Bitmap* bm) { + ren_map( + r, + hud_offset_x, + hud_offset_y, + &background_rect, + bm + ); +} + +void hud_hp(Renderer* r, const Bitmap* bm, int h) { + const int rmd = h & 1; + const int hh = h >> 1; + const int hmh = player_health >> 1; + int i; + int x = hud_offset_x + 3; + const int y = hud_offset_y + 3; + const int s = heart_empty_rect.w + 1; + for (i = 0; i < hh; i++, x += s) { + ren_map( + r, + x, + y, + &heart_full_rect, + bm + ); + } + if (rmd) { + ren_map( + r, + x, + y, + &heart_half_rect, + bm + ); + i++; + x += s; + } + for (; i < hmh; i++, x += s) + ren_map( + r, + x, + y, + &heart_empty_rect, + bm + ); +} + +void hud_charge(Renderer* r, const Bitmap* bm, int c, int f) { + int x = hud_offset_x + 3; + const int y = hud_offset_y + heart_empty_rect.h + 4; + if (c >= player_special_hits) { + int tx, ty; + Rect rect; + rect.x = x; + rect.y = y; + rect.w = + charge_empty_rect.w * + player_special_hits + + player_special_hits - 1; + rect.h = charge_empty_rect.h; + tx = rect.x + (rect.w >> 1) - 13 + ((f & 4) == 0); + ty = rect.y + (rect.h >> 1) - 2 + ((f & 6) == 0); + ren_text(r, tx, ty, "SPECIAL"); + ren_rect(r, &rect); + } else { + const int s = charge_empty_rect.w + 1; + int i; + for (i = 0; i < c; i++, x += s) + ren_map( + r, + x, + y, + &charge_full_rect, + bm + ); + for (; i < player_special_hits; i++, x += s) { + ren_map( + r, + x, + y, + &charge_empty_rect, + bm + ); + } + } +} + +void ren_hud(const World* w, Renderer* r) { + const Bitmap* bm = get_bitmap(asset_id_hud_img); + const Player* p = &w->player; + const int hp = p->hp; + const int c = p->charge; + hud_clip(r); + ren_clear(r); + hud_background(r, bm); + hud_hp(r, bm, hp); + hud_charge(r, bm, c, w->frame); + ren_rclip(r); +} diff --git a/intermediate/hud.bmp b/intermediate/hud.bmp new file mode 100644 index 0000000..c1850bd Binary files /dev/null and b/intermediate/hud.bmp differ diff --git a/obj.h b/obj.h index a74b015..c7d9589 100644 --- a/obj.h +++ b/obj.h @@ -79,4 +79,6 @@ void init_deathzone( ); int update_deathzone(Deathzone* d); +void ren_hud(const struct World* w, struct Renderer* r); + #endif diff --git a/world.c b/world.c index 98950f1..18cc6cd 100644 --- a/world.c +++ b/world.c @@ -75,4 +75,5 @@ void ren_world(const World* w, struct Renderer* r) { ren_particle(&w->particles[i], r); for (i = 0; i < w->enemy_count; i++) ren_enemy(&w->enemies[i], r); + ren_hud(w, r); } -- cgit v1.2.3-54-g00ecf