aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-09-30 22:28:50 +1000
committerquou <quou@disroot.org>2024-09-30 22:28:50 +1000
commitd2837633da48e3cc0530d718de5e0bbfcd4fcc34 (patch)
tree3cac6b4b49b93e199ed5b14e9438a0c026fc8b26
parentee655819d44307d974fb27e1fa04d079a3810d63 (diff)
enemy invulnerable frames
-rw-r--r--config.h1
-rw-r--r--enemy.c6
-rw-r--r--obj.h2
3 files changed, 8 insertions, 1 deletions
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;