Fix visual hitbox offset with forward extrapolation
Switch from backward interpolation (lerp prev→current) to forward extrapolation (current + (current-prev) * t). The visual now leads toward the next tile, aligning with the logical hitbox so coins disappear when Pac-Man visually reaches them. When blocked (sync-prev! sets prev=current), the offset is zero and the sprite stays at the current tile. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -262,7 +262,9 @@
|
|||||||
(+ a (* t (- b a))))
|
(+ a (* t (- b a))))
|
||||||
|
|
||||||
;; draw-pacman! :: pacman, number -> /
|
;; 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)
|
(define (draw-pacman! pacman progress)
|
||||||
(let* ((pos (pacman 'position))
|
(let* ((pos (pacman 'position))
|
||||||
(row (pos 'row))
|
(row (pos 'row))
|
||||||
@@ -270,8 +272,8 @@
|
|||||||
(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 (min progress 1))
|
||||||
(render-col (lerp prev-col col t))
|
(render-row (+ row (* t (- row prev-row))))
|
||||||
(render-row (lerp prev-row row t))
|
(render-col (+ col (* t (- col prev-col))))
|
||||||
(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))
|
||||||
@@ -281,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 smooth interpolation.
|
;; Updates all ghost sprite positions with forward extrapolation.
|
||||||
(define (draw-ghosts! ghosts)
|
(define (draw-ghosts! ghosts)
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (ghost ghost-draw)
|
(lambda (ghost ghost-draw)
|
||||||
@@ -291,8 +293,8 @@
|
|||||||
(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 (min (/ (ghost 'movement-timer) ghost-speed-ms) 1))
|
||||||
(render-row (lerp prev-row row t))
|
(render-row (+ row (* t (- row prev-row))))
|
||||||
(render-col (lerp prev-col col t))
|
(render-col (+ col (* t (- col prev-col))))
|
||||||
(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