aboutsummaryrefslogtreecommitdiff
path: root/src/game_loop
diff options
context:
space:
mode:
authorNielsCoding <48092678+heavydemon21@users.noreply.github.com>2023-04-04 15:25:34 +0200
committerNielsCoding <48092678+heavydemon21@users.noreply.github.com>2023-04-04 15:25:34 +0200
commit854a80001b9798d1454e4308e4efba96431e44d8 (patch)
tree8e023b13df43b3aaef5241e59bcbe5c90b1a2f8a /src/game_loop
parentf6c1eb582ac44b92c86816352bd56da5a6f4f1b5 (diff)
bullet/player/enemy/gameplay
bullet only needs different directions player is done enemy needs ai(Bjorn) gameplay may need some finetuning
Diffstat (limited to 'src/game_loop')
-rw-r--r--src/game_loop/game_over.h2
-rw-r--r--src/game_loop/gameplay.c50
-rw-r--r--src/game_loop/gameplay.h11
3 files changed, 44 insertions, 19 deletions
diff --git a/src/game_loop/game_over.h b/src/game_loop/game_over.h
index 80db667..47318df 100644
--- a/src/game_loop/game_over.h
+++ b/src/game_loop/game_over.h
@@ -14,5 +14,5 @@ typedef enum {
hh_e_game_over_end,
} hh_e_game_over;
-
+/** @brief game loop function game over*/
void hh_game_over(hh_e_game_state*);
diff --git a/src/game_loop/gameplay.c b/src/game_loop/gameplay.c
index 521ab85..da029f3 100644
--- a/src/game_loop/gameplay.c
+++ b/src/game_loop/gameplay.c
@@ -1,9 +1,9 @@
#include "gameplay.h"
-
+#include "engine/entity.h"
// player struct
-void hh_gameplay(hh_g_all_levels game, hh_e_game_state* hh_game_state){
+void hh_gameplay(hh_g_all_levels* game, hh_e_game_state* hh_game_state){
static hh_e_gameplay gameplay = hh_e_setup_screen;
static hh_entity* bullets;
static hh_entity player1={
@@ -16,7 +16,7 @@ void hh_gameplay(hh_g_all_levels game, hh_e_game_state* hh_game_state){
.size = (vec2){32,32},
.vel = (vec2){0,0},
.render = {
- .frame0 = 80,
+ .frame0 = 3,
.palette = 3,
.fam = (hh_s_ppu_loc_fam_entry){
.horizontal_flip = false,
@@ -33,11 +33,12 @@ 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){128,48},
+ .pos = (vec2){128,24},
+ .size = (vec2){16,16},
.vel = (vec2){0,0},
// .vec = (vec2){0,0},
.render = {
- .frame0 = 20,
+ .frame0 = 1,
.palette = 7,
.fam = (hh_s_ppu_loc_fam_entry){
.horizontal_flip = false,
@@ -47,31 +48,36 @@ void hh_gameplay(hh_g_all_levels game, hh_e_game_state* hh_game_state){
}
}
};
-
+ static int total_bullets = 5;
switch (gameplay)
{
case hh_e_setup_screen:
- bullets = hh_init_bullets(10);
- hh_setup_screen(game.level[game.current_level]);
+ 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
cam_pos = hh_draw_screen(player1.pos);
- hh_player_actions(&player1 ,cam_pos);
- hh_multiple_bullets(player1.pos, cam_pos,bullets);
- // enemy's
-
+ hh_player_actions(&player1);
+ hh_multiple_bullets(player1.pos,bullets);
+ hh_multiple_enemies(cam_pos, &enemy,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);
- if(game.level[game.current_level].hh_level_completed){
+
+ if(game->level[game->current_level].hh_level_completed){
gameplay = hh_e_level_complete;
}
break;
case hh_e_level_complete:
- if(game.current_level < 3){
- game.current_level++;
+ if(game->current_level < 3){
+ game->current_level+=1;
gameplay = hh_e_setup_screen;
}
else {
@@ -90,3 +96,17 @@ void hh_gameplay(hh_g_all_levels game, hh_e_game_state* hh_game_state){
}
void hh_reset_levels(){}
+
+
+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);
+
+ for (int i = 0; i < bullet_size; i++) {
+ hh_update_sprite(i+5,&bullets[i],cam_pos);
+ }
+ for (int i = 0; i < enemy_size; i++) {
+ hh_update_sprite(i+5+bullet_size,&enemies[i],cam_pos);
+ }
+}
diff --git a/src/game_loop/gameplay.h b/src/game_loop/gameplay.h
index fb5637c..9d66c37 100644
--- a/src/game_loop/gameplay.h
+++ b/src/game_loop/gameplay.h
@@ -5,6 +5,9 @@
#include "engine/sprite_controller.h"
#include "game_loop/starting_screen.h"
#include "engine/level_const.h"
+#include "engine/animator.h"
+#include "engine/enemy.h"
+
typedef enum {
hh_e_setup_screen,
@@ -12,7 +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_gameplay(hh_g_all_levels, hh_e_game_state*);
-
+/** @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*/
+void hh_render_all_entities(hh_entity* player, hh_entity* bullets, hh_entity* enemies, int bullet_size, int enemy_size, vec_cor cam_pos);