diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/char/enemy.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/char/enemy.c b/src/char/enemy.c index ff00915..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,10 +206,24 @@ 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; - while (c->cur_x < maze_size * MF_ENEMY_MIN_DIST && - c->cur_y < maze_size * MF_ENEMY_MIN_DIST) { - 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); |