diff options
author | P. J. McDermott <pj@pehjota.net> | 2021-08-10 01:54:34 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2021-08-10 01:54:34 (EDT) |
commit | 85494ad6865c9087b0d0f5a547b17042e7122662 (patch) | |
tree | 1f97a902929fb8c2c3d43280fde4e07aa9fdeaf9 /src | |
parent | 221523f82b2e4659db34f1fb1d8c180b3c442be3 (diff) | |
download | mazefight-85494ad6865c9087b0d0f5a547b17042e7122662.zip mazefight-85494ad6865c9087b0d0f5a547b17042e7122662.tar.gz mazefight-85494ad6865c9087b0d0f5a547b17042e7122662.tar.bz2 |
char/enemy: Expose random positioning function
Diffstat (limited to 'src')
-rw-r--r-- | src/char.h | 9 | ||||
-rw-r--r-- | src/char/enemy.c | 10 |
2 files changed, 14 insertions, 5 deletions
@@ -35,9 +35,6 @@ void mf_char_get_vector(struct mf_char *c, int *x, int *y, int *travel, int *dx, int *dy); -void -mf_player_key_event(struct mf_char *c, SDL_Event *e); - int mf_char_update(struct mf_char *c); @@ -47,4 +44,10 @@ mf_char_render(struct mf_char *c, SDL_Renderer *renderer); void mf_char_destroy(struct mf_char **c_c); +void +mf_player_key_event(struct mf_char *c, SDL_Event *e); + +void +mf_enemy_random_jump(struct mf_char *c, int maze_size); + #endif /* MF_CHAR_H */ diff --git a/src/char/enemy.c b/src/char/enemy.c index ca6d8e1..82cc16b 100644 --- a/src/char/enemy.c +++ b/src/char/enemy.c @@ -142,8 +142,7 @@ mf_enemy_new(struct mf_maze *maze, int cell_width, int maze_size) while (c->cur_x < maze_size * MF_ENEMY_MIN_DIST && c->cur_y < maze_size * MF_ENEMY_MIN_DIST) { - 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_dir = MF_CHAR_DIR_N_; @@ -152,3 +151,10 @@ mf_enemy_new(struct mf_maze *maze, int cell_width, int maze_size) 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); +} |