diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/player.c | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/src/player.c b/src/player.c index 1ec7795..fe4af3d 100644 --- a/src/player.c +++ b/src/player.c @@ -39,6 +39,7 @@ struct mf_player { int speed; enum _mf_player_dir cur_dir; enum _mf_player_dir new_dir; + enum _mf_player_dir old_dir; int turning; int cur_x; int cur_y; @@ -70,9 +71,9 @@ mf_player_new(struct mf_maze *maze, int cell_width) p->travel = 0; if (mf_maze_is_wall(maze, 0, 0, 1, 0)) { - p->cur_dir = MF_PLAYER_DIR_D_; + p->old_dir = p->cur_dir = MF_PLAYER_DIR_D_; } else { - p->cur_dir = MF_PLAYER_DIR_R_; + p->old_dir = p->cur_dir = MF_PLAYER_DIR_R_; } return p; @@ -137,6 +138,7 @@ mf_player_update(struct mf_player *p) } if (p->new_dir != MF_PLAYER_DIR_N_ && p->cur_dir != p->new_dir) { /* Want to turn */ + p->old_dir = p->cur_dir; p->cur_dir = p->new_dir; p->new_dir = MF_PLAYER_DIR_N_; p->turning = MF_PLAYER_TURN_TIME + 1; @@ -173,30 +175,46 @@ mf_player_update(struct mf_player *p) int mf_player_render(struct mf_player *p, SDL_Renderer *renderer) { - int e = 0; - int cx; - int cy; - int fx; - int r; - int x; - int y; - int i; - int oy; - int fr; - int hy; - int ox; + int e = 0; + int cx; + int cy; + double fx; + double ofx; + int r; + int x; + int y; + int i; + int oy; + int fr; + int hy; + int ox; cx = p->cur_x * p->cell_width + p->cell_width / 2; cy = p->cur_y * p->cell_width + p->cell_width / 2; switch (p->cur_dir) { - case MF_PLAYER_DIR_U_: cy -= p->travel; fx = 2; break; - case MF_PLAYER_DIR_D_: cy += p->travel; fx = 0; break; - case MF_PLAYER_DIR_L_: cx -= p->travel; fx = -1; break; - case MF_PLAYER_DIR_R_: cx += p->travel; fx = 1; break; + case MF_PLAYER_DIR_U_: cy -= p->travel; fx = 2.0; break; + case MF_PLAYER_DIR_D_: cy += p->travel; fx = 0.0; break; + case MF_PLAYER_DIR_L_: cx -= p->travel; fx = -1.0; break; + case MF_PLAYER_DIR_R_: cx += p->travel; fx = 1.0; break; default: fx = 0; break; } + switch (p->old_dir) { + case MF_PLAYER_DIR_U_: + if (p->cur_dir == MF_PLAYER_DIR_L_) { + ofx = -2.0; + } else { + ofx = 2.0; + } + break; + case MF_PLAYER_DIR_D_: ofx = 0.0; break; + case MF_PLAYER_DIR_L_: ofx = -1.0; break; + case MF_PLAYER_DIR_R_: ofx = 1.0; break; + default: ofx = 0.0; break; + } r = p->cell_width / 2 - MF_PLAYER_P; - fx *= (0.0 + MF_PLAYER_TURN_TIME-p->turning) / MF_PLAYER_TURN_TIME * r; + fx = ofx + (fx - ofx) * (MF_PLAYER_TURN_TIME - p->turning) / + MF_PLAYER_TURN_TIME; + fx *= r; /* * Head |