diff options
Diffstat (limited to 'src/game_loop')
-rw-r--r-- | src/game_loop/game_over.c | 28 | ||||
-rw-r--r-- | src/game_loop/game_over.h | 18 | ||||
-rw-r--r-- | src/game_loop/gameplay.c | 47 | ||||
-rw-r--r-- | src/game_loop/gameplay.h | 17 | ||||
-rw-r--r-- | src/game_loop/shop.c | 85 | ||||
-rw-r--r-- | src/game_loop/shop.h | 37 | ||||
-rw-r--r-- | src/game_loop/starting_screen.c | 32 | ||||
-rw-r--r-- | src/game_loop/starting_screen.h | 14 |
8 files changed, 278 insertions, 0 deletions
diff --git a/src/game_loop/game_over.c b/src/game_loop/game_over.c new file mode 100644 index 0000000..f5b70cf --- /dev/null +++ b/src/game_loop/game_over.c @@ -0,0 +1,28 @@ +#include "game_over.h" + + +void hh_game_over(hh_e_game_state* hh_game_state){ + static hh_e_game_over hh_e_states_game_over = hh_e_game_over_show; + + switch (hh_e_states_game_over) + { + case hh_e_game_over_show: + hh_clear_screen(); + hh_clear_sprite(); + // todo: make function to show game over + hh_e_states_game_over = hh_e_game_over_input; + break; + case hh_e_game_over_input: + if(g_hh_controller_p1.button_primary){ + hh_e_states_game_over = hh_e_game_over_end; + } + break; + case hh_e_game_over_end: + hh_e_states_game_over = hh_e_game_over_show; + *hh_game_state = hh_e_state_game_over; + break; + default: + hh_e_states_game_over = hh_e_game_over_show; + break; + } +} diff --git a/src/game_loop/game_over.h b/src/game_loop/game_over.h new file mode 100644 index 0000000..80db667 --- /dev/null +++ b/src/game_loop/game_over.h @@ -0,0 +1,18 @@ +#pragma once + +#include "input.h" +#include "engine/draw_screen.h" +#include "engine/level_const.h" + + +#include <stdint.h> +#include <stdbool.h> + +typedef enum { + hh_e_game_over_show, + hh_e_game_over_input, + hh_e_game_over_end, +} hh_e_game_over; + + +void hh_game_over(hh_e_game_state*); diff --git a/src/game_loop/gameplay.c b/src/game_loop/gameplay.c new file mode 100644 index 0000000..295eb5d --- /dev/null +++ b/src/game_loop/gameplay.c @@ -0,0 +1,47 @@ +#include "gameplay.h" + +// player struct + + +void hh_gameplay(hh_g_all_levels game, hh_e_game_state* hh_game_state){ + static hh_e_gameplay gameplay = hh_e_setup_screen; + + switch (gameplay) + { + case hh_e_setup_screen: + hh_setup_screen(game.level[game.current_level]); + gameplay = hh_e_play_level; + break; + case hh_e_play_level: + // todo: here come all the different functions for the gameplay + hh_player_actions(); + + + + + + 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++; + gameplay = hh_e_setup_screen; + } + else { + gameplay = hh_e_game_over; + } + break; + case hh_e_game_over: + // todo make reset levels + hh_reset_levels(); + gameplay = hh_e_setup_screen; + *hh_game_state = hh_e_state_game_over; + break; + default: + break; + } + +} +void hh_reset_levels(){} diff --git a/src/game_loop/gameplay.h b/src/game_loop/gameplay.h new file mode 100644 index 0000000..d309e78 --- /dev/null +++ b/src/game_loop/gameplay.h @@ -0,0 +1,17 @@ +#pragma once +#include "engine/draw_screen.h" +#include "engine/player_controller.h" +#include "engine/sprite_controller.h" +#include "game_loop/starting_screen.h" +#include "engine/level_const.h" + +typedef enum { + hh_e_setup_screen, + hh_e_play_level, + hh_e_level_complete, + hh_e_game_over, +}hh_e_gameplay; + +void hh_reset_levels(); +void hh_gameplay(hh_g_all_levels, hh_e_game_state*); + diff --git a/src/game_loop/shop.c b/src/game_loop/shop.c new file mode 100644 index 0000000..6a97d25 --- /dev/null +++ b/src/game_loop/shop.c @@ -0,0 +1,85 @@ +#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; + static bool pressed_LR = false; + + switch (hh_e_shop) + { + case hh_e_shop_show: + hh_clear_screen(); + hh_clear_sprite(); + // TODO: make function to show shop + //hh_setup_shop(); + 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_main: + if(g_hh_controller_p1.dpad_left || g_hh_controller_p1.dpad_right){ + 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_secondary){//Quick exit + hh_e_shop = hh_e_shop_end; + } + break; + case hh_e_shop_end: // delay? + hh_e_shop = hh_e_shop_show; + *hh_game_state = hh_e_state_gameplay; + break; + default: + hh_e_shop = hh_e_shop_show; + break; + } +} + +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; + } +} + +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 = 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 new file mode 100644 index 0000000..642bcc3 --- /dev/null +++ b/src/game_loop/shop.h @@ -0,0 +1,37 @@ +#pragma once + +#include "input.h" +#include "engine/draw_screen.h" +#include "engine/level_const.h" + + +#include <stdint.h> +#include <stdbool.h> + +typedef enum { + hh_e_shop_show, + hh_e_shop_main, + hh_e_shop_end, +} hh_e_shop_states; + +/** @brief amount of upgrade types */ +#define HH_SHOP_UPG_COUNT 5 +/** @brief count of visible upgrades in shop */ +#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; + +/** @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*); diff --git a/src/game_loop/starting_screen.c b/src/game_loop/starting_screen.c new file mode 100644 index 0000000..6ab0278 --- /dev/null +++ b/src/game_loop/starting_screen.c @@ -0,0 +1,32 @@ +#include "starting_screen.h"" +#include "input.h" +#include "engine/title_screen.h" +#include "engine/draw_screen.h" +// #include "engine/player_controller.h" + +bool hh_show_starting_screen(){ + static hh_e_screen_states hh_e_starting_screen = hh_e_state_show; + + switch (hh_e_starting_screen) + { + case hh_e_state_show: + hh_clear_screen(); + hh_init_title_screen(); + hh_e_starting_screen = hh_e_state_input; + return false; + break; + case hh_e_state_input: + if(g_hh_controller_p1.button_primary){ + hh_e_starting_screen = hh_e_state_end; + } + break; + case hh_e_state_end: + hh_e_starting_screen = hh_e_state_show; + return true; + break; + default: + hh_e_starting_screen = hh_e_state_show; + break; + } + return false; +} diff --git a/src/game_loop/starting_screen.h b/src/game_loop/starting_screen.h new file mode 100644 index 0000000..4228f38 --- /dev/null +++ b/src/game_loop/starting_screen.h @@ -0,0 +1,14 @@ +#pragma once + +#include <stdint.h> +#include <stdbool.h> + +typedef enum { + hh_e_state_show, + hh_e_state_input, + hh_e_state_end +} hh_e_screen_states; + + +bool hh_show_starting_screen(); + |