From 995342fb74fdd1ba5aeaa172a428538e7dd0dcdc Mon Sep 17 00:00:00 2001 From: Gene Pasquet Date: Wed, 8 Apr 2026 01:05:50 +0100 Subject: Code cleanup --- animation.scm | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'animation.scm') diff --git a/animation.scm b/animation.scm index a152753..4caf1fe 100644 --- a/animation.scm +++ b/animation.scm @@ -32,24 +32,25 @@ ;; Pass the animation table for this entity's type. ;; Entities without #:anim-name are returned unchanged. + (define (advance-animation entity anim) + (let* ((tick (+ 1 (entity-ref entity #:anim-tick 0))) + (duration (animation-duration anim)) + (frames (animation-frames anim)) + (frame (entity-ref entity #:anim-frame 0))) + (if (>= tick duration) + (let ((new-frame (modulo (+ frame 1) (length frames)))) + (entity-set (entity-set (entity-set entity + #:anim-tick 0) + #:anim-frame new-frame) + #:tile-id (frame->tile-id frames new-frame))) + (entity-set (entity-set entity #:anim-tick tick) + #:tile-id (frame->tile-id frames frame))))) + (define (animate-entity entity animations) - (let ((anim-name (entity-ref entity #:anim-name #f))) - (if (not anim-name) - entity - (let* ((entry (assq anim-name animations)) - (anim (and entry (cdr entry)))) - (if (not anim) - entity - (let* ((tick (+ 1 (entity-ref entity #:anim-tick 0))) - (duration (animation-duration anim)) - (frames (animation-frames anim)) - (frame (entity-ref entity #:anim-frame 0))) - (if (>= tick duration) - (let ((new-frame (modulo (+ frame 1) (length frames)))) - (entity-set (entity-set (entity-set entity - #:anim-tick 0) - #:anim-frame new-frame) - #:tile-id (frame->tile-id frames new-frame))) - (entity-set (entity-set entity #:anim-tick tick) - #:tile-id (frame->tile-id frames frame))))))))) + (let* ((anim-name (entity-ref entity #:anim-name #f)) + (entry (and anim-name (assq anim-name animations))) + (anim (and entry (cdr entry)))) + (if anim + (advance-animation entity anim) + entity))) ) ;; End of animation module -- cgit v1.2.3