aboutsummaryrefslogtreecommitdiff
path: root/player.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-10-01 18:59:53 +1000
committerquou <quou@disroot.org>2024-10-01 19:00:04 +1000
commita5f6618cd6a692eda3acd934b71355959b388518 (patch)
tree6f5d4813be49ccf9bab8740a14546e6ec3b6dd72 /player.c
parent626a3850ebc4859cecb9b3a003c96b69c2fdf7f9 (diff)
the enemy can hurt the player now
Diffstat (limited to 'player.c')
-rw-r--r--player.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/player.c b/player.c
index 1ebe589..7326fca 100644
--- a/player.c
+++ b/player.c
@@ -8,6 +8,8 @@
#include "render.h"
#include "world.h"
+const Rect player_rect = { 5, 4, 5, 12 };
+
void init_player(Player* p) {
p->anim = asset_id_guy_run_right_anm;
p->x = 0;
@@ -22,6 +24,8 @@ void init_player(Player* p) {
p->cooldown = 0;
p->slashing = 0;
p->face = face_right;
+ p->inv = 0;
+ p->hp = player_health;
}
void update_player_anim(Player* p) {
@@ -30,12 +34,11 @@ void update_player_anim(Player* p) {
}
void update_player_phys(Player* p, const Map* map) {
- const Rect r = {
- 5 << fbits,
- 4 << fbits,
- 5 << fbits,
- 12 << fbits
- };
+ Rect r = player_rect;
+ r.x <<= fbits;
+ r.y <<= fbits;
+ r.w <<= fbits;
+ r.h <<= fbits;
update_body(
map,
&p->x,
@@ -151,6 +154,26 @@ void update_player_move(Player* p, const App* a, World* w) {
}
}
+void update_player_hurt(Player* p, World* w) {
+ int i;
+ Rect r = player_rect;
+ r.x += p->x >> fbits;
+ r.y += p->y >> fbits;
+ if (p->inv) {
+ p->inv--;
+ return;
+ }
+ 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 = enemy_inv_frames;
+ }
+ }
+}
+
void update_player(
Player* p,
World* w,
@@ -158,6 +181,7 @@ void update_player(
const Map* map
) {
update_player_move(p, app, w);
+ update_player_hurt(p, w);
update_player_phys(p, map);
update_player_anim(p);
}