diff --git a/pacman-project/adt/draw.rkt b/pacman-project/adt/draw.rkt index 16f444b..a578825 100644 --- a/pacman-project/adt/draw.rkt +++ b/pacman-project/adt/draw.rkt @@ -262,7 +262,9 @@ (+ a (* t (- b a)))) ;; draw-pacman! :: pacman, number -> / - ;; Draws Pac-Man with smooth interpolation between tiles. + ;; Draws Pac-Man with forward extrapolation from current position. + ;; Formula: current + (current - prev) * t — visual leads toward + ;; the next tile so it aligns with the logical hitbox. (define (draw-pacman! pacman progress) (let* ((pos (pacman 'position)) (row (pos 'row)) @@ -270,8 +272,8 @@ (prev-row (pacman 'prev-row)) (prev-col (pacman 'prev-col)) (t (min progress 1)) - (render-col (lerp prev-col col t)) - (render-row (lerp prev-row row t)) + (render-row (+ row (* t (- row prev-row)))) + (render-col (+ col (* t (- col prev-col)))) (direction (pacman 'direction))) ((pacman-sprite 'set-x!) (grid->pixel-x render-col)) ((pacman-sprite 'set-y!) (grid->pixel-y render-row)) @@ -281,7 +283,7 @@ ((eq? direction 'down) ((pacman-sprite 'rotate!) rotation-down))))) ;; draw-ghosts! :: list -> / - ;; Updates all ghost sprite positions with smooth interpolation. + ;; Updates all ghost sprite positions with forward extrapolation. (define (draw-ghosts! ghosts) (for-each (lambda (ghost ghost-draw) @@ -291,8 +293,8 @@ (prev-row (ghost 'prev-row)) (prev-col (ghost 'prev-col)) (t (min (/ (ghost 'movement-timer) ghost-speed-ms) 1)) - (render-row (lerp prev-row row t)) - (render-col (lerp prev-col col t)) + (render-row (+ row (* t (- row prev-row)))) + (render-col (+ col (* t (- col prev-col)))) (dir (ghost 'direction))) ((ghost-draw 'update!) render-row render-col dir))) ghosts ghost-draw-states))