From 5ef6a71e935e2c3d1e5f9828e8cdbd78403a06a0 Mon Sep 17 00:00:00 2001 From: quou Date: Sun, 7 May 2023 09:46:39 +1000 Subject: Add some frames where the skulls are red after being damaged. --- collision_system.c | 2 ++ components.h | 1 + enemy.c | 18 ++++++++++++++---- game_config.h | 2 ++ intermediate/enemy.bmp | Bin 8330 -> 8330 bytes sprite.c | 8 ++++---- sprite.h | 4 ++-- 7 files changed, 25 insertions(+), 10 deletions(-) diff --git a/collision_system.c b/collision_system.c index ed05817..2bb8cdb 100644 --- a/collision_system.c +++ b/collision_system.c @@ -6,6 +6,7 @@ #include "components.h" #include "config.h" #include "fx.h" +#include "game_config.h" #include "rect.h" #include "standard.h" #include "world.h" @@ -62,6 +63,7 @@ static void handle_bullet_vs_enemy( pos = &world->positions[bullet]; e = &world->enemies[enemy]; + e->being_damaged = enemy_hit_frames; e->hp--; destroy_entity(world, bullet); new_player_bullet_explosion(world, pos->x, pos->y); diff --git a/components.h b/components.h index 4c1b950..fb0df18 100644 --- a/components.h +++ b/components.h @@ -36,6 +36,7 @@ typedef struct { int hp; int backpedal; int shoot_timer; + int being_damaged; } CEnemy; typedef struct { diff --git a/enemy.c b/enemy.c index 710a280..04baec4 100644 --- a/enemy.c +++ b/enemy.c @@ -37,7 +37,7 @@ Entity new_skull(World* world, int x, int y) { col->w = 14 << fbits; col->h = 14 << fbits; - init_csprite(sprite, sprite_skull_right); + init_csprite(sprite, sprite_skull); enemy->hp = skull_hp; enemy->shoot_timer = 0; @@ -91,6 +91,7 @@ void enemy_system(World* world) { unsigned bits; CPosition* pos; CEnemy* enemy; + CSprite* sprite; Player* player; CPosition* ppos; int dpx, dpy, tpx, tpy, d; @@ -118,10 +119,12 @@ void enemy_system(World* world) { if ( (bits & ctype_position) && (bits & ctype_enemy) && - (bits & ctype_skull) + (bits & ctype_skull) && + (bits & ctype_sprite) ) { - pos = &world->positions[i]; - enemy = &world->enemies[i]; + pos = &world->positions[i]; + enemy = &world->enemies[i]; + sprite = &world->sprites[i]; dpx = ((ppos->x - pos->x) >> 4) + 256; dpy = ((ppos->y - pos->y) >> 4) + 256; @@ -129,6 +132,13 @@ void enemy_system(World* world) { tpy = dpy; d = ((dpx * dpx) >> fbits) + ((dpy * dpy) >> fbits); + if (enemy->being_damaged) { + enemy->being_damaged--; + init_csprite(sprite, sprite_skull_damaged); + } else { + init_csprite(sprite, sprite_skull); + } + if (d < 10 << fbits) { dpx = -dpx; dpy = -dpy; diff --git a/game_config.h b/game_config.h index 4e955a9..3b0f9d3 100644 --- a/game_config.h +++ b/game_config.h @@ -6,6 +6,8 @@ #define player_max_hp 3 #define player_invul_frames 50 +#define enemy_hit_frames 10 + #define skull_hp 3 #define skull_speed (1 << fbits) diff --git a/intermediate/enemy.bmp b/intermediate/enemy.bmp index da1e068..ee0df40 100644 Binary files a/intermediate/enemy.bmp and b/intermediate/enemy.bmp differ diff --git a/sprite.c b/sprite.c index e2914ce..2b5647a 100644 --- a/sprite.c +++ b/sprite.c @@ -21,15 +21,15 @@ static const Sprite sprites[] = { asset_id_bullet, { 14, 14, 14, 9 } }, - /* sprite_skull_left */ + /* sprite_skull */ { asset_id_enemy, - { 16, 0, 16, 16 } + { 0, 0, 16, 16 } }, - /* sprite_skull_right */ + /* sprite_skull_damaged */ { asset_id_enemy, - { 0, 0, 16, 16 } + { 16, 0, 16, 16 } }, /* sprite_skull_debris_1 */ { diff --git a/sprite.h b/sprite.h index 5fd6b2a..8f9f736 100644 --- a/sprite.h +++ b/sprite.h @@ -10,8 +10,8 @@ typedef enum { sprite_player_bullet_right, sprite_player_bullet_up, sprite_player_bullet_down, - sprite_skull_left, - sprite_skull_right, + sprite_skull, + sprite_skull_damaged, sprite_skull_debris_1, sprite_skull_debris_2, sprite_skull_debris_3, -- cgit v1.2.3-54-g00ecf