summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorzlago2024-10-11 18:04:53 +0200
committerzlago2024-10-11 18:04:53 +0200
commit3f5039d3bdeffca261d4e07983667f0f636398cf (patch)
tree5ebf2ecaa6a814c7d782daa9b4f657fb112af7b7 /src
parent2e0f24e0344ee2bd5bd6e6269f39e804c50d05e0 (diff)
more fixes
Diffstat (limited to 'src')
-rw-r--r--src/entity.h4
-rw-r--r--src/walker.c28
2 files changed, 22 insertions, 10 deletions
diff --git a/src/entity.h b/src/entity.h
index 72fccb2..33aca68 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -49,9 +49,9 @@ struct entity {
 
 struct warp {
 	int (*update)(struct warp *);
-	unsigned x, y;
+	int x, y;
 	unsigned w, h;
-	unsigned tox, toy;
+	int tox, toy;
 	struct hitbox hitbox;
 	unsigned timer;
 	void *ext;
diff --git a/src/walker.c b/src/walker.c
index 0d32d57..fbb80d4 100644
--- a/src/walker.c
+++ b/src/walker.c
@@ -15,9 +15,15 @@
 #define ATTACK_DELAY 120
 #define ATTACK_DELAY2 60
 #define ATTACK_REPEAT 60
+#define DETECTION_RANGE to_fixed(64)
+#define GIVE_UP_RANGE to_fixed(96)
+#define CHASE_RANGE to_fixed(48)
+#define RUN_RANGE to_fixed(32)
+#define TARGET_RANGE to_fixed(40)
 
 struct walker_ext {
 	unsigned idle_time, attack_delay, attack_delay2, attack_repeat;
+	unsigned detection_range, give_up_range;
 	signed facing;
 };
 
@@ -243,7 +249,7 @@ static int walker_update(struct entity *self) {
 				anim(self, WALKER_A_WALK);
 				self->state = WALKER_PATROL;
 			}
-			if (abs(entities.player[0].x - self->x) + abs(entities.player[0].y - self->y) < to_fixed(64)) {
+			if (abs(entities.player[0].x - self->x) + abs(entities.player[0].y - self->y) < ext->detection_range) {
 				self->state = WALKER_ALERT_IDLE;
 				self->timer = ext->attack_delay;
 			}
@@ -260,7 +266,7 @@ static int walker_update(struct entity *self) {
 				self->state = WALKER_IDLE;
 				self->timer = ext->idle_time;
 			}
-			if (abs(entities.player[0].x - self->x) + abs(entities.player[0].y - self->y) < to_fixed(64)) {
+			if (abs(entities.player[0].x - self->x) + abs(entities.player[0].y - self->y) < ext->detection_range) {
 				anim(self, WALKER_A_IDLE);
 				self->state = WALKER_ALERT_IDLE;
 				self->timer = ext->attack_delay;
@@ -271,12 +277,12 @@ static int walker_update(struct entity *self) {
 			move(self, 0);
 			ext->facing = self->x > entities.player[0].x? -1: 1;
 			self->facing = ext->facing;
-			if (abs(entities.player[0].x - self->x) > to_fixed(48)) {
+			if (abs(entities.player[0].x - self->x) > CHASE_RANGE) {
 				if (is_walkable(self->x + to_fixed(ext->facing * WALKABLE_CHECK_DISTANCE), self->y)) {
 					anim(self, WALKER_A_WALK);
 					self->state = WALKER_ALERT_CHASE;
 				}
-			} else if (abs(entities.player[0].x - self->x) < to_fixed(32)) {
+			} else if (abs(entities.player[0].x - self->x) < RUN_RANGE) {
 				if (is_walkable(self->x + to_fixed(-ext->facing * WALKABLE_CHECK_DISTANCE), self->y)) {
 					ext->facing = -ext->facing;
 					anim(self, WALKER_A_WALK);
@@ -286,7 +292,7 @@ static int walker_update(struct entity *self) {
 					self->state = WALKER_ALERT_RUN;
 				}
 			}
-			if (abs(entities.player[0].x - self->x) + abs(entities.player[0].y - self->y) > to_fixed(96)) {
+			if (abs(entities.player[0].x - self->x) + abs(entities.player[0].y - self->y) > ext->give_up_range) {
 				self->state = WALKER_IDLE;
 			}
 			self->timer--;
@@ -299,7 +305,7 @@ static int walker_update(struct entity *self) {
 
 		case WALKER_ALERT_CHASE:
 			move(self, ext->facing);
-			if (abs(entities.player[0].x - self->x) < to_fixed(40) || !is_walkable(self->x + to_fixed(ext->facing * WALKABLE_CHECK_DISTANCE), self->y)) {
+			if (abs(entities.player[0].x - self->x) < TARGET_RANGE || !is_walkable(self->x + to_fixed(ext->facing * WALKABLE_CHECK_DISTANCE), self->y)) {
 				anim(self, WALKER_A_IDLE);
 				self->state = WALKER_ALERT_IDLE;
 				self->timer = ext->attack_delay;
@@ -308,7 +314,7 @@ static int walker_update(struct entity *self) {
 
 		case WALKER_ALERT_RUN:
 			move(self, ext->facing);
-			if (abs(entities.player[0].x - self->x) > to_fixed(40)) {
+			if (abs(entities.player[0].x - self->x) > TARGET_RANGE) {
 				anim(self, WALKER_A_IDLE);
 				self->state = WALKER_ALERT_IDLE;
 				self->timer = ext->attack_delay;
@@ -340,7 +346,7 @@ static int walker_update(struct entity *self) {
 				self->state = WALKER_ALERT_IDLE;
 				self->timer = ext->attack_repeat;
 			}
-			if (abs(entities.player[0].x - self->x) + abs(entities.player[0].y - self->y) > to_fixed(96)) {
+			if (abs(entities.player[0].x - self->x) + abs(entities.player[0].y - self->y) > ext->give_up_range) {
 				anim(self, WALKER_A_IDLE);
 				self->state = WALKER_IDLE;
 				self->timer = ext->idle_time;
@@ -415,6 +421,8 @@ struct entity *walker_new(struct entities *entities) {
 		.attack_delay = ATTACK_DELAY,
 		.attack_delay2 = ATTACK_DELAY2,
 		.attack_repeat = ATTACK_REPEAT,
+		.detection_range = DETECTION_RANGE,
+		.give_up_range = GIVE_UP_RANGE,
 		.facing = 1,
 	};
 	anim(self, WALKER_A_FALL);
@@ -437,6 +445,10 @@ int walker_property(struct entity *const restrict self, char const *const restri
 		ext->attack_delay2 = atoi(value);
 	} else if (strcmp(property, "attack repeat") == 0) {
 		ext->attack_repeat = atoi(value);
+	} else if (strcmp(property, "detection range") == 0) {
+		ext->detection_range = to_fixed(atoi(value));
+	} else if (strcmp(property, "give up range") == 0) {
+		ext->give_up_range = to_fixed(atoi(value));
 	} else {
 		return 1;
 	}