diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/GameLoop/shop.c | 78 | ||||
-rw-r--r-- | src/GameLoop/shop.h | 32 | ||||
-rw-r--r-- | src/GameLoop/startingScreen.c | 32 | ||||
-rw-r--r-- | src/GameLoop/startingScreen.h | 14 | ||||
-rw-r--r-- | src/demo.c | 1 | ||||
-rw-r--r-- | src/engine/entity.c | 50 | ||||
-rw-r--r-- | src/engine/entity.h | 4 | ||||
-rw-r--r-- | src/engine/player_controller.c | 143 | ||||
-rw-r--r-- | src/engine/player_controller.h | 2 | ||||
-rw-r--r-- | src/game_loop/gameplay.c | 49 | ||||
-rw-r--r-- | src/game_loop/starting_screen.c | 4 |
11 files changed, 121 insertions, 288 deletions
diff --git a/src/GameLoop/shop.c b/src/GameLoop/shop.c deleted file mode 100644 index fb7ef4c..0000000 --- a/src/GameLoop/shop.c +++ /dev/null @@ -1,78 +0,0 @@ -#include "shop.h" -#include "engine/maths.h" -#include "ppu/ppu.h" - -bool hh_show_Shop(){ - static hh_e_ShopStates hh_e_Shop = hh_e_shop_init; - static hh_e_upgrades upgrades[HH_SHOP_UPG_DISPLAY] = {0}; - static uint8_t selected = 0; - - switch (hh_e_Shop) - { - case hh_e_shop_init: - hh_clear_screen(); - hh_clear_sprite(); - - //TODO: render shop bg from level file here - //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; - return false; - 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(g_hh_controller_p1.button_primary){ - //apply selected upgrade - hh_e_Shop = hh_e_shop_end; - } - if(g_hh_controller_p1.button_secondary){ - hh_e_Shop = hh_e_shop_end; - } - break; - case hh_e_shop_end: - hh_e_Shop = hh_e_shop_init; - return true; - break; - default: - hh_e_Shop = hh_e_shop_init; - break; - } - return false; -} - -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 = i - }); - } -} - -void hh_shift_selected(uint8_t* pos, bool dir, uint8_t min, uint8_t max) { - if (dir) { - pos = CLAMP(++pos,min,max); - } else { - if (pos > 0) { - pos--; - } - } -} diff --git a/src/GameLoop/shop.h b/src/GameLoop/shop.h deleted file mode 100644 index 5cd6b53..0000000 --- a/src/GameLoop/shop.h +++ /dev/null @@ -1,32 +0,0 @@ -#include "input.h" -#include "engine/draw_screen.h" - - - -#include <stdint.h> -#include <stdbool.h> - -typedef enum { - hh_e_shop_init, - hh_e_shop_main, - hh_e_shop_end -} hh_e_ShopStates; - -/** @brief amount of upgrade types */ -#define HH_SHOP_UPG_COUNT 2 -/** @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_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); - -bool hh_show_Shop(); 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 <stdint.h> -#include <stdbool.h> - -typedef enum { - hh_e_STATE_SHOW, - hh_e_STATE_Input, - hh_e_STATE_END -} hh_e_screenStates; - - -bool hh_show_startingScreen(); - @@ -17,6 +17,7 @@ #include "game_loop/gameplay.h" #include "game_loop/shop.h" +#include <stdbool.h> hh_g_all_levels hh_game; diff --git a/src/engine/entity.c b/src/engine/entity.c index 58b62c9..7b780cf 100644 --- a/src/engine/entity.c +++ b/src/engine/entity.c @@ -127,3 +127,53 @@ bool hh_distance_circles (vec2 object_1, vec2 object_2, int radius_1, int radius return false; } } + +void hh_jump_entity(hh_entity* object_1){ + if (object_1->is_grounded == true) {//JUMP + object_1->vel.y = -10; + object_1->is_grounded = false; + } +} +void hh_gravity_entity(hh_entity* object_1){ + if (object_1->is_grounded == false && object_1->vel.y < 6) { + object_1->vel.y += 1; //gravity + } +} +void hh_hit_entity(hh_entity* object_1, int8_t* hit_timer, int8_t* direction){ + if(object_1->is_hit == true){ + hit_timer = 9; + object_1->is_hit = false; + } + if(hit_timer > -10){ + hit_timer--; + } + + if(hit_timer <= 0){ + if(direction != 0){ + if(object_1->vel.x > -1 * object_1->speed && object_1->vel.x < object_1->speed) { + object_1->vel.x = object_1->vel.x + direction; + } else { + if (object_1->vel.x > 0) { + object_1->vel.x--; + } else if(object_1->vel.x < 0) { + object_1->vel.x++; + } + } + } else { + if (object_1->vel.x > 0) { + object_1->vel.x--; + } else if(object_1->vel.x < 0) { + object_1->vel.x++; + } + } + + } else { + if (object_1->vel.x > 0) { + object_1->vel.x--; + } else if(object_1->vel.x < 0) { + object_1->vel.x++; + } + object_1->vel.y++; + } + +} diff --git a/src/engine/entity.h b/src/engine/entity.h index 68b450d..b681bd8 100644 --- a/src/engine/entity.h +++ b/src/engine/entity.h @@ -43,4 +43,8 @@ hh_entity hh_enemy_collision(hh_entity temp_player, hh_entity temp_enemy); /// @return true if objects collids bool hh_distance_circles(vec2 object_1, vec2 object_2, int radius_1, int radius_2); +// TODO: comments on functions below +void hh_jump_entity(hh_entity* ); +void hh_gravity_entity(hh_entity* ); +void hh_hit_entity(hh_entity* object_1, int8_t* hit_timer, int8_t* direction); diff --git a/src/engine/player_controller.c b/src/engine/player_controller.c index cec28df..096243b 100644 --- a/src/engine/player_controller.c +++ b/src/engine/player_controller.c @@ -7,30 +7,8 @@ #include "engine/animator.h" #include "engine/bullet.h" -void hh_player_actions() { - static hh_entity player={ - .hp = 4, - .speed = 6, - .is_grounded = false, - .is_hit = false, - .radius = 8, - .pos = (vec2){128+16,32}, - .vel = (vec2){0,0}, - .size = (vec2){32,32}, - .render = { - .frame0 = 80, - .palette = 3, - .ppu_foreground_index = 0, - .fam = (hh_s_ppu_loc_fam_entry){ - .horizontal_flip = false, - .vertical_flip = false, - .palette_index = 3, - .tilemap_index = 80, - } - } - }, player_new = {0}; - - static hh_entity bullet={ +void hh_player_actions(hh_entity* player, vec_cor cam_pos){ + static hh_entity bullet={ // .hp = 4, .speed = 6, .is_grounded = true, @@ -49,124 +27,37 @@ void hh_player_actions() { } } }; + static hh_entity player_new = {0}; + player_new = *player; - static hh_entity enemy={ - .hp = 4, - .speed = 6, - .is_grounded = false, - .is_hit = false, - .radius = 8, - .pos = (vec2){128,48}, - .vel = (vec2){0,0}, - .size = (vec2){16,16}, - .render = { - .frame0 = 20, - .palette = 7, - .ppu_foreground_index = 16, - .fam = (hh_s_ppu_loc_fam_entry){ - .horizontal_flip = false, - .vertical_flip = false, - .palette_index = 7, - .tilemap_index = 1, - } - } - }; - player_new = player; - // hh_input_read(); - static uint8_t hit = 0; int8_t hit_timer = 0; int8_t direction_x = (-1 * g_hh_controller_p1.dpad_left) + (1 * g_hh_controller_p1.dpad_right); int8_t direction_y = (-1 * g_hh_controller_p1.dpad_up) + (1 * g_hh_controller_p1.dpad_down); - if(player.is_hit == true){ - hit_timer = 9; - player.is_hit = false; - } - if(hit_timer > -10){ - hit_timer--; - } - - if(hit_timer <= 0){ - if(direction_x != 0){ - if(player.vel.x > -1 * player.speed && player.vel.x < player.speed) { - player.vel.x = player.vel.x + direction_x; - } else { - if (player.vel.x > 0) { - player.vel.x--; - } else if(player.vel.x < 0) { - player.vel.x++; - } - } - } else { - if (player.vel.x > 0) { - player.vel.x--; - } else if(player.vel.x < 0) { - player.vel.x++; - } - } - - /* // movement Y (w-s) disable gravity to use this - if(direction_y != 0){ - if(player.vel.y > -4 && player.vel.y < 4 ) { - player.vel.y = player.vel.y + direction_y; - } - } else { - if (player.vel.y > 0) { - player.vel.y--; - } else if(player.vel.y < 0) { - player.vel.y++; - } - } - - */ - } else { - if (player.vel.x > 0) { - player.vel.x--; - } else if(player.vel.x < 0) { - player.vel.x++; - } - player.vel.y++; - } - - - if (g_hh_controller_p1.button_primary && player.is_grounded == true) {//JUMP - player.vel.y = -10; - player.is_grounded = false; - } else if (player.vel.y < 6){ - player.vel.y += 1; //gravity + hh_hit_entity(player,hit_timer,direction_x); + hh_gravity_entity(player); + if(g_hh_controller_p1.button_primary){ + hh_jump_entity(player); } - -/* - player.vel = (vec2){.x = (-1 * g_hh_controller_p1.dpad_left) + (1 * g_hh_controller_p1.dpad_right), - .y = (-1 * g_hh_controller_p1.dpad_up) + (1 * g_hh_controller_p1.dpad_down) }; - player_new.vel = (vec2){ - .x = player.vel.x, - .y = player.vel.y, - }; -*/ player_new.vel = (vec2){ - .x = player.vel.x, - .y = player.vel.y, + .x = player->vel.x, + .y = player->vel.y, }; - - player_new = hh_enemy_collision(player, enemy); - + player_new.pos = (vec2){ - .x = player.pos.x + player_new.vel.x, - .y = player.pos.y + player_new.vel.y, + .x = player->pos.x + player_new.vel.x, + .y = player->pos.y + player_new.vel.y, }; - player = hh_background_collision( player, player_new); + *player = hh_background_collision ( *player, player_new); - vec_cor cam_pos;//value in tiles - cam_pos = hh_draw_screen(player.pos); - hh_shoot_bullet(player.pos, cam_pos ,&bullet); + hh_shoot_bullet(player->pos, cam_pos ,&bullet); uint16_t idx = 16; - idx = hh_update_sprite(idx, &player, cam_pos); - idx = hh_update_sprite(idx, &enemy, cam_pos); + idx = hh_update_sprite(idx, player, cam_pos); + // idx = hh_update_sprite(idx, &enemy, cam_pos); idx =16; diff --git a/src/engine/player_controller.h b/src/engine/player_controller.h index 400c18e..4a325e8 100644 --- a/src/engine/player_controller.h +++ b/src/engine/player_controller.h @@ -4,4 +4,4 @@ #include "engine/entity.h" // inputs -void hh_player_actions(); +void hh_player_actions(hh_entity* player, vec_cor cam_pos); diff --git a/src/game_loop/gameplay.c b/src/game_loop/gameplay.c index 295eb5d..bc6c98d 100644 --- a/src/game_loop/gameplay.c +++ b/src/game_loop/gameplay.c @@ -5,6 +5,47 @@ 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 player1={ + .hp = 4, + .speed = 6, + .is_grounded = false, + .is_hit = false, + .radius = 8, + .pos = (vec2){32,32}, + .size = (vec2){32,32}, + .vel = (vec2){0,0}, + .render = { + .frame0 = 80, + .palette = 3, + .fam = (hh_s_ppu_loc_fam_entry){ + .horizontal_flip = false, + .vertical_flip = false, + .palette_index = 3, + .tilemap_index = 80, + } + } + }; + // enemy gets replaced here is just for reference + static hh_entity enemy={ + .hp = 4, + .speed = 6, + .is_grounded = false, + .is_hit = false, + .radius = 8, + .pos = (vec2){128,48}, + .vel = (vec2){0,0}, + // .vec = (vec2){0,0}, + .render = { + .frame0 = 20, + .palette = 7, + .fam = (hh_s_ppu_loc_fam_entry){ + .horizontal_flip = false, + .vertical_flip = false, + .palette_index = 7, + .tilemap_index = 1, + } + } + }; switch (gameplay) { @@ -13,10 +54,12 @@ void hh_gameplay(hh_g_all_levels game, hh_e_game_state* hh_game_state){ gameplay = hh_e_play_level; break; case hh_e_play_level: - // todo: here come all the different functions for the gameplay - hh_player_actions(); - + // 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); + // enemy's diff --git a/src/game_loop/starting_screen.c b/src/game_loop/starting_screen.c index 6ab0278..c11e4fc 100644 --- a/src/game_loop/starting_screen.c +++ b/src/game_loop/starting_screen.c @@ -1,8 +1,8 @@ -#include "starting_screen.h"" +#include "starting_screen.h" #include "input.h" #include "engine/title_screen.h" #include "engine/draw_screen.h" -// #include "engine/player_controller.h" +#include "engine/player_controller.h" bool hh_show_starting_screen(){ static hh_e_screen_states hh_e_starting_screen = hh_e_state_show; |