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