diff options
author | P. J. McDermott <pj@pehjota.net> | 2021-08-09 01:15:32 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2021-08-09 01:15:32 (EDT) |
commit | f94d038f789c1270c727b04952d14eda5c47d585 (patch) | |
tree | b41d2e9ee01f8cb78735ee11f2af1eace5cb84e9 /src | |
parent | 05f7acb92dcf9812678857b25e9899a4adf84439 (diff) | |
download | mazefight-f94d038f789c1270c727b04952d14eda5c47d585.zip mazefight-f94d038f789c1270c727b04952d14eda5c47d585.tar.gz mazefight-f94d038f789c1270c727b04952d14eda5c47d585.tar.bz2 |
char: Add turn method
Diffstat (limited to 'src')
-rw-r--r-- | src/char/char.c | 4 | ||||
-rw-r--r-- | src/char/char.h | 2 | ||||
-rw-r--r-- | src/char/enemy.c | 9 | ||||
-rw-r--r-- | src/char/player.c | 6 |
4 files changed, 21 insertions, 0 deletions
diff --git a/src/char/char.c b/src/char/char.c index 05ca03a..b19e750 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -114,6 +114,10 @@ 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 { + if (c->turn(c) < 0) { + return -1; + } } } diff --git a/src/char/char.h b/src/char/char.h index 516974d..f5054d5 100644 --- a/src/char/char.h +++ b/src/char/char.h @@ -53,6 +53,7 @@ struct mf_char { SDL_Color eyes_color; int (*update)(struct mf_char *); int (*step)(struct mf_char *); + int (*turn)(struct mf_char *); int (*render)(struct mf_char *, SDL_Renderer *); void (*destroy)(struct mf_char *); }; @@ -68,6 +69,7 @@ mf_char_new(size_t size); }; \ c->update = &_mf_##name##_update; \ c->step = &_mf_##name##_step; \ + c->turn = &_mf_##name##_turn; \ 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 e480d10..7d913c4 100644 --- a/src/char/enemy.c +++ b/src/char/enemy.c @@ -88,6 +88,15 @@ _mf_enemy_step(struct mf_char *c) } static int +_mf_enemy_turn(struct mf_char *c) +{ + /* Go straight */ + c->new_dir = c->cur_dir; + + return 0; +} + +static int _mf_enemy_render(struct mf_char *c __attribute__((__unused__)), SDL_Renderer *renderer __attribute__((__unused__))) { diff --git a/src/char/player.c b/src/char/player.c index 7d20aad..eff0dbd 100644 --- a/src/char/player.c +++ b/src/char/player.c @@ -61,6 +61,12 @@ _mf_player_step(struct mf_char *c __attribute__((__unused__))) } static int +_mf_player_turn(struct mf_char *c __attribute__((__unused__))) +{ + return 0; +} + +static int _mf_player_render(struct mf_char *c __attribute__((__unused__)), SDL_Renderer *renderer __attribute__((__unused__))) { |