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:
joren
2026-03-23 11:56:22 +01:00
parent f251478dd6
commit 5e7456eba9

View File

@@ -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))