(define-module (game render other)
  #:use-module (game model other)
  #:use-module (game util assets)
  #:use-module (chickadee)
  #:use-module (chickadee math vector)
  #:use-module (chickadee graphics sprite)
  #:use-module (chickadee graphics texture)
  #:export (render-other
            render-other-load))



;; start index of the walk animation
(define other-walking-offset 3926)
(define other-falling-offset 3930)
(define other-climbing-offset 3929)

(define (other-sprite-walking other)
  (let* ((x (other-x other))
         (animation-frame (remainder x 3))
         (other-index (+ other-walking-offset animation-frame)))
    (texture-atlas-ref tile-atlas other-index)))

(define (other-sprite-stationary _other)
  (texture-atlas-ref tile-atlas other-walking-offset))

(define (other-sprite-falling other)
  (texture-atlas-ref tile-atlas other-climbing-offset))

(define (other-sprite-climbing other)
  (texture-atlas-ref tile-atlas other-climbing-offset))

(define (render-other other)
  (case (other-state other)
    ((stationary) (draw-sprite
                   (other-sprite-stationary other)
                   (vec2+ (other-position other) (vec2 -8.0 1.0))))
    ((fall) (draw-sprite
             (other-sprite-falling other)
             (vec2+ (other-position other) (vec2 -8.0 1.0))))
    ((climb) (draw-sprite
              (other-sprite-climbing other)
              (vec2+ (other-position other) (vec2 -8.0 1.0))))
    ((go-left) (draw-sprite
                (other-sprite-walking other)
                (vec2+ (other-position other) (vec2 8.0 1.0))
                #:scale (vec2 -1.0 1.0)
                ))
    ((go-right) (draw-sprite
                 (other-sprite-walking other)
                 (vec2+ (other-position other) (vec2 -8.0 1.0))))
    )
  )
