summaryrefslogtreecommitdiffstats
path: root/src/char
diff options
context:
space:
mode:
Diffstat (limited to 'src/char')
-rw-r--r--src/char/enemy.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/char/enemy.c b/src/char/enemy.c
index b8836fb..0644ed3 100644
--- a/src/char/enemy.c
+++ b/src/char/enemy.c
@@ -39,6 +39,7 @@ _mf_enemy_update(struct mf_char *c __attribute__((__unused__)))
static int
_mf_enemy_step(struct mf_char *c)
{
+ struct mf_enemy *e = (struct mf_enemy *) c;
enum _mf_char_dir dirs[4] = {MF_CHAR_DIR_U_, MF_CHAR_DIR_D_,
MF_CHAR_DIR_L_, MF_CHAR_DIR_R_};
int i;
@@ -84,9 +85,27 @@ _mf_enemy_step(struct mf_char *c)
/* Wall ahead; don't go this direction. */
continue;
}
+ for (j = 0; j < e->num_allies; ++j) {
+ if (e->allies[j] == c) {
+ /* Found self */
+ continue;
+ }
+ if (e->allies[j]->cur_x == c->cur_x + dx &&
+ e->allies[j]->cur_y == c->cur_y + dy) {
+ /* Another enemy currently in this direction */
+ goto next_dir;
+ }
+ if (e->allies[j]->new_x == c->cur_x + dx &&
+ e->allies[j]->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;