From 5e7456eba99d973ccf34d70727303038f822ddb4 Mon Sep 17 00:00:00 2001 From: joren Date: Mon, 23 Mar 2026 11:56:22 +0100 Subject: [PATCH] Fix visual hitbox offset with forward extrapolation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- pacman-project/adt/draw.rkt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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))