From 634192b8cdef3e0a0dea0f315ec04ac4023b3ad9 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Thu, 19 Aug 2021 15:39:05 -0400 Subject: char/enemy: Resume movement after stopping If backed into a dead end by an ally, wait for the ally to leave then resume movement. --- (limited to 'src/char') 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; } -- cgit v0.9.1