aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/settings.json6
-rw-r--r--src/demo.c4
-rw-r--r--src/engine/animator.c26
-rw-r--r--src/engine/enemy_ai.c13
-rw-r--r--src/engine/entity.c5
-rw-r--r--src/engine/player_controller.c4
-rw-r--r--src/engine/sprite_controller.h3
-rw-r--r--src/engine/types.h6
-rw-r--r--src/game_loop/gameplay.c5
-rw-r--r--src/game_loop/shop.c34
-rw-r--r--src/game_loop/shop.h15
-rw-r--r--src/game_loop/ui.c16
-rw-r--r--src/game_loop/ui.h5
-rw-r--r--src/static/.gitignore1
-rw-r--r--src/static/dynamic.tsx71
15 files changed, 173 insertions, 41 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index d027762..55d7b04 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -8,5 +8,9 @@
}
},
"cmake.configureOnOpen": false,
- "files.eol": "\n"
+ "files.eol": "\n",
+ "files.associations": {
+ "entity.h": "c",
+ "shop.h": "c"
+ }
}
diff --git a/src/demo.c b/src/demo.c
index 20f8381..d072dbc 100644
--- a/src/demo.c
+++ b/src/demo.c
@@ -48,6 +48,8 @@ void hh_demo_setup() {
}
void hh_demo_loop(unsigned long frame) {
+ static uint64_t hh_rng_seed = 0;
+ hh_rng_seed++;
switch (hh_game_states)
@@ -59,7 +61,7 @@ void hh_demo_loop(unsigned long frame) {
}
break;
case hh_e_state_shop:
- hh_shop(&hh_game_states, &hh_game.shop);
+ hh_e_upgrades upg = hh_shop(&hh_game_states, &hh_game, hh_rng_seed);
break;
case hh_e_state_gameplay:
hh_gameplay(&hh_game, &hh_game_states);
diff --git a/src/engine/animator.c b/src/engine/animator.c
index 71d0582..f188096 100644
--- a/src/engine/animator.c
+++ b/src/engine/animator.c
@@ -6,21 +6,38 @@
#define hh_white_palette 6
+#define hh_animate_cycle 4
void hh_animate_hit(hh_s_rendering* in, bool hit) {
if (hit) {
in->fam.palette_index = hh_white_palette;
- } else {
+ in->cooldown = hh_animate_cycle;
+ } else if(in->cooldown == 0) {
in->fam.palette_index = in->palette;
+ } else {
+ if (in->cooldown > 0) {
+ in->cooldown--;
+ }
}
}
void hh_animate(hh_s_rendering* in, uint16_t start, uint16_t end, uint8_t step) {
- if (in->fam.tilemap_index >= start && in->fam.tilemap_index < end) {
- in->fam.tilemap_index += step;
- } else {// rollover
+ if (in->fam.tilemap_index < start) {//check for sudden animation change
in->fam.tilemap_index = start;
+ in->cooldown = hh_animate_cycle;
+ } else {
+ if (in->cooldown-- == 0) {
+
+ if (in->fam.tilemap_index < end) {
+ in->fam.tilemap_index += step;
+ } else {// rollover
+ in->fam.tilemap_index = start;
+ }
+ in->cooldown = hh_animate_cycle;
+ }
+
}
+
}
//TODO: if entity not inside of screen, don't update idx (problems with old idx not being overwritten anymore)
@@ -45,5 +62,4 @@ void hh_show_quad(uint16_t *idx, hh_s_rendering* in) {
temp.position_y = CLAMP(in->fam.position_y, -16, HH_PPU_SCREEN_HEIGHT);
temp.position_x = CLAMP(in->fam.position_x, -16, HH_PPU_SCREEN_WIDTH);
hh_ppu_update_foreground(++*idx, temp);
- temp.tilemap_index++;
}
diff --git a/src/engine/enemy_ai.c b/src/engine/enemy_ai.c
index 81d04d9..974de9e 100644
--- a/src/engine/enemy_ai.c
+++ b/src/engine/enemy_ai.c
@@ -34,9 +34,15 @@ void hh_slime_ai(hh_entity* enemy, hh_entity player){
hh_gravity_entity(enemy);
hh_update_enemy_movement(enemy);
+ hh_animate(&enemy->render,
+ HH_TM_SLIME_JUMPABLE_OFFSET ,
+ HH_TM_SLIME_JUMPABLE_OFFSET + 3,1
+ );
+
}
void hh_jump_slime_ai(hh_entity* enemy, hh_entity player){
+ bool jumped = false;
int8_t direction = hh_get_direction(player.pos.x, enemy->pos.x);
hh_gravity_entity(enemy);
if((player.pos.x - enemy->pos.x) >= -hunt_player && (player.pos.x - enemy->pos.x) <= hunt_player){
@@ -44,11 +50,16 @@ void hh_jump_slime_ai(hh_entity* enemy, hh_entity player){
// TODO: fix this if statement and make it cleaner. this makes the enemy jump when the player mets the condition
if((player.pos.y - enemy->pos.y) < -16 && (player.pos.y - enemy->pos.y) >= -100 && (player.pos.x - enemy->pos.x) >= -10 && (player.pos.x - enemy->pos.x) <= 10){
hh_jump_entity(enemy);
+ jumped = true;
}
}
-
+ hh_animate(&enemy->render,
+ HH_TM_SLIME_JUMPABLE_OFFSET + (jumped?4:0),
+ HH_TM_SLIME_JUMPABLE_OFFSET + (enemy->render.fam.tilemap_index>=HH_TM_SLIME_JUMPABLE_OFFSET+5 ? 7 : 3),1
+ );
hh_update_enemy_movement(enemy);
+
}
#define terror_owl_attack_timer 100
#define terror_owl_follow_player_delay 5
diff --git a/src/engine/entity.c b/src/engine/entity.c
index eba6481..4bf1b60 100644
--- a/src/engine/entity.c
+++ b/src/engine/entity.c
@@ -173,7 +173,9 @@ void hh_jump_entity(hh_entity* object_1){
}
void hh_gravity_entity(hh_entity* object_1){
if (object_1->is_grounded == false) {
- object_1->vel.y += 1; //gravity
+ if(object_1->vel.y < 15) {
+ object_1->vel.y += 1; //gravity
+ }
}
}
@@ -181,6 +183,7 @@ void hh_movement_entity(hh_entity* object_1, int8_t* direction){
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;
+ object_1->render.fam.horizontal_flip=(object_1->vel.x>0?0:1);// flips direction of object_1
} else {
if (object_1->vel.x > 0) {
object_1->vel.x--;
diff --git a/src/engine/player_controller.c b/src/engine/player_controller.c
index 0148792..7e2e678 100644
--- a/src/engine/player_controller.c
+++ b/src/engine/player_controller.c
@@ -37,6 +37,10 @@ void hh_player_actions(hh_entity* player){
*player = hh_background_collision ( *player, player_new);
+
+ if (direction_x != 0) {
+ player->render.fam.horizontal_flip = (direction_x > 0 ?0:1);
+ }
}
diff --git a/src/engine/sprite_controller.h b/src/engine/sprite_controller.h
index 93a2aaf..7467289 100644
--- a/src/engine/sprite_controller.h
+++ b/src/engine/sprite_controller.h
@@ -18,6 +18,7 @@
#define HH_PAL_IDX_BRICK 1
#define HH_PAL_IDX_SLIME 2
#define HH_PAL_IDX_HUD 2
+#define HH_PAL_IDX_UPGRADE 2
#define HH_PAL_IDX_BULLET 3
#define HH_PAL_IDX_GOZER 3
#define HH_PAL_IDX_TITLE_SCREEN_ICON 3
@@ -35,7 +36,7 @@ const static uint8_t hh_g_sprite_palette[HH_TM_GROUPS] = {
HH_PAL_IDX_TITLE_SCREEN_ICON,
HH_PAL_IDX_TITLE_SCREEN_ICON,
HH_PAL_IDX_HUD,
- HH_PAL_IDX_HUD,
+ HH_PAL_IDX_UPGRADE,
HH_PAL_IDX_BULLET,
HH_PAL_IDX_GOZER,
HH_PAL_IDX_SLIME,
diff --git a/src/engine/types.h b/src/engine/types.h
index 5fc80fa..ba41ca7 100644
--- a/src/engine/types.h
+++ b/src/engine/types.h
@@ -26,10 +26,16 @@ typedef struct {
hh_s_ppu_loc_fam_entry fam; //screen
uint16_t frame0;
uint16_t palette;
+ uint16_t cooldown;
}hh_s_rendering;
typedef struct {
+ uint8_t* start, len;
+}hh_s_animations;
+
+
+typedef struct {
vec2 pos, vel, size;
bool is_grounded;
bool is_hit;
diff --git a/src/game_loop/gameplay.c b/src/game_loop/gameplay.c
index 3d750f4..200dfac 100644
--- a/src/game_loop/gameplay.c
+++ b/src/game_loop/gameplay.c
@@ -10,7 +10,7 @@ void hh_gameplay(hh_g_all_levels* game, hh_e_game_state* hh_game_state){
static hh_entity* bullets;
static hh_entity player1={
.hp = 4,
- .speed = 6,
+ .speed = 3,
.is_grounded = false,
.is_hit = false,
.radius = 8,
@@ -48,7 +48,8 @@ void hh_gameplay(hh_g_all_levels* game, hh_e_game_state* hh_game_state){
.vertical_flip = false,
.palette_index = 2,
.tilemap_index = HH_TM_SLIME_OFFSET,
- }
+ },
+ .cooldown = 0
}
};
static int total_bullets = 15;
diff --git a/src/game_loop/shop.c b/src/game_loop/shop.c
index 60fc70b..c8dcfe5 100644
--- a/src/game_loop/shop.c
+++ b/src/game_loop/shop.c
@@ -4,7 +4,7 @@
#include "game_loop/ui.h"
-void hh_shop(hh_e_game_state* hh_game_state, hh_level_entity* level_shop){
+hh_e_upgrades hh_shop(hh_e_game_state* hh_game_state, hh_g_all_levels* levels, int rng_seed){
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;
@@ -17,12 +17,15 @@ void hh_shop(hh_e_game_state* hh_game_state, hh_level_entity* level_shop){
// hh_clear_sprite();
// TODO: make function to show shop
//hh_setup_shop();
- hh_setup_screen(*level_shop);
- hh_shop_init(&upgrades);
+ hh_setup_screen(levels->shop);
+ hh_shop_upg_init(&upgrades, rng_seed);
selected = HH_SHOP_UPG_DISPLAY/2;
hh_shop_display(selected, &upgrades);
int idx = 16;
- hh_ui_show_char(&idx,"aBYz09",(vec2){32,32});
+ // hh_ui_show_char(&idx,"abyz09",(vec2){32,32});
+ char* c[3];
+ itoa(c,levels->current_level);
+ hh_ui_show_char(&idx,c,(vec2){304-16-8,0});
hh_e_shop = hh_e_shop_main;
break;
@@ -39,6 +42,7 @@ void hh_shop(hh_e_game_state* hh_game_state, hh_level_entity* level_shop){
if(g_hh_controller_p1.button_primary){
//apply selected upgrade
// hh_e_shop = hh_e_shop_end;
+ return upgrades[selected];
}
if(g_hh_controller_p1.button_secondary){//Quick exit
hh_e_shop = hh_e_shop_end;
@@ -52,15 +56,21 @@ void hh_shop(hh_e_game_state* hh_game_state, hh_level_entity* level_shop){
hh_e_shop = hh_e_shop_show;
break;
}
+ return hh_e_NULL;
}
uint8_t hh_shop_translate_upgrades(hh_e_upgrades upg) {
- return upg+10;
+ return HH_TM_UPGRADES_OFFSET+upg;
}
-void hh_shop_init(hh_e_upgrades* in) {
+void hh_shop_upg_init(hh_e_upgrades* in, int seed) {
+ srand(seed);
for (int i = 0; i < HH_SHOP_UPG_DISPLAY; i++) {
- in[i] = i%HH_SHOP_UPG_COUNT;
+ hh_e_upgrades rng = rand()%(HH_SHOP_UPG_COUNT);
+ while (rng == in[i-1]){
+ rng = rand()%(HH_SHOP_UPG_COUNT);
+ }
+ in[i] = rng;
}
}
@@ -74,18 +84,10 @@ void hh_shop_display(uint8_t selected, hh_e_upgrades* upgrades) {
(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,
+ .palette_index = HH_PAL_IDX_UPGRADE,
.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
index 6f8f5a7..c4f3ced 100644
--- a/src/game_loop/shop.h
+++ b/src/game_loop/shop.h
@@ -3,6 +3,7 @@
#include "input.h"
#include "engine/draw_screen.h"
#include "engine/level_const.h"
+#include "engine/sprite_controller.h"
#include <stdint.h>
@@ -20,18 +21,18 @@ typedef enum {
#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_NULL = -1,
hh_e_upg_heal,
hh_e_upg_max_health,
+ hh_e_upg_jump,
+ hh_e_upg_damage,
+ hh_e_upg_max_ammo,
+ hh_e_upg_speed,
} hh_e_upgrades;
/** @brief init */
-void hh_shop_init(hh_e_upgrades* in);
+void hh_shop_upg_init(hh_e_upgrades* in, int seed);
/** @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* ,hh_level_entity* );
+hh_e_upgrades hh_shop(hh_e_game_state* ,hh_g_all_levels* , int);
diff --git a/src/game_loop/ui.c b/src/game_loop/ui.c
index 3354d43..60dbfc2 100644
--- a/src/game_loop/ui.c
+++ b/src/game_loop/ui.c
@@ -16,7 +16,6 @@ void hh_ui_show_hp(int* idx, hh_entity* player, uint8_t max_hp, vec_cor cam_pos)
});
}
}
-
void hh_ui_show_char(int* idx, char* str, vec2 pos) {
int i = 0;
int tilemap_idx,
@@ -38,10 +37,23 @@ void hh_ui_show_char(int* idx, char* str, vec2 pos) {
.horizontal_flip = false, .vertical_flip = false,
.palette_index = palette_idx,
.tilemap_index = tilemap_idx,
- .position_x = 8 + i*15, .position_y = 8
+ .position_x = pos.x + i*15, .position_y = pos.y
}
});
i++;
}
}
+
+void itoa(char *c, int i) {
+ c[0] = i + '0';
+ c[1] = '\0';
+}
+
+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);
+ }
+}
diff --git a/src/game_loop/ui.h b/src/game_loop/ui.h
index 7a8ffbd..073824e 100644
--- a/src/game_loop/ui.h
+++ b/src/game_loop/ui.h
@@ -17,3 +17,8 @@ void hh_ui_show_hp(int* idx, hh_entity* player, uint8_t max_hp, vec_cor cam_pos)
void hh_ui_show_char(int* idx, char* str, vec2 pos);
+/** @brief converts char* [0] to i and [1]='\0' */
+void itoa(char *c, int i);
+
+/** @brief moves 'cursor' through selection field */
+void hh_shift_selected(uint8_t *pos, bool dir, uint8_t min, uint8_t max);
diff --git a/src/static/.gitignore b/src/static/.gitignore
index e960c6e..4d628f9 100644
--- a/src/static/.gitignore
+++ b/src/static/.gitignore
@@ -7,3 +7,4 @@ tiled.mk
*.csv
*.out
*.tiled-session
+*.tmx
diff --git a/src/static/dynamic.tsx b/src/static/dynamic.tsx
index 742083f..fde4347 100644
--- a/src/static/dynamic.tsx
+++ b/src/static/dynamic.tsx
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
-<tileset version="1.10" tiledversion="1.10.1" name="dynamic" tilewidth="16" tileheight="16" tilecount="108" columns="0">
+<tileset version="1.10" tiledversion="1.10.1" name="dynamic" tilewidth="16" tileheight="16" tilecount="129" columns="0">
<grid orientation="orthogonal" width="1" height="1"/>
+ <tile id="107">
+ <image width="16" height="16" source="tiled/font_35.png"/>
+ </tile>
<tile id="0">
<image width="16" height="16" source="tiled/font_34.png"/>
</tile>
@@ -103,9 +106,51 @@
<tile id="33">
<image width="16" height="16" source="tiled/font_01.png"/>
</tile>
+ <tile id="108">
+ <image width="16" height="16" source="tiled/boss1_05.png"/>
+ </tile>
+ <tile id="109">
+ <image width="16" height="16" source="tiled/boss1_04.png"/>
+ </tile>
+ <tile id="110">
+ <image width="16" height="16" source="tiled/boss1_03.png"/>
+ </tile>
+ <tile id="111">
+ <image width="16" height="16" source="tiled/boss1_02.png"/>
+ </tile>
+ <tile id="112">
+ <image width="16" height="16" source="tiled/boss1_01.png"/>
+ </tile>
+ <tile id="113">
+ <image width="16" height="16" source="tiled/boss1_00.png"/>
+ </tile>
<tile id="34">
<image width="16" height="16" source="tiled/font_00.png"/>
</tile>
+ <tile id="114">
+ <image width="16" height="16" source="tiled/slime_jumpable_07.png"/>
+ </tile>
+ <tile id="115">
+ <image width="16" height="16" source="tiled/slime_jumpable_06.png"/>
+ </tile>
+ <tile id="116">
+ <image width="16" height="16" source="tiled/slime_jumpable_05.png"/>
+ </tile>
+ <tile id="117">
+ <image width="16" height="16" source="tiled/slime_jumpable_04.png"/>
+ </tile>
+ <tile id="118">
+ <image width="16" height="16" source="tiled/slime_jumpable_03.png"/>
+ </tile>
+ <tile id="119">
+ <image width="16" height="16" source="tiled/slime_jumpable_02.png"/>
+ </tile>
+ <tile id="120">
+ <image width="16" height="16" source="tiled/slime_jumpable_01.png"/>
+ </tile>
+ <tile id="121">
+ <image width="16" height="16" source="tiled/slime_jumpable_00.png"/>
+ </tile>
<tile id="35">
<image width="16" height="16" source="tiled/slime_03.png"/>
</tile>
@@ -130,6 +175,27 @@
<tile id="42">
<image width="16" height="16" source="tiled/bullet_01.png"/>
</tile>
+ <tile id="122">
+ <image width="16" height="16" source="tiled/upgrades_04.png"/>
+ </tile>
+ <tile id="123">
+ <image width="16" height="16" source="tiled/upgrades_03.png"/>
+ </tile>
+ <tile id="124">
+ <image width="16" height="16" source="tiled/upgrades_02.png"/>
+ </tile>
+ <tile id="125">
+ <image width="16" height="16" source="tiled/upgrades_01.png"/>
+ </tile>
+ <tile id="126">
+ <image width="16" height="16" source="tiled/upgrades_00.png"/>
+ </tile>
+ <tile id="127">
+ <image width="16" height="16" source="tiled/hud_heart_01.png"/>
+ </tile>
+ <tile id="128">
+ <image width="16" height="16" source="tiled/hud_heart_00.png"/>
+ </tile>
<tile id="43">
<image width="16" height="16" source="tiled/bullet_00.png"/>
</tile>
@@ -322,7 +388,4 @@
<tile id="106">
<image width="16" height="16" source="tiled/air_00.png"/>
</tile>
- <tile id="107">
- <image width="16" height="16" source="tiled/font_35.png"/>
- </tile>
</tileset>