summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-12-24 03:00:39 (EST)
committer P. J. McDermott <pj@pehjota.net>2021-12-24 04:44:26 (EST)
commit90105c230095e04c051f86a3f0991e06efaf025f (patch)
tree763e7d97f512382df1542c07bc57c7b0e333a2b0
parent74f7f4e252824a139df5430cef87b87d5b082b60 (diff)
downloadmazefight-90105c230095e04c051f86a3f0991e06efaf025f.zip
mazefight-90105c230095e04c051f86a3f0991e06efaf025f.tar.gz
mazefight-90105c230095e04c051f86a3f0991e06efaf025f.tar.bz2
char/enemy: Don't spawn on top of allies
-rw-r--r--src/char/enemy.c24
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);