summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2022-01-26 17:28:16 (EST)
committer P. J. McDermott <pj@pehjota.net>2022-01-27 00:47:34 (EST)
commit7a2bba097269a711ae6a65c5287968eb04795e9a (patch)
tree57cd7ca9ab298f120e9556b510cabc8ece0e691a
parentd3592210f1bfeb419a4478a7b118db7e940fcb7d (diff)
downloadmazefight-7a2bba097269a711ae6a65c5287968eb04795e9a.zip
mazefight-7a2bba097269a711ae6a65c5287968eb04795e9a.tar.gz
mazefight-7a2bba097269a711ae6a65c5287968eb04795e9a.tar.bz2
Revert "char/enemy: Factor out collision check into jump"
This reverts commit 01e2f6af97c858b810e834b53aa25c356b940a38.
-rw-r--r--src/char/enemy.c53
1 files changed, 26 insertions, 27 deletions
diff --git a/src/char/enemy.c b/src/char/enemy.c
index 1e03567..8bb2c4e 100644
--- a/src/char/enemy.c
+++ b/src/char/enemy.c
@@ -178,6 +178,8 @@ mf_enemy_new(struct mf_maze *maze, int cell_width, int maze_size,
{
struct mf_char *c;
struct mf_enemy *e;
+ int collide;
+ int i;
mf_char_init(c, e, enemy);
@@ -204,42 +206,39 @@ mf_enemy_new(struct mf_maze *maze, int cell_width, int maze_size,
c->eyes_color.r = MF_COLOR_EEYE_R, c->eyes_color.g = MF_COLOR_EEYE_G;
c->eyes_color.b = MF_COLOR_EEYE_B, c->eyes_color.a = MF_COLOR_EEYE_A;
- e->num_allies = num_allies;
- e->allies = allies;
- e->waiting = SDL_FALSE;
-
- mf_enemy_random_jump(c, maze_size);
+ do {
+ collide = SDL_FALSE;
+ if (c->cur_x < maze_size * MF_ENEMY_MIN_DIST &&
+ c->cur_y < maze_size * MF_ENEMY_MIN_DIST) {
+ collide = SDL_TRUE;
+ } else {
+ for (i = 0; i < num_allies; ++i) {
+ if (allies[i] != NULL &&
+ c->cur_x == allies[i]->cur_x &&
+ c->cur_y == allies[i]->cur_y) {
+ collide = SDL_TRUE;
+ }
+ }
+ }
+ if (collide == SDL_TRUE) {
+ mf_enemy_random_jump(c, maze_size);
+ }
+ } while (collide == SDL_TRUE);
c->cur_dir = MF_CHAR_DIR_N_;
_mf_enemy_step(c);
c->cur_dir = c->new_dir;
+ e->num_allies = num_allies;
+ e->allies = allies;
+ e->waiting = SDL_FALSE;
+
return c;
}
void
mf_enemy_random_jump(struct mf_char *c, int maze_size)
{
- struct mf_enemy *e = (struct mf_enemy *) c;
- int collide;
- int i;
-
- collide = SDL_FALSE;
- if (c->cur_x < maze_size * MF_ENEMY_MIN_DIST &&
- c->cur_y < maze_size * MF_ENEMY_MIN_DIST) {
- collide = SDL_TRUE;
- } else {
- for (i = 0; i < e->num_allies; ++i) {
- if (e->allies[i] != NULL &&
- c->cur_x == e->allies[i]->cur_x &&
- c->cur_y == e->allies[i]->cur_y) {
- collide = SDL_TRUE;
- }
- }
- }
- if (collide == SDL_TRUE) {
- c->cur_x = rand() / (RAND_MAX / maze_size);
- c->cur_y = rand() / (RAND_MAX / maze_size);
- mf_enemy_random_jump(c, maze_size);
- }
+ c->cur_x = rand() / (RAND_MAX / maze_size);
+ c->cur_y = rand() / (RAND_MAX / maze_size);
}