diff options
Diffstat (limited to 'src/engine')
| -rw-r--r-- | src/engine/animator.c | 25 | ||||
| -rw-r--r-- | src/engine/enemy_ai.c | 13 | ||||
| -rw-r--r-- | src/engine/entity.c | 5 | ||||
| -rw-r--r-- | src/engine/player_controller.c | 4 | ||||
| -rw-r--r-- | src/engine/sprite_controller.h | 3 | ||||
| -rw-r--r-- | src/engine/types.h | 6 | 
6 files changed, 49 insertions, 7 deletions
| diff --git a/src/engine/animator.c b/src/engine/animator.c index 0811ba7..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) 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; |