summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-18 17:55:19 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-19 14:34:35 (EDT)
commit7a252a42c4ec1a0116f7eff5727afcda3c5aba22 (patch)
tree7a43893fc414f7e29eec682cad56cd160da499d9 /src
parentad6baa8005d083b5dbe8b4c3a68808b1819cd6ae (diff)
downloadmazefight-7a252a42c4ec1a0116f7eff5727afcda3c5aba22.zip
mazefight-7a252a42c4ec1a0116f7eff5727afcda3c5aba22.tar.gz
mazefight-7a252a42c4ec1a0116f7eff5727afcda3c5aba22.tar.bz2
char/enemy: Add collision avoidance
Diffstat (limited to 'src')
-rw-r--r--src/char/enemy.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/char/enemy.c b/src/char/enemy.c
index f8e91a3..e51e440 100644
--- a/src/char/enemy.c
+++ b/src/char/enemy.c
@@ -52,6 +52,7 @@ _mf_enemy_step(struct mf_char *c)
enum _mf_char_dir back;
int dx;
int dy;
+ struct mf_char *o;
/* Shuffle directions */
for (i = 0; i < 4; ++i) {
@@ -89,9 +90,21 @@ _mf_enemy_step(struct mf_char *c)
/* Wall ahead; don't go this direction. */
continue;
}
+ for (o = c; o != NULL; o = ((struct mf_enemy *) o)->next_enemy){
+ if (o->cur_x == c->cur_x+dx && o->cur_y == c->cur_y+dy){
+ /* Another enemy currently in this direction */
+ goto next_dir;
+ }
+ if (o->new_x == c->cur_x+dx && o->new_y == c->cur_y+dy){
+ /* Another enemy moving in this direction */
+ goto next_dir;
+ }
+ }
/* Move */
c->new_dir = dirs[i];
return 0;
+ next_dir:
+ continue;
}
return 0;