aboutsummaryrefslogtreecommitdiff
path: root/src/game_loop
diff options
context:
space:
mode:
authorUnavailableDev <ggwildplay@gmail.com>2023-04-03 11:37:45 +0200
committerUnavailableDev <ggwildplay@gmail.com>2023-04-03 11:37:45 +0200
commitf761624a95de538bb2be8f9449ed0edb8ae067ad (patch)
treeb0224b1516a362c27903efd4797f9bdf1a7eabc6 /src/game_loop
parent05504df10934cac60b774fb10e86593ec3897510 (diff)
parentcd9d3141626e7be29b69da15b989d23eb63e46f0 (diff)
Merge branch 'game-engine' into dev
Diffstat (limited to 'src/game_loop')
-rw-r--r--src/game_loop/shop.c60
-rw-r--r--src/game_loop/shop.h19
2 files changed, 71 insertions, 8 deletions
diff --git a/src/game_loop/shop.c b/src/game_loop/shop.c
index b3d2234..ea75d46 100644
--- a/src/game_loop/shop.c
+++ b/src/game_loop/shop.c
@@ -1,21 +1,34 @@
#include "shop.h"
-
+#include "engine/maths.h"
+#include "ppu/ppu.h"
void hh_shop(hh_e_game_state* hh_game_state){
static hh_e_shop_states hh_e_shop = hh_e_shop_show;
-
+ static hh_e_upgrades upgrades[HH_SHOP_UPG_DISPLAY] = {0};
+ static uint8_t selected = 0;
+
switch (hh_e_shop)
{
case hh_e_shop_show:
hh_clear_screen();
hh_clear_sprite();
- // todo: make function to show shop
+ // TODO: make function to show shop
//hh_setup_shop();
- hh_e_shop = hh_e_shop_input;
+ hh_shop_init(&upgrades);
+ selected = HH_SHOP_UPG_DISPLAY/2;
+ // hh_shop_display(selected, &upgrades);
+ hh_e_shop = hh_e_shop_main;
break;
- case hh_e_shop_input:
- // todo: make it so that you can choose between shop
- if(g_hh_controller_p1.button_primary){
+ case hh_e_shop_main:
+ if(g_hh_controller_p1.dpad_left || g_hh_controller_p1.dpad_right){
+ hh_shift_selected(&selected,(g_hh_controller_p1.dpad_right?1:0),0,HH_SHOP_UPG_DISPLAY);
+ // hh_shop_display(selected, &upgrades);
+ }
+ // if(g_hh_controller_p1.button_primary){
+ // //apply selected upgrade
+ // hh_e_shop = hh_e_shop_end;
+ // }
+ if(g_hh_controller_p1.button_secondary){//Quick exit
hh_e_shop = hh_e_shop_end;
}
break;
@@ -28,3 +41,36 @@ void hh_shop(hh_e_game_state* hh_game_state){
break;
}
}
+
+void hh_shop_init(hh_e_upgrades* in) {
+ for (int i = 0; i < HH_SHOP_UPG_DISPLAY; i++) {
+ in[i] = i%HH_SHOP_UPG_COUNT;
+ }
+}
+
+void hh_shop_display(uint8_t selected, hh_e_upgrades* upgrades) {
+ const vec_cor start = {48,16};
+ const uint8_t up = 8,
+ space = 24+8;
+
+ for (int i = 0; i < HH_SHOP_UPG_DISPLAY; i++) {
+ hh_ppu_update_foreground(i+16,
+ (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),
+ .palette_index = 7,
+ .tilemap_index = 8
+ });
+ }
+}
+
+void hh_shift_selected(uint8_t* pos, bool dir, uint8_t min, uint8_t max) {
+ if (dir) {
+ pos = CLAMP(++pos,min,max);
+ } else {
+ if (pos > 0) {
+ pos--;
+ }
+ }
+}
+
diff --git a/src/game_loop/shop.h b/src/game_loop/shop.h
index 7d01b7e..b0ad5e4 100644
--- a/src/game_loop/shop.h
+++ b/src/game_loop/shop.h
@@ -10,9 +10,26 @@
typedef enum {
hh_e_shop_show,
- hh_e_shop_input,
+ hh_e_shop_main,
hh_e_shop_end,
} hh_e_shop_states;
+/** @brief amount of upgrade types */
+#define HH_SHOP_UPG_COUNT 2
+/** @brief count of visible upgrades in shop */
+#define HH_SHOP_UPG_DISPLAY 4
+/** @brief all possible upgrades */
+typedef enum {
+ hh_e_upg_jump,
+ hh_e_upg_heal,
+ hh_e_upg_max_health,
+} hh_e_upgrades;
+
+/** @brief init */
+void hh_shop_init(hh_e_upgrades* in);
+/** @brief deals with displayed entity rendering */
+void hh_shop_display(uint8_t selected, hh_e_upgrades* upgrades);
+/** @brief moves 'cursor' through selection field */
+void hh_shift_selected(uint8_t* pos, bool dir, uint8_t min, uint8_t max);
void hh_shop(hh_e_game_state*);