aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h1
-rw-r--r--obj.h1
-rw-r--r--player.c38
3 files changed, 36 insertions, 4 deletions
diff --git a/config.h b/config.h
index 7dcf8d7..6a69ee7 100644
--- a/config.h
+++ b/config.h
@@ -50,6 +50,7 @@
#define enemy_demon_attack_dist f1
#define enemy_demon_jump_force (5 << fbits)
#define enemy_slash_damage 1
+#define enemy_touch_damage 1
#define enemy_knockback (4 << fbits)
#define enemy_hurt_freeze 1
diff --git a/obj.h b/obj.h
index f29d5a4..98f2ebf 100644
--- a/obj.h
+++ b/obj.h
@@ -95,6 +95,7 @@ typedef struct {
void init_enemy(Enemy* e, Enemy_Type t, int x, int y);
int update_enemy(Enemy* e, struct World* w);
void ren_enemy(const Enemy* e, struct Renderer* r);
+void get_enemy_rect(Enemy_Type t, Rect* d);
typedef struct {
Rect r;
diff --git a/player.c b/player.c
index b3a1d00..33e6d2c 100644
--- a/player.c
+++ b/player.c
@@ -157,7 +157,7 @@ void update_player_move(Player* p, const App* a, World* w) {
}
void update_player_hurt(Player* p, World* w) {
- int i;
+ int i, cx, cy;
Rect r = player_rect;
r.x += p->x >> fbits;
r.y += p->y >> fbits;
@@ -165,17 +165,47 @@ void update_player_hurt(Player* p, World* w) {
p->inv--;
return;
}
+ cx = p->x + ((player_rect.w >> 1) << fbits);
+ cy = p->y + ((player_rect.h >> 1) << fbits);
for (i = 0; i < w->deathzone_count; i++) {
const Deathzone* dz = &w->deathzones[i];
if (!dz->friendly && rects_overlap(&r, &dz->r)) {
p->hp -= dz->hp;
p->vx -= dz->vx;
p->vy -= dz->vy;
- p->inv = player_inv_frames;
- w->freeze = player_hurt_freeze;
- return;
+ inst_effect(w, cx, cy, -dz->vx, -dz->vy, 32);
+ goto took_damage;
}
}
+ for (i = 0; i < w->enemy_count; i++) {
+ const Enemy* e = &w->enemies[i];
+ Rect er;
+ get_enemy_rect(e->t, &er);
+ er.x += e->x >> fbits;
+ er.y += e->y >> fbits;
+ if (rects_overlap(&r, &er)) {
+ int ecx = e->x + ((er.w >> 1) << fbits);
+ int ecy = e->y + ((er.h >> 1) << fbits);
+ int tx = cx - ecx;
+ int ty = cy - ecy;
+ int l = fxsqrt(
+ ((tx * tx) >> fbits) +
+ ((ty * ty) >> fbits)
+ );
+ tx <<= fbits;
+ ty <<= fbits;
+ tx /= l;
+ ty /= l;
+ p->hp -= enemy_touch_damage;
+ inst_effect(w, cx, cy, tx, ty, 32);
+ goto took_damage;
+ }
+ }
+ return;
+took_damage:
+ p->inv = player_inv_frames;
+ w->freeze = player_hurt_freeze;
+ play_sound(2048);
}
void update_player_special(Player* p, const App* a, World* w) {