diff options
author | UnavailableDev <ggwildplay@gmail.com> | 2023-04-03 13:25:33 +0200 |
---|---|---|
committer | UnavailableDev <ggwildplay@gmail.com> | 2023-04-03 13:25:33 +0200 |
commit | 433cbd970797d4472d12c704163719aec7340202 (patch) | |
tree | 85e07b3a5214ce87a517df1e1dbe73709e900211 | |
parent | 68862666219c07ee62c9e59dd6866c1c7b26cc00 (diff) |
shop selections done
-rw-r--r-- | src/game_loop/shop.c | 39 | ||||
-rw-r--r-- | src/game_loop/shop.h | 6 |
2 files changed, 28 insertions, 17 deletions
diff --git a/src/game_loop/shop.c b/src/game_loop/shop.c index ea75d46..6a97d25 100644 --- a/src/game_loop/shop.c +++ b/src/game_loop/shop.c @@ -6,6 +6,7 @@ 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; + static bool pressed_LR = false; switch (hh_e_shop) { @@ -16,23 +17,28 @@ void hh_shop(hh_e_game_state* hh_game_state){ //hh_setup_shop(); hh_shop_init(&upgrades); selected = HH_SHOP_UPG_DISPLAY/2; - // hh_shop_display(selected, &upgrades); + hh_shop_display(selected, &upgrades); hh_e_shop = hh_e_shop_main; break; 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 (!pressed_LR) { + hh_shift_selected(&selected,(g_hh_controller_p1.dpad_right?1:0),0,HH_SHOP_UPG_DISPLAY-1); + hh_shop_display(selected, &upgrades); + } + pressed_LR = true; + } else { + pressed_LR = false; + } + if(g_hh_controller_p1.button_primary){ + //apply selected upgrade + hh_e_shop = hh_e_shop_end; } - // 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; - case hh_e_shop_end: + case hh_e_shop_end: // delay? hh_e_shop = hh_e_shop_show; *hh_game_state = hh_e_state_gameplay; break; @@ -42,6 +48,10 @@ void hh_shop(hh_e_game_state* hh_game_state){ } } +uint8_t hh_shop_translate_upgrades(hh_e_upgrades upg) { + return upg+10; +} + 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; @@ -57,20 +67,19 @@ void hh_shop_display(uint8_t selected, hh_e_upgrades* upgrades) { 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), + .position_x = i*space+start.x, .position_y = start.y + (i==selected?-up:0), .palette_index = 7, - .tilemap_index = 8 + .tilemap_index = hh_shop_translate_upgrades(upgrades[i]) }); } } -void hh_shift_selected(uint8_t* pos, bool dir, uint8_t min, uint8_t max) { +void hh_shift_selected(uint8_t *pos, bool dir, uint8_t min, uint8_t max) { if (dir) { - pos = CLAMP(++pos,min,max); + *pos = MIN(*pos+1,max); } else { - if (pos > 0) { - pos--; - } + *pos = MAX(*pos-1,min); } + // printf("b: %d sel: %d\n",dir, *pos); } diff --git a/src/game_loop/shop.h b/src/game_loop/shop.h index b0ad5e4..642bcc3 100644 --- a/src/game_loop/shop.h +++ b/src/game_loop/shop.h @@ -15,12 +15,14 @@ typedef enum { } hh_e_shop_states; /** @brief amount of upgrade types */ -#define HH_SHOP_UPG_COUNT 2 +#define HH_SHOP_UPG_COUNT 5 /** @brief count of visible upgrades in shop */ -#define HH_SHOP_UPG_DISPLAY 4 +#define HH_SHOP_UPG_DISPLAY 5 /** @brief all possible upgrades */ typedef enum { hh_e_upg_jump, + hh_e_upg_speed, + hh_e_upg_damage, hh_e_upg_heal, hh_e_upg_max_health, } hh_e_upgrades; |