aboutsummaryrefslogtreecommitdiff
path: root/src/game_loop
diff options
context:
space:
mode:
authorUnavailableDev <69792062+UnavailableDev@users.noreply.github.com>2023-04-06 12:32:23 +0200
committerGitHub <noreply@github.com>2023-04-06 12:32:23 +0200
commitd1c00c98ca0f2ca498284e60fa057a610cc5c461 (patch)
treea2efebcb9917d7f4f3666a722338f50b9590e843 /src/game_loop
parent1771aaa12736b4dbc24419270cf595de6d345969 (diff)
parent93e9426d5642dfab7a13d5a34873b296de1d9642 (diff)
Merge pull request #58 from UnavailableDev/dev
Dynamic tilemap
Diffstat (limited to 'src/game_loop')
-rw-r--r--src/game_loop/gameplay.c82
-rw-r--r--src/game_loop/gameplay.h3
-rw-r--r--src/game_loop/shop.c48
-rw-r--r--src/game_loop/shop.h6
-rw-r--r--src/game_loop/starting_screen.c1
5 files changed, 90 insertions, 50 deletions
diff --git a/src/game_loop/gameplay.c b/src/game_loop/gameplay.c
index da029f3..384ce40 100644
--- a/src/game_loop/gameplay.c
+++ b/src/game_loop/gameplay.c
@@ -1,5 +1,6 @@
#include "gameplay.h"
#include "engine/entity.h"
+#include "static/tilemap.h"
// player struct
@@ -12,59 +13,58 @@ void hh_gameplay(hh_g_all_levels* game, hh_e_game_state* hh_game_state){
.is_grounded = false,
.is_hit = false,
.radius = 8,
- .pos = (vec2){32,32},
- .size = (vec2){32,32},
+ .pos = (vec2){32,200},
+ .size = (vec2){16,32},
.vel = (vec2){0,0},
.render = {
- .frame0 = 3,
+ .frame0 = HH_TM_GOZER_OFFSET,
.palette = 3,
.fam = (hh_s_ppu_loc_fam_entry){
.horizontal_flip = false,
.vertical_flip = false,
.palette_index = 3,
- .tilemap_index = 80,
+ .tilemap_index = HH_TM_GOZER_OFFSET,
}
}
};
// enemy gets replaced here is just for reference
static hh_entity enemy={
+ .object_type = jumping_slime,
.hp = 4,
- .speed = 6,
+ .speed = 2,
.is_grounded = false,
.is_hit = false,
.radius = 8,
- .pos = (vec2){128,24},
+ .pos = (vec2){200,200},
.size = (vec2){16,16},
.vel = (vec2){0,0},
// .vec = (vec2){0,0},
.render = {
- .frame0 = 1,
- .palette = 7,
+ .frame0 = HH_TM_SLIME_OFFSET,
+ .palette = 2,
.fam = (hh_s_ppu_loc_fam_entry){
.horizontal_flip = false,
.vertical_flip = false,
- .palette_index = 7,
- .tilemap_index = 1,
+ .palette_index = 2,
+ .tilemap_index = HH_TM_SLIME_OFFSET,
}
}
};
- static int total_bullets = 5;
+ static int total_bullets = 15;
switch (gameplay)
{
case hh_e_setup_screen:
- printf("%d\n",game->current_level);
bullets = hh_init_bullets(total_bullets);
hh_setup_screen(game->level[game->current_level]);
gameplay = hh_e_play_level;
- enemy.hp=4;
break;
case hh_e_play_level:
- // TODO: here come all the different functions for the gameplay
- vec_cor cam_pos;//value in tiles
+
+ vec_cor cam_pos;
cam_pos = hh_draw_screen(player1.pos);
hh_player_actions(&player1);
hh_multiple_bullets(player1.pos,bullets);
- hh_multiple_enemies(cam_pos, &enemy,1);
+ hh_multiple_enemies(&enemy, player1, cam_pos, 1);
hh_check_all_collisions(&player1,&enemy,1,bullets,total_bullets,cam_pos);
hh_solve_hitted_enemies(&enemy,1);
hh_render_all_entities(&player1,bullets,&enemy,total_bullets,1, cam_pos);
@@ -74,19 +74,24 @@ void hh_gameplay(hh_g_all_levels* game, hh_e_game_state* hh_game_state){
if(game->level[game->current_level].hh_level_completed){
gameplay = hh_e_level_complete;
}
+ else if(player1.hp == 0){
+ gameplay = hh_e_game_over;
+ }
break;
case hh_e_level_complete:
- if(game->current_level < 3){
- game->current_level+=1;
- gameplay = hh_e_setup_screen;
- }
- else {
- gameplay = hh_e_game_over;
- }
+ // // TODO: from complete to shop or game_over
+ // if(game->current_level < 3){
+ // game->current_level+=1;
+ // gameplay = hh_e_setup_screen;
+ // }
+ // else {
+
+ // gameplay = hh_e_game_over;
+ // }
break;
case hh_e_game_over:
// todo make reset levels
- hh_reset_levels();
+ hh_reset_levels(&player1);
gameplay = hh_e_setup_screen;
*hh_game_state = hh_e_state_game_over;
break;
@@ -95,18 +100,39 @@ void hh_gameplay(hh_g_all_levels* game, hh_e_game_state* hh_game_state){
}
}
-void hh_reset_levels(){}
+void hh_reset_levels(hh_entity* player){
+ *player = (hh_entity){
+ .hp = 4,
+ .speed = 6,
+ .is_grounded = false,
+ .is_hit = false,
+ .radius = 16,
+ .pos = (vec2){32,32},
+ .size = (vec2){16,32},
+ .vel = (vec2){0,0},
+ .render = {
+ .frame0 = HH_TM_GOZER_OFFSET,
+ .palette = 3,
+ .fam = (hh_s_ppu_loc_fam_entry){
+ .horizontal_flip = false,
+ .vertical_flip = false,
+ .palette_index = 3,
+ .tilemap_index = HH_TM_GOZER_OFFSET,
+ }
+ }
+ };
+}
void hh_render_all_entities(hh_entity* player, hh_entity* bullets, hh_entity* enemies, int bullet_size, int enemy_size, vec_cor cam_pos){
int index = 0;
- hh_update_sprite(0 , player, cam_pos);
+ hh_update_sprite(&index , player, cam_pos);
for (int i = 0; i < bullet_size; i++) {
- hh_update_sprite(i+5,&bullets[i],cam_pos);
+ hh_update_sprite(&index,&bullets[i],cam_pos);
}
for (int i = 0; i < enemy_size; i++) {
- hh_update_sprite(i+5+bullet_size,&enemies[i],cam_pos);
+ hh_update_sprite(&index,&enemies[i],cam_pos);
}
}
diff --git a/src/game_loop/gameplay.h b/src/game_loop/gameplay.h
index 9d66c37..8adddb4 100644
--- a/src/game_loop/gameplay.h
+++ b/src/game_loop/gameplay.h
@@ -15,8 +15,9 @@ typedef enum {
hh_e_level_complete,
hh_e_game_over,
}hh_e_gameplay;
+
/** @brief resets all the levels the first condition */
-void hh_reset_levels();
+void hh_reset_levels(hh_entity* player);
/** @brief game loop function to handle the gameplay*/
void hh_gameplay(hh_g_all_levels* game, hh_e_game_state* hh_game_state);
/** @brief renders all the entities*/
diff --git a/src/game_loop/shop.c b/src/game_loop/shop.c
index ea75d46..da27524 100644
--- a/src/game_loop/shop.c
+++ b/src/game_loop/shop.c
@@ -2,37 +2,44 @@
#include "engine/maths.h"
#include "ppu/ppu.h"
-void hh_shop(hh_e_game_state* hh_game_state){
+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};
static uint8_t selected = 0;
+ static bool pressed_LR = false;
switch (hh_e_shop)
{
case hh_e_shop_show:
- hh_clear_screen();
- hh_clear_sprite();
+ // hh_clear_screen();
+ // hh_clear_sprite();
// TODO: make function to show shop
//hh_setup_shop();
+ hh_setup_screen(*level_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 +49,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;
@@ -49,7 +60,7 @@ void hh_shop_init(hh_e_upgrades* in) {
}
void hh_shop_display(uint8_t selected, hh_e_upgrades* upgrades) {
- const vec_cor start = {48,16};
+ const vec_cor start = {104,144+16};
const uint8_t up = 8,
space = 24+8;
@@ -57,20 +68,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..6f8f5a7 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
/** @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;
@@ -32,4 +34,4 @@ 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*);
+void hh_shop(hh_e_game_state* ,hh_level_entity* );
diff --git a/src/game_loop/starting_screen.c b/src/game_loop/starting_screen.c
index c11e4fc..d9f8ea6 100644
--- a/src/game_loop/starting_screen.c
+++ b/src/game_loop/starting_screen.c
@@ -11,6 +11,7 @@ bool hh_show_starting_screen(){
{
case hh_e_state_show:
hh_clear_screen();
+ hh_clear_sprite();
hh_init_title_screen();
hh_e_starting_screen = hh_e_state_input;
return false;