aboutsummaryrefslogtreecommitdiff
path: root/src/game_loop
diff options
context:
space:
mode:
Diffstat (limited to 'src/game_loop')
-rw-r--r--src/game_loop/gameplay.c5
-rw-r--r--src/game_loop/shop.c34
-rw-r--r--src/game_loop/shop.h15
-rw-r--r--src/game_loop/ui.c16
-rw-r--r--src/game_loop/ui.h5
5 files changed, 48 insertions, 27 deletions
diff --git a/src/game_loop/gameplay.c b/src/game_loop/gameplay.c
index 3d750f4..200dfac 100644
--- a/src/game_loop/gameplay.c
+++ b/src/game_loop/gameplay.c
@@ -10,7 +10,7 @@ void hh_gameplay(hh_g_all_levels* game, hh_e_game_state* hh_game_state){
static hh_entity* bullets;
static hh_entity player1={
.hp = 4,
- .speed = 6,
+ .speed = 3,
.is_grounded = false,
.is_hit = false,
.radius = 8,
@@ -48,7 +48,8 @@ void hh_gameplay(hh_g_all_levels* game, hh_e_game_state* hh_game_state){
.vertical_flip = false,
.palette_index = 2,
.tilemap_index = HH_TM_SLIME_OFFSET,
- }
+ },
+ .cooldown = 0
}
};
static int total_bullets = 15;
diff --git a/src/game_loop/shop.c b/src/game_loop/shop.c
index 60fc70b..c8dcfe5 100644
--- a/src/game_loop/shop.c
+++ b/src/game_loop/shop.c
@@ -4,7 +4,7 @@
#include "game_loop/ui.h"
-void hh_shop(hh_e_game_state* hh_game_state, hh_level_entity* level_shop){
+hh_e_upgrades hh_shop(hh_e_game_state* hh_game_state, hh_g_all_levels* levels, int rng_seed){
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;
@@ -17,12 +17,15 @@ void hh_shop(hh_e_game_state* hh_game_state, hh_level_entity* level_shop){
// hh_clear_sprite();
// TODO: make function to show shop
//hh_setup_shop();
- hh_setup_screen(*level_shop);
- hh_shop_init(&upgrades);
+ hh_setup_screen(levels->shop);
+ hh_shop_upg_init(&upgrades, rng_seed);
selected = HH_SHOP_UPG_DISPLAY/2;
hh_shop_display(selected, &upgrades);
int idx = 16;
- hh_ui_show_char(&idx,"aBYz09",(vec2){32,32});
+ // hh_ui_show_char(&idx,"abyz09",(vec2){32,32});
+ char* c[3];
+ itoa(c,levels->current_level);
+ hh_ui_show_char(&idx,c,(vec2){304-16-8,0});
hh_e_shop = hh_e_shop_main;
break;
@@ -39,6 +42,7 @@ void hh_shop(hh_e_game_state* hh_game_state, hh_level_entity* level_shop){
if(g_hh_controller_p1.button_primary){
//apply selected upgrade
// hh_e_shop = hh_e_shop_end;
+ return upgrades[selected];
}
if(g_hh_controller_p1.button_secondary){//Quick exit
hh_e_shop = hh_e_shop_end;
@@ -52,15 +56,21 @@ void hh_shop(hh_e_game_state* hh_game_state, hh_level_entity* level_shop){
hh_e_shop = hh_e_shop_show;
break;
}
+ return hh_e_NULL;
}
uint8_t hh_shop_translate_upgrades(hh_e_upgrades upg) {
- return upg+10;
+ return HH_TM_UPGRADES_OFFSET+upg;
}
-void hh_shop_init(hh_e_upgrades* in) {
+void hh_shop_upg_init(hh_e_upgrades* in, int seed) {
+ srand(seed);
for (int i = 0; i < HH_SHOP_UPG_DISPLAY; i++) {
- in[i] = i%HH_SHOP_UPG_COUNT;
+ hh_e_upgrades rng = rand()%(HH_SHOP_UPG_COUNT);
+ while (rng == in[i-1]){
+ rng = rand()%(HH_SHOP_UPG_COUNT);
+ }
+ in[i] = rng;
}
}
@@ -74,18 +84,10 @@ void hh_shop_display(uint8_t selected, hh_e_upgrades* upgrades) {
(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,
+ .palette_index = HH_PAL_IDX_UPGRADE,
.tilemap_index = hh_shop_translate_upgrades(upgrades[i])
});
}
}
-void hh_shift_selected(uint8_t *pos, bool dir, uint8_t min, uint8_t max) {
- if (dir) {
- *pos = MIN(*pos+1,max);
- } else {
- *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 6f8f5a7..c4f3ced 100644
--- a/src/game_loop/shop.h
+++ b/src/game_loop/shop.h
@@ -3,6 +3,7 @@
#include "input.h"
#include "engine/draw_screen.h"
#include "engine/level_const.h"
+#include "engine/sprite_controller.h"
#include <stdint.h>
@@ -20,18 +21,18 @@ typedef enum {
#define HH_SHOP_UPG_DISPLAY 4
/** @brief all possible upgrades */
typedef enum {
- hh_e_upg_jump,
- hh_e_upg_speed,
- hh_e_upg_damage,
+ hh_e_NULL = -1,
hh_e_upg_heal,
hh_e_upg_max_health,
+ hh_e_upg_jump,
+ hh_e_upg_damage,
+ hh_e_upg_max_ammo,
+ hh_e_upg_speed,
} hh_e_upgrades;
/** @brief init */
-void hh_shop_init(hh_e_upgrades* in);
+void hh_shop_upg_init(hh_e_upgrades* in, int seed);
/** @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* ,hh_level_entity* );
+hh_e_upgrades hh_shop(hh_e_game_state* ,hh_g_all_levels* , int);
diff --git a/src/game_loop/ui.c b/src/game_loop/ui.c
index 3354d43..60dbfc2 100644
--- a/src/game_loop/ui.c
+++ b/src/game_loop/ui.c
@@ -16,7 +16,6 @@ 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) {
int i = 0;
int tilemap_idx,
@@ -38,10 +37,23 @@ void hh_ui_show_char(int* idx, char* str, vec2 pos) {
.horizontal_flip = false, .vertical_flip = false,
.palette_index = palette_idx,
.tilemap_index = tilemap_idx,
- .position_x = 8 + i*15, .position_y = 8
+ .position_x = pos.x + i*15, .position_y = pos.y
}
});
i++;
}
}
+
+void itoa(char *c, int i) {
+ c[0] = i + '0';
+ c[1] = '\0';
+}
+
+void hh_shift_selected(uint8_t *pos, bool dir, uint8_t min, uint8_t max) {
+ if (dir) {
+ *pos = MIN(*pos+1,max);
+ } else {
+ *pos = MAX(*pos-1,min);
+ }
+}
diff --git a/src/game_loop/ui.h b/src/game_loop/ui.h
index 7a8ffbd..073824e 100644
--- a/src/game_loop/ui.h
+++ b/src/game_loop/ui.h
@@ -17,3 +17,8 @@ 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);
+/** @brief converts char* [0] to i and [1]='\0' */
+void itoa(char *c, int i);
+
+/** @brief moves 'cursor' through selection field */
+void hh_shift_selected(uint8_t *pos, bool dir, uint8_t min, uint8_t max);