summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-19 15:39:05 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-19 15:58:06 (EDT)
commit634192b8cdef3e0a0dea0f315ec04ac4023b3ad9 (patch)
tree6dd8e03649f1bc6890131e79131a257e7ead00f9
parent483d5cf42b38828e152561817769bd4155612c99 (diff)
downloadmazefight-634192b8cdef3e0a0dea0f315ec04ac4023b3ad9.zip
mazefight-634192b8cdef3e0a0dea0f315ec04ac4023b3ad9.tar.gz
mazefight-634192b8cdef3e0a0dea0f315ec04ac4023b3ad9.tar.bz2
char/enemy: Resume movement after stopping
If backed into a dead end by an ally, wait for the ally to leave then resume movement.
-rw-r--r--src/char/enemy.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/char/enemy.c b/src/char/enemy.c
index 0644ed3..6b1440f 100644
--- a/src/char/enemy.c
+++ b/src/char/enemy.c
@@ -28,15 +28,10 @@ struct mf_enemy {
struct mf_char parent;
int num_allies;
struct mf_char **allies;
+ int waiting;
};
static int
-_mf_enemy_update(struct mf_char *c __attribute__((__unused__)))
-{
- return 0;
-}
-
-static int
_mf_enemy_step(struct mf_char *c)
{
struct mf_enemy *e = (struct mf_enemy *) c;
@@ -103,11 +98,14 @@ _mf_enemy_step(struct mf_char *c)
}
/* Move */
c->new_dir = dirs[i];
+ e->waiting = SDL_FALSE;
return 0;
next_dir:
continue;
}
+ c->new_dir = MF_CHAR_DIR_N_;
+ e->waiting = SDL_TRUE;
return 0;
}
@@ -120,6 +118,18 @@ _mf_enemy_turn(struct mf_char *c)
return 0;
}
+static int
+_mf_enemy_update(struct mf_char *c)
+{
+ struct mf_enemy *e = (struct mf_enemy *) c;
+
+ if (e->waiting == SDL_TRUE) {
+ return _mf_enemy_step(c);
+ } else {
+ return 0;
+ }
+}
+
static void
_mf_enemy_collide(struct mf_char *c)
{
@@ -189,6 +199,7 @@ mf_enemy_new(struct mf_maze *maze, int cell_width, int maze_size,
e->num_allies = num_allies;
e->allies = allies;
+ e->waiting = SDL_FALSE;
return c;
}