From 552dcc17db2b98287ba1b480c2e70759cd94d81f Mon Sep 17 00:00:00 2001 From: NielsCoding <48092678+heavydemon21@users.noreply.github.com> Date: Thu, 30 Mar 2023 13:02:36 +0200 Subject: gameloop/bullet/levels gameloop moet nog wat gefixt worden. shop moet nog wat art en functie krijgen zefde voor gameover/highscore bullet moet meerdere entityten kunnen doen nu nog alleen gemaakt voor 1. levels moet alleen nog backwords kunnen --- src/GameLoop/game_over.c | 28 +++++++++++++ src/GameLoop/game_over.h | 18 +++++++++ src/GameLoop/gameplay.c | 44 ++++++++++++++++++++ src/GameLoop/gameplay.h | 17 ++++++++ src/GameLoop/shop.c | 28 ++++++------- src/GameLoop/shop.h | 12 +++--- src/demo.c | 35 +++++----------- src/engine/bullet.c | 65 +++++++++++++----------------- src/engine/bullet.h | 17 +++----- src/engine/draw_screen.c | 103 ++++++++++++++++++++++++++--------------------- src/engine/draw_screen.h | 22 ++++++---- src/engine/level_const.c | 22 ++++++++++ src/engine/level_const.h | 31 ++++++++++++++ src/makefile | 3 ++ 14 files changed, 299 insertions(+), 146 deletions(-) create mode 100644 src/GameLoop/game_over.c create mode 100644 src/GameLoop/game_over.h create mode 100644 src/GameLoop/gameplay.c create mode 100644 src/GameLoop/gameplay.h create mode 100644 src/engine/level_const.c create mode 100644 src/engine/level_const.h diff --git a/src/GameLoop/game_over.c b/src/GameLoop/game_over.c new file mode 100644 index 0000000..09e6858 --- /dev/null +++ b/src/GameLoop/game_over.c @@ -0,0 +1,28 @@ +#include "game_over.h" + + +void hh_game_over(hh_e_GameState* 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_GameOver; + break; + default: + hh_e_states_game_over = hh_e_game_over_SHOW; + break; + } +} diff --git a/src/GameLoop/game_over.h b/src/GameLoop/game_over.h new file mode 100644 index 0000000..0d40b6c --- /dev/null +++ b/src/GameLoop/game_over.h @@ -0,0 +1,18 @@ +#pragma once + +#include "input.h" +#include "engine/draw_screen.h" +#include "engine/level_const.h" + + +#include +#include + +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_GameState*); diff --git a/src/GameLoop/gameplay.c b/src/GameLoop/gameplay.c new file mode 100644 index 0000000..72297f5 --- /dev/null +++ b/src/GameLoop/gameplay.c @@ -0,0 +1,44 @@ +#include "gameplay.h" + + + +void hh_gameplay(hh_g_all_levels game, hh_e_GameState* 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.currentLevel]); + 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.currentLevel].hh_level_completed){ + gameplay = hh_e_level_complete; + } + break; + case hh_e_level_complete: + if(game.currentLevel < 3){ + game.currentLevel++; + 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_GameOver; + break; + default: + break; + } + +} +void hh_reset_levels(){} diff --git a/src/GameLoop/gameplay.h b/src/GameLoop/gameplay.h new file mode 100644 index 0000000..6e8c1ec --- /dev/null +++ b/src/GameLoop/gameplay.h @@ -0,0 +1,17 @@ +#pragma once +#include "engine/draw_screen.h" +#include "engine/player_controller.h" +#include "engine/sprite_controller.h" +#include "GameLoop/startingScreen.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_GameState*); + diff --git a/src/GameLoop/shop.c b/src/GameLoop/shop.c index eb6bed5..8e6dc71 100644 --- a/src/GameLoop/shop.c +++ b/src/GameLoop/shop.c @@ -1,30 +1,30 @@ #include "shop.h" -bool hh_show_Shop(){ - static hh_e_ShopStates hh_e_Shop = hh_e_STATE_SHOW; +void hh_Shop(hh_e_GameState* hh_game_state){ + static hh_e_ShopStates hh_e_Shop = hh_e_shop_SHOW; switch (hh_e_Shop) { - case hh_e_STATE_SHOW: - //hh_clear_screen(); - + case hh_e_shop_SHOW: + hh_clear_screen(); + hh_clear_sprite(); + // TODO: make function to show shop //hh_setup_shop(); - hh_e_Shop = hh_e_STATE_Input; - return false; + hh_e_Shop = hh_e_shop_Input; break; - case hh_e_STATE_Input: + case hh_e_shop_Input: + // TODO: make it so that you can choose between shop if(g_hh_controller_p1.button_primary){ - hh_e_Shop = hh_e_STATE_END; + hh_e_Shop = hh_e_shop_END; } break; - case hh_e_STATE_END: - hh_e_Shop = hh_e_STATE_SHOW; - return true; + case hh_e_shop_END: + hh_e_Shop = hh_e_shop_SHOW; + *hh_game_state = hh_e_STATE_Gameplay; break; default: - hh_e_Shop = hh_e_STATE_SHOW; + hh_e_Shop = hh_e_shop_SHOW; break; } - return false; } diff --git a/src/GameLoop/shop.h b/src/GameLoop/shop.h index 4014f58..1efc057 100644 --- a/src/GameLoop/shop.h +++ b/src/GameLoop/shop.h @@ -1,16 +1,18 @@ +#pragma once + #include "input.h" #include "engine/draw_screen.h" - +#include "engine/level_const.h" #include #include typedef enum { - hh_e_STATE_SHOW, - hh_e_STATE_Input, - hh_e_STATE_END + hh_e_shop_SHOW, + hh_e_shop_Input, + hh_e_shop_END, } hh_e_ShopStates; -bool hh_show_Shop(); +void hh_Shop(hh_e_GameState*); diff --git a/src/demo.c b/src/demo.c index 22ee8b7..886dda8 100644 --- a/src/demo.c +++ b/src/demo.c @@ -11,19 +11,14 @@ #include "engine/draw_screen.h" #include "engine/player_controller.h" #include "engine/sprite_controller.h" -#include "GameLoop/startingScreen.h" - +#include "engine/level_const.h" -typedef enum { - hh_e_STATE_startingScreen, - hh_e_STATE_Shop, - hh_e_STATE_Gameplay, - hh_e_STATE_GameOver, - hh_e_STATE_HighScore -} hh_e_GameState; -hh_e_GameState hh_gameStates; +#include "GameLoop/startingScreen.h" +#include "GameLoop/gameplay.h" +#include "GameLoop/shop.h" +hh_g_all_levels hh_game; uint16_t g_hh_pos_x = 1000; // 0b0000 0001 0011 0110 uint16_t g_hh_pos_y; @@ -43,13 +38,13 @@ typedef struct { }hh_s_tiles; +hh_e_GameState hh_gameStates; hh_entity hh_g_player, hh_g_player_new; void hh_demo_setup() { hh_setup_palettes(); // hh_setup_screen(); - - + hh_game = hh_init_game_levels(); } void hh_demo_loop(unsigned long frame) { @@ -64,22 +59,10 @@ void hh_demo_loop(unsigned long frame) { } break; case hh_e_STATE_Shop: - // TODO: - // if(hh_show_Shop()){ - hh_clear_screen(); - hh_clear_sprite(); - hh_setup_screen(); - hh_clear_sprite(); - hh_gameStates = hh_e_STATE_Gameplay; - // } - // function: new level is chosen goto level + hh_Shop(&hh_gameStates); break; case hh_e_STATE_Gameplay: - hh_player_actions(); - - // TODO: - // function: if level complete goto shop - // function: if player is dead goto game over + hh_gameplay(hh_game, &hh_gameStates); break; case hh_e_STATE_GameOver: // TODO: diff --git a/src/engine/bullet.c b/src/engine/bullet.c index 5aa9e51..2016a4d 100644 --- a/src/engine/bullet.c +++ b/src/engine/bullet.c @@ -1,44 +1,35 @@ #include "bullet.h" -#include "engine/sprite_controller.h" -void shootBullet(vec2 playerPos, Bullet* bullet){ - // Set bullet's x and y coordinates to player's coordinates - bullet->x = playerPos.x; - bullet->y = playerPos.y; - // Set bullet's velocity to a fixed value - bullet->velocity = 1; - // Set bullet's status to active - bullet->isActive = true; -} -void updateBullet(Bullet* bullet, int deltaTime){ - // Only update bullet if it is active - static int latestLocationBullet = 0; - if (bullet->isActive) { - // Move bullet based on velocity and deltaTime - bullet->x += bullet->velocity * deltaTime; - drawBullet(bullet); - // Check if bullet has moved 16 pixels - if (bullet->x - latestLocationBullet > 32) { - // Set bullet's status to inactive - bullet->isActive = false; - drawBullet(&(Bullet){.x = -16,.y = -16. }); - } - } - else{ - latestLocationBullet = bullet->x; - } + +// TODO: use hh_entity as bullet struct +void shootBullet(vec2 playerPos, vec_cor cam_pos, hh_entity* bullet){ + vec2 temp; + if(g_hh_controller_p1.button_secondary){ + if(bullet->is_grounded){ + bullet->is_grounded=false; + bullet->pos = playerPos; + } + } + else{ + if(!bullet->is_grounded){ + updateBullet(bullet , cam_pos, temp); + drawBullet(*bullet); + } + } + + } -void drawBullet(Bullet* bullet){ +void collision +void updateBullet(hh_entity* bullet, vec_cor cam_pos, vec2 start){ + bullet->pos.x += 1; + // update bullet sprite on ppu + bullet->render.fam.position_x = (bullet->pos.x-cam_pos.x); + bullet->render.fam.position_y = (bullet->pos.y-cam_pos.y); - hh_ppu_update_foreground(10, (hh_s_ppu_loc_fam_entry) - { - .position_x = bullet->x, - .position_y = bullet->y, - .horizontal_flip = false, - .vertical_flip = false, - .palette_index = 7, - .tilemap_index = 84, // change tilemap to the correct foreground index; - }); +} +void drawBullet(hh_entity bullet){ + hh_s_ppu_loc_fam_entry temp = bullet.render.fam; + hh_ppu_update_foreground(10,temp); } diff --git a/src/engine/bullet.h b/src/engine/bullet.h index ad67d84..5bbc031 100644 --- a/src/engine/bullet.h +++ b/src/engine/bullet.h @@ -1,16 +1,11 @@ #pragma once #include "player_controller.h" +#include "engine/sprite_controller.h" +#include "input.h" -typedef struct { - int x; - int y; - int velocity; - int isActive; - int hit; -} Bullet; +void shootBullet(vec2 playerPos, vec_cor cam_pos, hh_entity*); -//Bullet* createBullet(float x, float y, float velocity, float direction); -void shootBullet(vec2 playerPos, Bullet* bullet); -void updateBullet(Bullet* bullet, int deltaTime); -void drawBullet(Bullet* bullet); +void updateBullet(hh_entity* , vec_cor, vec2 ); + +void drawBullet(hh_entity); diff --git a/src/engine/draw_screen.c b/src/engine/draw_screen.c index 0c31bf6..4a5ca68 100644 --- a/src/engine/draw_screen.c +++ b/src/engine/draw_screen.c @@ -1,66 +1,77 @@ #include "engine/draw_screen.h" -#include "engine/sprite_controller.h" +//#include "engine/sprite_controller.h" +hh_level_entity level; +uint64_t offset=0; uint8_t hh_world_to_tile(vec2 pos){ - //TODO: remove magic file name here - FILE* level = fopen("static/level1_test.bin", "rb"); /* open binary file */ - if (!level) { /* check if file opened successfully */ - fprintf(stderr, "Error: Failed to open file.\n"); - return 0; - } - int index = ((pos.y/16)*40 + pos.x/16);//TODO: remove magic number(s) - fseek(level, (index * sizeof(int)) + sizeof(int), SEEK_SET); - int tile;// = (int*)malloc(sizeof(int)); - fread(&tile, sizeof(int), 1, level); // read 1 tile from binary - - fclose(level); - // int val = tile; - // free(tile); + + int index = (((pos.y/16)*hh_max_x_size) + (pos.x/16));//TODO: remove magic number(s) + int tile= level.place[index]; return tile; } +void hh_update_screen(vec2 view, vec2 player){ + int currentTileY = view.y / 16; + int offset_px = view.y-(offset / 40 * 16); -// remeber old value to know which part to update. -vec2 previousViewport = { .x = 0, .y = 0 }; -void hh_draw_screen(vec_cor viewport){ - if (viewport.x == previousViewport.x && viewport.y == previousViewport.y) return; - - hh_ppu_update_aux((hh_s_ppu_loc_aux){ - .bg_shift_x = viewport.x, - .bg_shift_y = viewport.y, - .fg_fetch = 0, - .sysreset = 0, - }); - // update previous viewport values - previousViewport = viewport; -} + // || (offset_px == 0 && lastUpdated != 0 && player.y/16 == currentTileY-5) + if( (offset_px > 230) ){ + int size = (hh_max_x_size) * hh_max_y_size; + offset = currentTileY * level.x; -void hh_setup_screen(){ - //(HH_map_size_X*HH_map_size_Y) - int size = 2400; // max X = 40 en max Y = 80 - //TODO: remove magic file name here - FILE* level = fopen("static/level1_test.bin", "rb"); /* open binary file */ - if (!level) { /* check if file opened successfully */ - fprintf(stderr, "Error: Failed to open level file.\n"); - return; + // Update the background screen + for (int BAM_index = 0; BAM_index < size; BAM_index++) { + hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ + .horizontal_flip = false, + .vertical_flip = false, + .palette_index = hh_get_palette(level.place[offset+BAM_index]), + .tilemap_index = level.place[offset+BAM_index], + }); + } } - fseek(level, (0* sizeof(int)) + sizeof(int), SEEK_SET); - int* tile = (int*)malloc(size*sizeof(int)); - fread(tile, sizeof(int), size, level); // read 1 tile from binary - - fclose(level); - +} +void hh_setup_screen(hh_level_entity currentlevel){ + hh_clear_screen(); + hh_clear_sprite(); + level = currentlevel; + int size = hh_max_x_size* hh_max_y_size; + printf("hier\n"); for(int BAM_index = 0; BAM_index < size; BAM_index++){ hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ .horizontal_flip = false, .vertical_flip = false, - .palette_index = hh_get_palette(tile[BAM_index]), - .tilemap_index = tile[BAM_index], + .palette_index = hh_get_palette(currentlevel.place[BAM_index]), + .tilemap_index = currentlevel.place[BAM_index], }); } - free(tile); } +vec_cor hh_draw_screen(vec2 player) { + static vec_cor previousViewport = {0, 0}; + int offset_px = offset/40*16; + //printf("%d\n",offset_px%2); + vec_cor viewport = hh_update_camera(player,(vec2){.x=0,.y=offset_px},(vec2){.x=20*16,.y=30*16+offset_px/4});//TODO: remove magic number(s) + + hh_update_screen((vec2){.y=viewport.y,.x=0},player); + if (viewport.x == previousViewport.x && viewport.y == previousViewport.y){} + else{ + // update previous viewport values + + //printf("viewport y %d\n",viewport.y-(offset/40*16)); + //printf("offset %d\n",offset); + hh_ppu_update_aux((hh_s_ppu_loc_aux){ + .bg_shift_x = viewport.x - 0, + .bg_shift_y = viewport.y-(offset/40*16), + .fg_fetch = 0, + .sysreset = 0, + }); + previousViewport = viewport; + + } + + return viewport; +} + void hh_clear_screen(){ // (HH_PPU_SCREEN_HEIGHT*HH_PPU_SCREEN_WIDTH)/(HH_PPU_SPRITE_HEIGHT*HH_PPU_SPRITE_WIDTH) for (int i = 0; i < HH_PPU_BG_CANVAS_TILES_H*HH_PPU_BG_CANVAS_TILES_V; i++) { diff --git a/src/engine/draw_screen.h b/src/engine/draw_screen.h index 95765e5..0d1b68a 100644 --- a/src/engine/draw_screen.h +++ b/src/engine/draw_screen.h @@ -3,24 +3,32 @@ // every function call for drawing the screen goes here. #include "engine/maths.h" -#include "ppu/consts.h" #include "ppu/ppu.h" - +#include "engine/level_const.h" +#include "engine/sprite_controller.h" #include #include #include +#include "engine/camera.h" - -#define HH_map_size_X 80 -#define HH_map_size_Y 60 +#define hh_max_x_size 40 +#define hh_max_y_size 30 /** @brief return a single tile from world binary */ uint8_t hh_world_to_tile(vec2 pos); + /** @brief shift to level if viewport changed position */ -void hh_draw_screen(vec2 viewport); +vec_cor hh_draw_screen(vec2 player); + /** @brief send data to BAM memory from binary level */ -void hh_setup_screen(); +void hh_setup_screen(hh_level_entity currentlevel); +/** @brief updates screen based on view and maybe player position if it needs to turn back*/ +void hh_update_screen(vec2 view, vec2 ); + /** @brief send black screen to background memory */ void hh_clear_screen(); + /** @brief clears all sprite data */ void hh_clear_sprite(); +/** @brief send data to BAM memory from binary from shop */ +void hh_setup_Shop(); diff --git a/src/engine/level_const.c b/src/engine/level_const.c new file mode 100644 index 0000000..b568e86 --- /dev/null +++ b/src/engine/level_const.c @@ -0,0 +1,22 @@ +#include "engine/level_const.h" + + +hh_g_all_levels hh_init_game_levels(){ + hh_g_all_levels levels; + levels.currentLevel=0; + + levels.level[0].x=40; + levels.level[0].y=60; + levels.level[0].hh_level_completed=false; + FILE *fp = fopen("../test/bin/level1_test.bin", "rb"); + fseek(fp, 0, SEEK_END); + int size = ftell(fp) / sizeof(int); + fseek(fp, (0 * sizeof(int)) + sizeof(int), SEEK_SET); + int* hh_game_level1 = malloc(size * sizeof(int)); + fread(hh_game_level1, sizeof(int), size, fp); + fclose(fp); + levels.level[0].place = hh_game_level1; + + return levels; +} + diff --git a/src/engine/level_const.h b/src/engine/level_const.h new file mode 100644 index 0000000..7a4aac5 --- /dev/null +++ b/src/engine/level_const.h @@ -0,0 +1,31 @@ +#pragma once +#include +#include +#include +#include +#include ` + +typedef enum { + hh_e_STATE_startingScreen, + hh_e_STATE_Shop, + hh_e_STATE_Gameplay, + hh_e_STATE_GameOver, + hh_e_STATE_HighScore +} hh_e_GameState; + +typedef struct { + int x; + int y; + int hh_total_enemies; + int* place; + bool hh_level_completed; +}hh_level_entity; + +typedef struct { + hh_level_entity level[1]; + int currentLevel; + + +}hh_g_all_levels; + +hh_g_all_levels hh_init_game_levels(); diff --git a/src/makefile b/src/makefile index cd248e2..d00b0ee 100644 --- a/src/makefile +++ b/src/makefile @@ -40,7 +40,10 @@ LOCAL_SRCS += main.c \ engine/entity.c \ engine/bullet.c \ engine/title_screen.c \ + engine/level_const.c \ GameLoop/shop.c \ + GameLoop/gameplay.c \ + GameLoop/game_over.c \ GameLoop/startingScreen.c CFLAGS += $(SHARED_FLAGS) -- cgit v1.2.3 From e987d23d915942ec4a3910b9cc2729f1b21361a9 Mon Sep 17 00:00:00 2001 From: NielsCoding <48092678+heavydemon21@users.noreply.github.com> Date: Sun, 2 Apr 2023 20:48:06 +0200 Subject: snake case/background --- src/GameLoop/game_over.c | 28 ------------- src/GameLoop/game_over.h | 18 -------- src/GameLoop/gameplay.c | 44 -------------------- src/GameLoop/gameplay.h | 17 -------- src/GameLoop/shop.c | 30 -------------- src/GameLoop/shop.h | 18 -------- src/GameLoop/startingScreen.c | 32 --------------- src/GameLoop/startingScreen.h | 14 ------- src/demo.c | 53 ++++++++++++------------ src/engine/bullet.c | 14 +++---- src/engine/bullet.h | 6 +-- src/engine/camera.c | 7 +++- src/engine/draw_screen.c | 91 +++++++++++++++++++++++++++-------------- src/engine/draw_screen.h | 2 +- src/engine/level_const.c | 23 +++++++++-- src/engine/level_const.h | 24 +++++------ src/game_loop/game_over.c | 28 +++++++++++++ src/game_loop/game_over.h | 18 ++++++++ src/game_loop/gameplay.c | 47 +++++++++++++++++++++ src/game_loop/gameplay.h | 17 ++++++++ src/game_loop/shop.c | 30 ++++++++++++++ src/game_loop/shop.h | 18 ++++++++ src/game_loop/starting_screen.c | 32 +++++++++++++++ src/game_loop/starting_screen.h | 14 +++++++ src/makefile | 8 ++-- 25 files changed, 341 insertions(+), 292 deletions(-) delete mode 100644 src/GameLoop/game_over.c delete mode 100644 src/GameLoop/game_over.h delete mode 100644 src/GameLoop/gameplay.c delete mode 100644 src/GameLoop/gameplay.h delete mode 100644 src/GameLoop/shop.c delete mode 100644 src/GameLoop/shop.h delete mode 100644 src/GameLoop/startingScreen.c delete mode 100644 src/GameLoop/startingScreen.h create mode 100644 src/game_loop/game_over.c create mode 100644 src/game_loop/game_over.h create mode 100644 src/game_loop/gameplay.c create mode 100644 src/game_loop/gameplay.h create mode 100644 src/game_loop/shop.c create mode 100644 src/game_loop/shop.h create mode 100644 src/game_loop/starting_screen.c create mode 100644 src/game_loop/starting_screen.h diff --git a/src/GameLoop/game_over.c b/src/GameLoop/game_over.c deleted file mode 100644 index 09e6858..0000000 --- a/src/GameLoop/game_over.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "game_over.h" - - -void hh_game_over(hh_e_GameState* 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_GameOver; - break; - default: - hh_e_states_game_over = hh_e_game_over_SHOW; - break; - } -} diff --git a/src/GameLoop/game_over.h b/src/GameLoop/game_over.h deleted file mode 100644 index 0d40b6c..0000000 --- a/src/GameLoop/game_over.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "input.h" -#include "engine/draw_screen.h" -#include "engine/level_const.h" - - -#include -#include - -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_GameState*); diff --git a/src/GameLoop/gameplay.c b/src/GameLoop/gameplay.c deleted file mode 100644 index 72297f5..0000000 --- a/src/GameLoop/gameplay.c +++ /dev/null @@ -1,44 +0,0 @@ -#include "gameplay.h" - - - -void hh_gameplay(hh_g_all_levels game, hh_e_GameState* 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.currentLevel]); - 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.currentLevel].hh_level_completed){ - gameplay = hh_e_level_complete; - } - break; - case hh_e_level_complete: - if(game.currentLevel < 3){ - game.currentLevel++; - 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_GameOver; - break; - default: - break; - } - -} -void hh_reset_levels(){} diff --git a/src/GameLoop/gameplay.h b/src/GameLoop/gameplay.h deleted file mode 100644 index 6e8c1ec..0000000 --- a/src/GameLoop/gameplay.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "engine/draw_screen.h" -#include "engine/player_controller.h" -#include "engine/sprite_controller.h" -#include "GameLoop/startingScreen.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_GameState*); - diff --git a/src/GameLoop/shop.c b/src/GameLoop/shop.c deleted file mode 100644 index 8e6dc71..0000000 --- a/src/GameLoop/shop.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "shop.h" - - -void hh_Shop(hh_e_GameState* hh_game_state){ - static hh_e_ShopStates hh_e_Shop = hh_e_shop_SHOW; - - 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_e_Shop = hh_e_shop_Input; - break; - case hh_e_shop_Input: - // TODO: make it so that you can choose between shop - if(g_hh_controller_p1.button_primary){ - hh_e_Shop = hh_e_shop_END; - } - break; - case hh_e_shop_END: - hh_e_Shop = hh_e_shop_SHOW; - *hh_game_state = hh_e_STATE_Gameplay; - break; - default: - hh_e_Shop = hh_e_shop_SHOW; - break; - } -} diff --git a/src/GameLoop/shop.h b/src/GameLoop/shop.h deleted file mode 100644 index 1efc057..0000000 --- a/src/GameLoop/shop.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "input.h" -#include "engine/draw_screen.h" -#include "engine/level_const.h" - - -#include -#include - -typedef enum { - hh_e_shop_SHOW, - hh_e_shop_Input, - hh_e_shop_END, -} hh_e_ShopStates; - - -void hh_Shop(hh_e_GameState*); diff --git a/src/GameLoop/startingScreen.c b/src/GameLoop/startingScreen.c deleted file mode 100644 index 4fc5af9..0000000 --- a/src/GameLoop/startingScreen.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "startingScreen.h" -#include "input.h" -#include "engine/title_screen.h" -#include "engine/draw_screen.h" -// #include "engine/player_controller.h" - -bool hh_show_startingScreen(){ - static hh_e_screenStates hh_e_startingScreen = hh_e_STATE_SHOW; - - switch (hh_e_startingScreen) - { - case hh_e_STATE_SHOW: - hh_clear_screen(); - hh_init_title_screen(); - hh_e_startingScreen = hh_e_STATE_Input; - return false; - break; - case hh_e_STATE_Input: - if(g_hh_controller_p1.button_primary){ - hh_e_startingScreen = hh_e_STATE_END; - } - break; - case hh_e_STATE_END: - hh_e_startingScreen = hh_e_STATE_SHOW; - return true; - break; - default: - hh_e_startingScreen = hh_e_STATE_SHOW; - break; - } - return false; -} diff --git a/src/GameLoop/startingScreen.h b/src/GameLoop/startingScreen.h deleted file mode 100644 index f51cc66..0000000 --- a/src/GameLoop/startingScreen.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -#include - -typedef enum { - hh_e_STATE_SHOW, - hh_e_STATE_Input, - hh_e_STATE_END -} hh_e_screenStates; - - -bool hh_show_startingScreen(); - diff --git a/src/demo.c b/src/demo.c index 886dda8..4fa1be2 100644 --- a/src/demo.c +++ b/src/demo.c @@ -13,9 +13,9 @@ #include "engine/sprite_controller.h" #include "engine/level_const.h" -#include "GameLoop/startingScreen.h" -#include "GameLoop/gameplay.h" -#include "GameLoop/shop.h" +#include "game_loop/starting_screen.h" +#include "game_loop/gameplay.h" +#include "game_loop/shop.h" hh_g_all_levels hh_game; @@ -38,57 +38,56 @@ typedef struct { }hh_s_tiles; -hh_e_GameState hh_gameStates; -hh_entity hh_g_player, hh_g_player_new; +hh_e_game_state hh_game_states; + hh_entity hh_g_player, hh_g_player_new; void hh_demo_setup() { hh_setup_palettes(); - // hh_setup_screen(); hh_game = hh_init_game_levels(); } void hh_demo_loop(unsigned long frame) { - switch (hh_gameStates) + switch (hh_game_states) { - case hh_e_STATE_startingScreen: - bool ret = hh_show_startingScreen(); + case hh_e_state_starting_screen: + bool ret = hh_show_starting_screen(); if(ret){ - hh_gameStates = hh_e_STATE_Shop; + hh_game_states = hh_e_state_shop; } break; - case hh_e_STATE_Shop: - hh_Shop(&hh_gameStates); + case hh_e_state_shop: + hh_shop(&hh_game_states); break; - case hh_e_STATE_Gameplay: - hh_gameplay(hh_game, &hh_gameStates); + case hh_e_state_gameplay: + hh_gameplay(hh_game, &hh_game_states); break; - case hh_e_STATE_GameOver: - // TODO: + case hh_e_state_game_over: + // todo: // function: show game over screen // function: after time goto high score break; - case hh_e_STATE_HighScore: - // TODO: + case hh_e_state_high_score: + // todo: // fucntion: show all previously scored points // function: button pressed goto starting screen break; default: - hh_gameStates = hh_e_STATE_startingScreen; + hh_game_states = hh_e_state_starting_screen; break; } } -// void sendData(uint8_t address, uint16_t data) { -// uint8_t bitData[3]; -// bitData[2] = data & 0xff; -// bitData[1] = (data >> 8); -// bitData[0] = address; // first byte is address +// void send_data(uint8_t address, uint16_t data) { +// uint8_t bit_data[3]; +// bit_data[2] = data & 0xff; +// bit_data[1] = (data >> 8); +// bit_data[0] = address; // first byte is address // -// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET); -// HAL_SPI_Transmit(&hspi1, bitData, 3, 100); //2*8 bit data -// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_SET); +// hal_gpio_write_pin(gpioa, gpio_pin_9, gpio_pin_reset); +// hal_spi_transmit(&hspi1, bit_data, 3, 100); //2*8 bit data +// hal_gpio_write_pin(gpioa, gpio_pin_9, gpio_pin_set); // } diff --git a/src/engine/bullet.c b/src/engine/bullet.c index 2016a4d..e6ca6df 100644 --- a/src/engine/bullet.c +++ b/src/engine/bullet.c @@ -3,25 +3,25 @@ // TODO: use hh_entity as bullet struct -void shootBullet(vec2 playerPos, vec_cor cam_pos, hh_entity* bullet){ +void hh_shoot_bullet(vec2 player, vec_cor cam_pos, hh_entity* bullet){ vec2 temp; if(g_hh_controller_p1.button_secondary){ if(bullet->is_grounded){ bullet->is_grounded=false; - bullet->pos = playerPos; + bullet->pos = player; } } else{ if(!bullet->is_grounded){ - updateBullet(bullet , cam_pos, temp); - drawBullet(*bullet); + hh_update_bullet(bullet , cam_pos); + hh_draw_bullet(*bullet); } } } -void collision -void updateBullet(hh_entity* bullet, vec_cor cam_pos, vec2 start){ + +void hh_update_bullet(hh_entity* bullet, vec_cor cam_pos){ bullet->pos.x += 1; // update bullet sprite on ppu @@ -29,7 +29,7 @@ void updateBullet(hh_entity* bullet, vec_cor cam_pos, vec2 start){ bullet->render.fam.position_y = (bullet->pos.y-cam_pos.y); } -void drawBullet(hh_entity bullet){ +void hh_draw_bullet(hh_entity bullet){ hh_s_ppu_loc_fam_entry temp = bullet.render.fam; hh_ppu_update_foreground(10,temp); } diff --git a/src/engine/bullet.h b/src/engine/bullet.h index 5bbc031..5f07b2e 100644 --- a/src/engine/bullet.h +++ b/src/engine/bullet.h @@ -4,8 +4,8 @@ #include "input.h" -void shootBullet(vec2 playerPos, vec_cor cam_pos, hh_entity*); +void hh_shoot_bullet(vec2 playerPos, vec_cor cam_pos, hh_entity*); -void updateBullet(hh_entity* , vec_cor, vec2 ); +void hh_update_bullet(hh_entity* , vec_cor ); -void drawBullet(hh_entity); +void hh_draw_bullet(hh_entity); diff --git a/src/engine/camera.c b/src/engine/camera.c index 2c3e517..6898430 100644 --- a/src/engine/camera.c +++ b/src/engine/camera.c @@ -4,12 +4,13 @@ vec_cor hh_update_camera(vec_cen new, vec2 min, vec2 max){ - //TODO: change floating point math to fix point math //TODO: remove magic number at y camera offset // new = vec_cen2cor(new,(vec2){.x=max.x/2,.y=max.y/2}); - new = vec_cen2cor((vec2){.x=new.x+(HH_PPU_SPRITE_WIDTH),.y=new.y+(HH_PPU_SPRITE_HEIGHT*8)},(vec2){.x=max.x/2,.y=max.y/2}); + new = vec_cen2cor((vec2){.x=new.x+(HH_PPU_SPRITE_WIDTH),.y=new.y+(HH_PPU_SPRITE_HEIGHT*8)},(vec2){.x=(max.x - min.x)/2,.y=(max.y - min.y)/2}); + // new = vec_cen2cor((vec2){.x=new.x+(HH_PPU_SPRITE_WIDTH),.y=new.y+(HH_PPU_SPRITE_HEIGHT*8)},(vec2){.x=max.x/2,.y=max.y/2}); + // new.x = new.x << HH_MATH_FIXED_POINT; // new.y = new.y << HH_MATH_FIXED_POINT; static vec_cor old; @@ -30,6 +31,8 @@ vec_cor hh_update_camera(vec_cen new, vec2 min, vec2 max){ old.x = CLAMP(new.x,min.x,max.x); old.y = CLAMP(new.y,min.y,max.y); + //printf("camera new %d min %d max %d\n",new.y,min.y,max.y); return old; } + diff --git a/src/engine/draw_screen.c b/src/engine/draw_screen.c index 4a5ca68..d1d7a04 100644 --- a/src/engine/draw_screen.c +++ b/src/engine/draw_screen.c @@ -1,72 +1,101 @@ #include "engine/draw_screen.h" -//#include "engine/sprite_controller.h" hh_level_entity level; -uint64_t offset=0; +uint64_t offsetY=0; +uint64_t offsetX=0; uint8_t hh_world_to_tile(vec2 pos){ - int index = (((pos.y/16)*hh_max_x_size) + (pos.x/16));//TODO: remove magic number(s) + int index = (((pos.y/HH_PPU_SPRITE_HEIGHT)*level.size.x) + (pos.x/HH_PPU_SPRITE_WIDTH));//TODO: remove magic number(s) int tile= level.place[index]; return tile; } void hh_update_screen(vec2 view, vec2 player){ - int currentTileY = view.y / 16; - int offset_px = view.y-(offset / 40 * 16); + int current_tile_y = view.y / HH_PPU_SPRITE_HEIGHT; + int current_tile_x = view.x / HH_PPU_SPRITE_WIDTH; + int offset_py = view.y - (offsetY / 40 * HH_PPU_SPRITE_HEIGHT); + int offset_px = view.x - offsetX * HH_PPU_SPRITE_WIDTH; + static int prev_ofsset = 0; + int size = MIN(HH_PPU_BG_CANVAS_TILES_H,level.size.x) * MIN(HH_PPU_BG_CANVAS_TILES_V,level.size.y); + if( (offset_py == 0 || offset_py > 230) && level.size.y > level.size.x && prev_ofsset != offset_py){ + if(offset_py==0){ + offsetY = (current_tile_y-14) * level.size.x; + } + else{ + offsetY = current_tile_y * level.size.x; + } - // || (offset_px == 0 && lastUpdated != 0 && player.y/16 == currentTileY-5) - if( (offset_px > 230) ){ - int size = (hh_max_x_size) * hh_max_y_size; - offset = currentTileY * level.x; - // Update the background screen for (int BAM_index = 0; BAM_index < size; BAM_index++) { hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ .horizontal_flip = false, .vertical_flip = false, - .palette_index = hh_get_palette(level.place[offset+BAM_index]), - .tilemap_index = level.place[offset+BAM_index], + .palette_index = hh_get_palette(level.place[offsetY + BAM_index]), + .tilemap_index = level.place[offsetY + BAM_index], + }); + } + prev_ofsset = offset_py; + } + else if ((offset_px == 0 || offset_px > 310) && level.size.x > level.size.y && prev_ofsset != offset_px) + { + if(offset_px==0){ + offsetX = current_tile_x - 14; + } + else{ + offsetX = current_tile_x; + } + // Update the background screen + for (int BAM_index = 0; BAM_index < size; BAM_index++) { + int var = (BAM_index / HH_PPU_BG_CANVAS_TILES_H) * level.size.x + MIN((BAM_index % HH_PPU_BG_CANVAS_TILES_H + offsetX),level.size.x); + hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ + .horizontal_flip = false, + .vertical_flip = false, + .palette_index = hh_get_palette(level.place[var]), + .tilemap_index = level.place[var], }); } } + + prev_ofsset = offset_px; + } void hh_setup_screen(hh_level_entity currentlevel){ hh_clear_screen(); hh_clear_sprite(); level = currentlevel; - int size = hh_max_x_size* hh_max_y_size; - printf("hier\n"); - for(int BAM_index = 0; BAM_index < size; BAM_index++){ + offsetY=0; + offsetX=0; + int size = MIN(HH_PPU_BG_CANVAS_TILES_H, level.size.x) * MIN(HH_PPU_BG_CANVAS_TILES_V, level.size.y); + for (int BAM_index = 0; BAM_index < size; BAM_index++) { + int var = (BAM_index / HH_PPU_BG_CANVAS_TILES_H) * level.size.x + BAM_index % HH_PPU_BG_CANVAS_TILES_H; hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ .horizontal_flip = false, .vertical_flip = false, - .palette_index = hh_get_palette(currentlevel.place[BAM_index]), - .tilemap_index = currentlevel.place[BAM_index], + .palette_index = hh_get_palette(currentlevel.place[var]), + .tilemap_index = currentlevel.place[var], }); } } vec_cor hh_draw_screen(vec2 player) { static vec_cor previousViewport = {0, 0}; - int offset_px = offset/40*16; - //printf("%d\n",offset_px%2); - vec_cor viewport = hh_update_camera(player,(vec2){.x=0,.y=offset_px},(vec2){.x=20*16,.y=30*16+offset_px/4});//TODO: remove magic number(s) - - hh_update_screen((vec2){.y=viewport.y,.x=0},player); + int offset_py = offsetY / 40 * HH_PPU_SPRITE_HEIGHT; + + int offset_px = (offsetX * HH_PPU_SPRITE_WIDTH) ; + vec_cor viewport = hh_update_camera(player,(vec2){.x = offset_px, .y = offset_py},(vec2){.x = HH_PPU_SCREEN_WIDTH + offset_px, .y = 480 + offset_py});//TODO: remove magic number(s) + viewport.x = CLAMP(viewport.x, 0, level.size.x * HH_PPU_SPRITE_WIDTH - HH_PPU_SCREEN_WIDTH); + viewport.y = CLAMP(viewport.y, 0, level.size.y * HH_PPU_SPRITE_HEIGHT - HH_PPU_SCREEN_HEIGHT); + + hh_update_screen((vec2){.y=viewport.y,.x=viewport.x},player); if (viewport.x == previousViewport.x && viewport.y == previousViewport.y){} else{ - // update previous viewport values - - //printf("viewport y %d\n",viewport.y-(offset/40*16)); - //printf("offset %d\n",offset); hh_ppu_update_aux((hh_s_ppu_loc_aux){ - .bg_shift_x = viewport.x - 0, - .bg_shift_y = viewport.y-(offset/40*16), + .bg_shift_x = viewport.x - offset_px, + .bg_shift_y = viewport.y - offset_py, .fg_fetch = 0, .sysreset = 0, }); previousViewport = viewport; - } return viewport; @@ -93,8 +122,8 @@ void hh_clear_screen(){ void hh_clear_sprite(){ for (int i = 0; i < HH_PPU_FG_SPRITE_COUNT; i++) { hh_ppu_update_foreground(i,(hh_s_ppu_loc_fam_entry){ - .position_x = -16, - .position_y = -16, + .position_x = -HH_PPU_SPRITE_WIDTH, + .position_y = -HH_PPU_SPRITE_HEIGHT, }); } } diff --git a/src/engine/draw_screen.h b/src/engine/draw_screen.h index 0d1b68a..9130842 100644 --- a/src/engine/draw_screen.h +++ b/src/engine/draw_screen.h @@ -11,7 +11,7 @@ #include #include "engine/camera.h" -#define hh_max_x_size 40 +#define hh_max_x_size 40 #define hh_max_y_size 30 /** @brief return a single tile from world binary */ diff --git a/src/engine/level_const.c b/src/engine/level_const.c index b568e86..5ba0187 100644 --- a/src/engine/level_const.c +++ b/src/engine/level_const.c @@ -3,11 +3,16 @@ hh_g_all_levels hh_init_game_levels(){ hh_g_all_levels levels; - levels.currentLevel=0; - - levels.level[0].x=40; - levels.level[0].y=60; + levels.current_level=0; + + levels.level[0].size.x=40; + levels.level[0].size.y=100; levels.level[0].hh_level_completed=false; + + levels.level[1].size.x=100; + levels.level[1].size.y=28; + levels.level[1].hh_level_completed=false; + FILE *fp = fopen("../test/bin/level1_test.bin", "rb"); fseek(fp, 0, SEEK_END); int size = ftell(fp) / sizeof(int); @@ -15,7 +20,17 @@ hh_g_all_levels hh_init_game_levels(){ int* hh_game_level1 = malloc(size * sizeof(int)); fread(hh_game_level1, sizeof(int), size, fp); fclose(fp); + + FILE *lvl2 = fopen("../test/bin/level2_test.bin", "rb"); + fseek(lvl2, 0, SEEK_END); + size = ftell(lvl2) / sizeof(int); + fseek(lvl2, (0 * sizeof(int)) + sizeof(int), SEEK_SET); + int* hh_game_level2 = malloc(size * sizeof(int)); + fread(hh_game_level2, sizeof(int), size, lvl2); + fclose(lvl2); + levels.level[0].place = hh_game_level1; + levels.level[1].place = hh_game_level2; return levels; } diff --git a/src/engine/level_const.h b/src/engine/level_const.h index 7a4aac5..b86ae7b 100644 --- a/src/engine/level_const.h +++ b/src/engine/level_const.h @@ -3,27 +3,27 @@ #include #include #include -#include ` +#include "engine/maths.h" +#include "engine/entity.h" typedef enum { - hh_e_STATE_startingScreen, - hh_e_STATE_Shop, - hh_e_STATE_Gameplay, - hh_e_STATE_GameOver, - hh_e_STATE_HighScore -} hh_e_GameState; - + hh_e_state_starting_screen, + hh_e_state_shop, + hh_e_state_gameplay, + hh_e_state_game_over, + hh_e_state_high_score +} hh_e_game_state; +//entity array met enemeies typedef struct { - int x; - int y; + vec2 size; int hh_total_enemies; int* place; bool hh_level_completed; }hh_level_entity; typedef struct { - hh_level_entity level[1]; - int currentLevel; + hh_level_entity level[2]; + int current_level; }hh_g_all_levels; 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 +#include + +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..b3d2234 --- /dev/null +++ b/src/game_loop/shop.c @@ -0,0 +1,30 @@ +#include "shop.h" + + +void hh_shop(hh_e_game_state* hh_game_state){ + static hh_e_shop_states hh_e_shop = hh_e_shop_show; + + 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_e_shop = hh_e_shop_input; + break; + case hh_e_shop_input: + // todo: make it so that you can choose between shop + if(g_hh_controller_p1.button_primary){ + hh_e_shop = hh_e_shop_end; + } + break; + case hh_e_shop_end: + hh_e_shop = hh_e_shop_show; + *hh_game_state = hh_e_state_gameplay; + break; + default: + hh_e_shop = hh_e_shop_show; + break; + } +} diff --git a/src/game_loop/shop.h b/src/game_loop/shop.h new file mode 100644 index 0000000..7d01b7e --- /dev/null +++ b/src/game_loop/shop.h @@ -0,0 +1,18 @@ +#pragma once + +#include "input.h" +#include "engine/draw_screen.h" +#include "engine/level_const.h" + + +#include +#include + +typedef enum { + hh_e_shop_show, + hh_e_shop_input, + hh_e_shop_end, +} hh_e_shop_states; + + +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 +#include + +typedef enum { + hh_e_state_show, + hh_e_state_input, + hh_e_state_end +} hh_e_screen_states; + + +bool hh_show_starting_screen(); + diff --git a/src/makefile b/src/makefile index d00b0ee..4dc84e6 100644 --- a/src/makefile +++ b/src/makefile @@ -41,10 +41,10 @@ LOCAL_SRCS += main.c \ engine/bullet.c \ engine/title_screen.c \ engine/level_const.c \ - GameLoop/shop.c \ - GameLoop/gameplay.c \ - GameLoop/game_over.c \ - GameLoop/startingScreen.c + game_loop/shop.c \ + game_loop/gameplay.c \ + game_loop/game_over.c \ + game_loop/starting_screen.c CFLAGS += $(SHARED_FLAGS) LFLAGS += $(SHARED_FLAGS) -- cgit v1.2.3