From d2837633da48e3cc0530d718de5e0bbfcd4fcc34 Mon Sep 17 00:00:00 2001 From: quou Date: Mon, 30 Sep 2024 22:28:50 +1000 Subject: enemy invulnerable frames --- config.h | 1 + enemy.c | 6 ++++++ obj.h | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config.h b/config.h index f2b0699..e5c4936 100644 --- a/config.h +++ b/config.h @@ -40,6 +40,7 @@ #define player_lunge_force (f1) #define player_slash_damage 1 +#define enemy_inv_frames 8 #define enemy_demon_move_force 32 #define enemy_demon_attack_dist f1 #define enemy_demon_jump_force (5 << fbits) diff --git a/enemy.c b/enemy.c index bc0bbba..1c82e47 100644 --- a/enemy.c +++ b/enemy.c @@ -44,6 +44,7 @@ void init_enemy(Enemy* e, Enemy_Type t, int x, int y) { e->anim = asset_id_demon_idle_left_anm; e->face = face_left; e->state = enemy_state_patrol; + e->inv = 0; } void update_enemy_anim(Enemy* e) { @@ -82,6 +83,10 @@ void update_enemy_phys(Enemy* e, const Map* map) { void update_enemy_hurt(Enemy* e, const World* w) { Rect a; int i; + if (e->inv) { + e->inv--; + return; + } get_enemy_rect(e->t, &a); a.x += e->x >> fbits; a.y += e->y >> fbits; @@ -91,6 +96,7 @@ void update_enemy_hurt(Enemy* e, const World* w) { e->hp -= dz->hp; e->vx -= dz->vx; e->vy -= dz->vy; + e->inv = enemy_inv_frames; } } } diff --git a/obj.h b/obj.h index 8824a2d..7cbb962 100644 --- a/obj.h +++ b/obj.h @@ -52,7 +52,7 @@ typedef struct { int x, y, vx, vy; int hp, frame, anim; int grounded, headbutted, on_ramp; - int state; + int state, inv; Face face; Rect rect; } Enemy; -- cgit v1.2.3-54-g00ecf