summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-19 17:41:43 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-19 17:41:43 (EDT)
commit2aba6b402b43877dcd7d42c51df8e91bd355b32d (patch)
tree50ed80a2533cae707c9f4752dd957f69e1150065
parent44a31faf04009ee147f1e2fbf3ba3cab9fd13b12 (diff)
downloadmazefight-2aba6b402b43877dcd7d42c51df8e91bd355b32d.zip
mazefight-2aba6b402b43877dcd7d42c51df8e91bd355b32d.tar.gz
mazefight-2aba6b402b43877dcd7d42c51df8e91bd355b32d.tar.bz2
Revert "char/enemy: Try to fix movement lag"
This reverts commit 44a31faf04009ee147f1e2fbf3ba3cab9fd13b12.
-rw-r--r--src/char/enemy.c71
1 files changed, 36 insertions, 35 deletions
diff --git a/src/char/enemy.c b/src/char/enemy.c
index a8cda76..3f9f994 100644
--- a/src/char/enemy.c
+++ b/src/char/enemy.c
@@ -112,6 +112,39 @@ _mf_enemy_step(struct mf_char *c)
static int
_mf_enemy_turn(struct mf_char *c)
{
+ struct mf_enemy *e = (struct mf_enemy *) c;
+ int dx;
+ int dy;
+ int i;
+
+ switch (c->cur_dir) {
+ case MF_CHAR_DIR_U_: dx = 0; dy = -1; break;
+ case MF_CHAR_DIR_D_: dx = 0; dy = 1; break;
+ case MF_CHAR_DIR_L_: dx = -1; dy = 0; break;
+ case MF_CHAR_DIR_R_: dx = 1; dy = 0; break;
+ default: dx = 0; dy = 0; break;
+ }
+
+ for (i = 0; i < e->num_allies; ++i) {
+ if (e->allies[i] == c) {
+ /* Found self */
+ continue;
+ }
+ if (e->allies[i]->cur_x == c->cur_x + dx &&
+ e->allies[i]->cur_y == c->cur_y + dy) {
+ /* Another enemy currently in this direction */
+ return _mf_enemy_step(c);
+ }
+ if (e->allies[i]->new_x == c->cur_x + dx &&
+ e->allies[i]->new_y == c->cur_y + dy) {
+ /* Another enemy moving in this direction */
+ return _mf_enemy_step(c);
+ }
+ }
+
+ /* Go straight */
+ c->new_dir = c->cur_dir;
+
return 0;
}
@@ -211,41 +244,9 @@ mf_enemy_random_jump(struct mf_char *c, int maze_size)
int
mf_enemy_postupdate(struct mf_char *c)
{
- struct mf_enemy *e = (struct mf_enemy *) c;
- int dx;
- int dy;
- int i;
-
- if (c->turning > 0 || c->new_dir != MF_CHAR_DIR_N_) {
+ if (c->travel == 0 && c->turning == 0) {
+ return _mf_enemy_turn(c);
+ } else {
return 0;
}
-
- switch (c->cur_dir) {
- case MF_CHAR_DIR_U_: dx = 0; dy = -1; break;
- case MF_CHAR_DIR_D_: dx = 0; dy = 1; break;
- case MF_CHAR_DIR_L_: dx = -1; dy = 0; break;
- case MF_CHAR_DIR_R_: dx = 1; dy = 0; break;
- default: dx = 0; dy = 0; break;
- }
-
- for (i = 0; i < e->num_allies; ++i) {
- if (e->allies[i] == c) {
- /* Found self */
- continue;
- }
- if (e->allies[i]->cur_x == c->cur_x + dx &&
- e->allies[i]->cur_y == c->cur_y + dy) {
- /* Another enemy currently in this direction */
- return _mf_enemy_step(c);
- }
- if (e->allies[i]->new_x == c->cur_x + dx &&
- e->allies[i]->new_y == c->cur_y + dy) {
- /* Another enemy moving in this direction */
- return _mf_enemy_step(c);
- }
- }
-
- /* Go straight */
- c->new_dir = c->cur_dir;
- return 0;
}