diff options
Diffstat (limited to 'src/char')
-rw-r--r-- | src/char/char.c | 9 | ||||
-rw-r--r-- | src/char/char.h | 4 | ||||
-rw-r--r-- | src/char/enemy.c | 14 | ||||
-rw-r--r-- | src/char/player.c | 8 |
4 files changed, 22 insertions, 13 deletions
diff --git a/src/char/char.c b/src/char/char.c index 97c3cc4..05ca03a 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -59,7 +59,6 @@ mf_char_get_vector(struct mf_char *c, int *x, int *y, int *travel, int mf_char_update(struct mf_char *c) { - int stepped = SDL_FALSE; int dx; int dy; @@ -70,7 +69,9 @@ mf_char_update(struct mf_char *c) /* Reached next cell */ c->cur_x = c->new_x; c->cur_y = c->new_y; - stepped = SDL_TRUE; + if (c->step(c) < 0) { + return -1; + } if (c->cur_dir == c->new_dir) { /* Want to continue straight */ c->travel -= c->cell_width; @@ -113,13 +114,11 @@ mf_char_update(struct mf_char *c) c->new_x = c->cur_x + dx; c->new_y = c->cur_y + dy; c->travel += c->speed; - } else { - stepped = SDL_TRUE; } } end: - return c->update(c, stepped); + return c->update(c); } int diff --git a/src/char/char.h b/src/char/char.h index ad0a74d..516974d 100644 --- a/src/char/char.h +++ b/src/char/char.h @@ -51,7 +51,8 @@ struct mf_char { SDL_Color head_color; SDL_Color smil_color; SDL_Color eyes_color; - int (*update)(struct mf_char *, int); + int (*update)(struct mf_char *); + int (*step)(struct mf_char *); int (*render)(struct mf_char *, SDL_Renderer *); void (*destroy)(struct mf_char *); }; @@ -66,6 +67,7 @@ mf_char_new(size_t size); return NULL; \ }; \ c->update = &_mf_##name##_update; \ + c->step = &_mf_##name##_step; \ c->render = &_mf_##name##_render; \ c->destroy = &_mf_##name##_destroy; \ t_c = (struct mf_##name *) c; \ diff --git a/src/char/enemy.c b/src/char/enemy.c index 3907cf6..edfd5c3 100644 --- a/src/char/enemy.c +++ b/src/char/enemy.c @@ -29,7 +29,13 @@ struct mf_enemy { }; static int -_mf_enemy_update(struct mf_char *c, int stepped) +_mf_enemy_update(struct mf_char *c __attribute__((__unused__))) +{ + return 0; +} + +static int +_mf_enemy_step(struct mf_char *c) { enum _mf_char_dir dirs[4] = {MF_CHAR_DIR_U_, MF_CHAR_DIR_D_, MF_CHAR_DIR_L_, MF_CHAR_DIR_R_}; @@ -39,10 +45,6 @@ _mf_enemy_update(struct mf_char *c, int stepped) int dx; int dy; - if (stepped == SDL_FALSE) { - return 0; - } - /* Shuffle directions */ for (i = 0; i < 4; ++i) { j = rand() / (RAND_MAX / (i+1)); @@ -125,7 +127,7 @@ mf_enemy_new(struct mf_maze *maze, int cell_width, int maze_size) } c->cur_dir = MF_CHAR_DIR_N_; - _mf_enemy_update(c, SDL_TRUE); + _mf_enemy_step(c); c->cur_dir = c->new_dir; return c; diff --git a/src/char/player.c b/src/char/player.c index 8f44aa2..7d20aad 100644 --- a/src/char/player.c +++ b/src/char/player.c @@ -28,7 +28,7 @@ struct mf_player { }; static int -_mf_player_update(struct mf_char *c, int stepped __attribute__((__unused__))) +_mf_player_update(struct mf_char *c) { int dx; int dy; @@ -55,6 +55,12 @@ _mf_player_update(struct mf_char *c, int stepped __attribute__((__unused__))) } static int +_mf_player_step(struct mf_char *c __attribute__((__unused__))) +{ + return 0; +} + +static int _mf_player_render(struct mf_char *c __attribute__((__unused__)), SDL_Renderer *renderer __attribute__((__unused__))) { |