From d8e8e63bac3ef5a203106c09731ed2e55c87688a Mon Sep 17 00:00:00 2001 From: UnavailableDev Date: Thu, 6 Apr 2023 16:40:34 +0200 Subject: rendering hp + strings --- src/game_loop/gameplay.c | 3 +++ src/game_loop/shop.c | 7 ++++++- src/game_loop/ui.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/game_loop/ui.h | 19 +++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/game_loop/ui.c create mode 100644 src/game_loop/ui.h (limited to 'src/game_loop') diff --git a/src/game_loop/gameplay.c b/src/game_loop/gameplay.c index 384ce40..3d750f4 100644 --- a/src/game_loop/gameplay.c +++ b/src/game_loop/gameplay.c @@ -1,6 +1,7 @@ #include "gameplay.h" #include "engine/entity.h" #include "static/tilemap.h" +#include "game_loop/ui.h" // player struct @@ -135,4 +136,6 @@ void hh_render_all_entities(hh_entity* player, hh_entity* bullets, hh_entity* en for (int i = 0; i < enemy_size; i++) { hh_update_sprite(&index,&enemies[i],cam_pos); } + + hh_ui_show_hp(&index, player, 7, cam_pos); } diff --git a/src/game_loop/shop.c b/src/game_loop/shop.c index da27524..60fc70b 100644 --- a/src/game_loop/shop.c +++ b/src/game_loop/shop.c @@ -2,6 +2,8 @@ #include "engine/maths.h" #include "ppu/ppu.h" +#include "game_loop/ui.h" + void hh_shop(hh_e_game_state* hh_game_state, hh_level_entity* level_shop){ static hh_e_shop_states hh_e_shop = hh_e_shop_show; static hh_e_upgrades upgrades[HH_SHOP_UPG_DISPLAY] = {0}; @@ -19,6 +21,9 @@ void hh_shop(hh_e_game_state* hh_game_state, hh_level_entity* level_shop){ hh_shop_init(&upgrades); selected = HH_SHOP_UPG_DISPLAY/2; hh_shop_display(selected, &upgrades); + int idx = 16; + hh_ui_show_char(&idx,"aBYz09",(vec2){32,32}); + hh_e_shop = hh_e_shop_main; break; case hh_e_shop_main: @@ -65,7 +70,7 @@ void hh_shop_display(uint8_t selected, hh_e_upgrades* upgrades) { space = 24+8; for (int i = 0; i < HH_SHOP_UPG_DISPLAY; i++) { - hh_ppu_update_foreground(i+16, + hh_ppu_update_foreground(i, (hh_s_ppu_loc_fam_entry){ .horizontal_flip = false, .vertical_flip = false, .position_x = i*space+start.x, .position_y = start.y + (i==selected?-up:0), diff --git a/src/game_loop/ui.c b/src/game_loop/ui.c new file mode 100644 index 0000000..3354d43 --- /dev/null +++ b/src/game_loop/ui.c @@ -0,0 +1,47 @@ +#include "game_loop/ui.h" + +void hh_ui_show_hp(int* idx, hh_entity* player, uint8_t max_hp, vec_cor cam_pos) { + for (int i = 0; i < max_hp; i++) { + int tilemap_idx = HH_TM_HUD_HEART_OFFSET + (player->hp > i?0:1), + palette_idx = HH_PAL_IDX_HUD; + hh_show_quad(idx, &(hh_s_rendering){ + .frame0 = tilemap_idx, + .palette = palette_idx, + .fam = (hh_s_ppu_loc_fam_entry){ + .horizontal_flip = false, .vertical_flip = false, + .palette_index = palette_idx, + .tilemap_index = tilemap_idx, + .position_x = 8 + i*15, .position_y = 8 + } + }); + } +} + +void hh_ui_show_char(int* idx, char* str, vec2 pos) { + int i = 0; + int tilemap_idx, + palette_idx = 6; + while (str[i] != '\0') { + if(str[i] >= 'A' && str[i] <= 'Z'){ + tilemap_idx = HH_TM_FONT_OFFSET + str[i]-'A'+10; + } else if (str[i] >= 'a' && str[i] <= 'z') { + tilemap_idx = HH_TM_FONT_OFFSET + str[i]-'a'+10; + } else if (str[i] >= '0' && str[i] <= '9'){ + tilemap_idx = HH_TM_FONT_OFFSET + str[i]-48; + } else { + return; + } + hh_show_quad(idx, &(hh_s_rendering){ + .frame0 = tilemap_idx, + .palette = palette_idx, + .fam = (hh_s_ppu_loc_fam_entry){ + .horizontal_flip = false, .vertical_flip = false, + .palette_index = palette_idx, + .tilemap_index = tilemap_idx, + .position_x = 8 + i*15, .position_y = 8 + } + }); + i++; + } + +} diff --git a/src/game_loop/ui.h b/src/game_loop/ui.h new file mode 100644 index 0000000..7a8ffbd --- /dev/null +++ b/src/game_loop/ui.h @@ -0,0 +1,19 @@ +#pragma once + +#include "static/tilemap.h" +#include "engine/player_controller.h" + +#include "ppu/types.h" + +#include "engine/types.h" +#include "engine/entity.h" +#include "engine/animator.h" +#include "engine/player_controller.h" + + +// extern hh_g_max_hp; + +void hh_ui_show_hp(int* idx, hh_entity* player, uint8_t max_hp, vec_cor cam_pos); + +void hh_ui_show_char(int* idx, char* str, vec2 pos); + -- cgit v1.2.3