From e5acb707aaceb92982b81f7170add924cc41653f Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Mon, 6 Nov 2023 10:53:08 +0100 Subject: Fix update-animated-sprite. --- scenes/death.scm | 8 ++++---- scenes/game.scm | 8 ++++---- utils.scm | 8 +++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/scenes/death.scm b/scenes/death.scm index 5351dba..67e24a7 100644 --- a/scenes/death.scm +++ b/scenes/death.scm @@ -152,13 +152,13 @@ quite short.")) (vec2 (+ (/ %width 2) 25) (- (/ %height 2) 20)) #:dead? #true)) - (update-animated-sprite *player* 0) + (update-animated-sprite *player*) (set! (walk-speed *player*) 0.3) (set! *reaper* (reaper #:start-position (vec2 (+ (/ %width 2) 110) (- (/ %height 2) 20)))) - (update-animated-sprite *reaper* 0) + (update-animated-sprite *reaper*) (set! (walk-speed *reaper*) 0.3) (with-agenda @@ -316,8 +316,8 @@ quite short.")) (define (update-scene dt) (update-agenda dt) - (update-animated-sprite *player* dt) - (update-animated-sprite *reaper* dt) + (update-animated-sprite *player*) + (update-animated-sprite *reaper*) ;; Move the world (unless pretend-walking? diff --git a/scenes/game.scm b/scenes/game.scm index 3fe2a45..442071e 100644 --- a/scenes/game.scm +++ b/scenes/game.scm @@ -94,7 +94,7 @@ map's positions layer." )) (set! *player* (lorenzo #:start-position (location "player"))) - (update-animated-sprite *player* 0) + (update-animated-sprite *player*) (grid-add grid 'player (+ (vec2-x (position *player*)) player-grid-x-offset) (+ (vec2-y (position *player*)) player-grid-y-offset) @@ -103,7 +103,7 @@ map's positions layer." (set! *reaper* (reaper #:start-position (location "reaper"))) - (update-animated-sprite *reaper* 0) + (update-animated-sprite *reaper*) ;; XXX: Chickadee parses the object layer incorrectly, so all ;; objects are flipped vertically. We use this to compute the @@ -248,8 +248,8 @@ map's positions layer." (define (update-scene dt) (update-agenda dt) - (update-animated-sprite *player* dt) - (update-animated-sprite *reaper* dt)) + (update-animated-sprite *player*) + (update-animated-sprite *reaper*)) (define scene diff --git a/utils.scm b/utils.scm index 5533cc0..df93b26 100644 --- a/utils.scm +++ b/utils.scm @@ -118,12 +118,14 @@ given MAX-WIDTH. Return a list of lines." (vec2+ offset (position sprite)) #:tint (tint sprite))) -(define (update-animated-sprite sprite dt) +(define (update-animated-sprite sprite) (let* ((anim (assq-ref (animations sprite) (current-animation sprite))) (frame-duration (frame-duration sprite)) (anim-duration (* frame-duration (vector-length anim))) - (time (modulo (- (agenda-time) (start-time sprite)) anim-duration)) - (frame (vector-ref anim (floor (/ time frame-duration)))) + (time (floor-remainder (- (agenda-time) (start-time sprite)) + anim-duration)) + (frame (vector-ref anim (inexact->exact + (floor (/ time frame-duration))))) (texture-region (texture-atlas-ref (asset-ref (atlas sprite)) frame))) (set! (texture sprite) texture-region))) -- cgit v1.2.3