diff options
author | P. J. McDermott <pj@pehjota.net> | 2021-08-09 01:12:29 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2021-08-09 01:12:29 (EDT) |
commit | 05f7acb92dcf9812678857b25e9899a4adf84439 (patch) | |
tree | a154da7ca2537de174f356a0c48619b2eb872020 /src | |
parent | 016c9daf3e46d08204f24b6da7d7820c64414a34 (diff) | |
download | mazefight-05f7acb92dcf9812678857b25e9899a4adf84439.zip mazefight-05f7acb92dcf9812678857b25e9899a4adf84439.tar.gz mazefight-05f7acb92dcf9812678857b25e9899a4adf84439.tar.bz2 |
char/enemy: Fix anti-backtracking
Diffstat (limited to 'src')
-rw-r--r-- | src/char/enemy.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/char/enemy.c b/src/char/enemy.c index edfd5c3..e480d10 100644 --- a/src/char/enemy.c +++ b/src/char/enemy.c @@ -42,6 +42,7 @@ _mf_enemy_step(struct mf_char *c) int i; int j; int t; + enum _mf_char_dir back; int dx; int dy; @@ -52,8 +53,17 @@ _mf_enemy_step(struct mf_char *c) dirs[i] = dirs[j]; dirs[j] = t; } + + /* Don't go backwards unless necessary */ + switch (c->cur_dir) { + case MF_CHAR_DIR_U_: back = MF_CHAR_DIR_D_; break; + case MF_CHAR_DIR_D_: back = MF_CHAR_DIR_U_; break; + case MF_CHAR_DIR_L_: back = MF_CHAR_DIR_R_; break; + case MF_CHAR_DIR_R_: back = MF_CHAR_DIR_L_; break; + default: back = MF_CHAR_DIR_N_; break; + } for (i = 0; i < 3; ++i) { - if (dirs[i] == c->cur_dir) { + if (dirs[i] == back) { t = dirs[i]; dirs[i] = dirs[3]; dirs[3] = t; |