Fix ghost and Pac-Man movement interpolation teleport #1
@@ -262,20 +262,18 @@
|
||||
(+ a (* t (- b a))))
|
||||
|
||||
;; draw-pacman! :: pacman, number -> /
|
||||
;; Draws Pac-Man with offset backward interpolation. Uses
|
||||
;; lerp(prev, current, 0.5 + t/2) so the visual starts at the
|
||||
;; midpoint (max 0.5 tile lag) and arrives at current by t=1.
|
||||
;; No jumps on direction changes unlike forward extrapolation.
|
||||
;; Draws Pac-Man with smooth backward interpolation. Uses
|
||||
;; lerp(prev, current, t) so the visual smoothly transitions
|
||||
;; from the previous tile strictly to the current tile by t=1.
|
||||
(define (draw-pacman! pacman progress)
|
||||
(let* ((pos (pacman 'position))
|
||||
(row (pos 'row))
|
||||
(col (pos 'col))
|
||||
(prev-row (pacman 'prev-row))
|
||||
(prev-col (pacman 'prev-col))
|
||||
(t (min progress 1))
|
||||
(factor (+ 0.5 (* 0.5 t)))
|
||||
(render-row (lerp prev-row row factor))
|
||||
(render-col (lerp prev-col col factor))
|
||||
(t (max 0 (min progress 1)))
|
||||
(render-row (lerp prev-row row t))
|
||||
(render-col (lerp prev-col col t))
|
||||
(direction (pacman 'direction)))
|
||||
((pacman-sprite 'set-x!) (grid->pixel-x render-col))
|
||||
((pacman-sprite 'set-y!) (grid->pixel-y render-row))
|
||||
@@ -285,7 +283,7 @@
|
||||
((eq? direction 'down) ((pacman-sprite 'rotate!) rotation-down)))))
|
||||
|
||||
;; draw-ghosts! :: list -> /
|
||||
;; Updates all ghost sprite positions with offset backward interpolation.
|
||||
;; Updates all ghost sprite positions with smooth backward interpolation.
|
||||
(define (draw-ghosts! ghosts)
|
||||
(for-each
|
||||
(lambda (ghost ghost-draw)
|
||||
@@ -294,10 +292,9 @@
|
||||
(col (pos 'col))
|
||||
(prev-row (ghost 'prev-row))
|
||||
(prev-col (ghost 'prev-col))
|
||||
(t (min (/ (ghost 'movement-timer) ghost-speed-ms) 1))
|
||||
(factor (+ 0.5 (* 0.5 t)))
|
||||
(render-row (lerp prev-row row factor))
|
||||
(render-col (lerp prev-col col factor))
|
||||
(t (max 0 (min (/ (ghost 'movement-timer) ghost-speed-ms) 1)))
|
||||
(render-row (lerp prev-row row t))
|
||||
(render-col (lerp prev-col col t))
|
||||
(dir (ghost 'direction)))
|
||||
((ghost-draw 'update!) render-row render-col dir)))
|
||||
ghosts ghost-draw-states))
|
||||
|
||||
Reference in New Issue
Block a user