diff options
author | quou <quou@disroot.org> | 2023-05-07 09:46:39 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2023-05-07 09:46:39 +1000 |
commit | 5ef6a71e935e2c3d1e5f9828e8cdbd78403a06a0 (patch) | |
tree | 128326b3234ec3b168f85b7a6749ff0fa4635a09 | |
parent | 40eb179043b77f011fb1048c386ee187f64569d0 (diff) |
Add some frames where the skulls are red after being damaged.
-rw-r--r-- | collision_system.c | 2 | ||||
-rw-r--r-- | components.h | 1 | ||||
-rw-r--r-- | enemy.c | 18 | ||||
-rw-r--r-- | game_config.h | 2 | ||||
-rw-r--r-- | intermediate/enemy.bmp | bin | 8330 -> 8330 bytes | |||
-rw-r--r-- | sprite.c | 8 | ||||
-rw-r--r-- | 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 { @@ -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 Binary files differindex da1e068..ee0df40 100644 --- a/intermediate/enemy.bmp +++ b/intermediate/enemy.bmp @@ -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 */ { @@ -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, |