aboutsummaryrefslogtreecommitdiff
path: root/src/game_loop
diff options
context:
space:
mode:
authorUnavailableDev <ggwildplay@gmail.com>2023-04-06 16:40:34 +0200
committerUnavailableDev <ggwildplay@gmail.com>2023-04-06 16:40:34 +0200
commitd8e8e63bac3ef5a203106c09731ed2e55c87688a (patch)
treec9876a5c0f1cfea1eb56a2c046bcb4d5813e2d78 /src/game_loop
parent93e9426d5642dfab7a13d5a34873b296de1d9642 (diff)
rendering hp + strings
Diffstat (limited to 'src/game_loop')
-rw-r--r--src/game_loop/gameplay.c3
-rw-r--r--src/game_loop/shop.c7
-rw-r--r--src/game_loop/ui.c47
-rw-r--r--src/game_loop/ui.h19
4 files changed, 75 insertions, 1 deletions
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);
+