summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/char/enemy.c53
1 files changed, 27 insertions, 26 deletions
diff --git a/src/char/enemy.c b/src/char/enemy.c
index 8bb2c4e..1e03567 100644
--- a/src/char/enemy.c
+++ b/src/char/enemy.c
@@ -178,8 +178,6 @@ 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);
@@ -206,39 +204,42 @@ 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;
- 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);
+ e->num_allies = num_allies;
+ e->allies = allies;
+ e->waiting = SDL_FALSE;
+
+ mf_enemy_random_jump(c, maze_size);
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)
{
- c->cur_x = rand() / (RAND_MAX / maze_size);
- c->cur_y = rand() / (RAND_MAX / 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);
+ }
}