summaryrefslogtreecommitdiff
path: root/bonnie-bee/player.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2021-10-23 17:09:34 -0400
committerDavid Thompson <dthompson@vistahigherlearning.com>2021-10-23 17:09:34 -0400
commit3fc18437f905f18aa4bf3b688930dbc68f8721b3 (patch)
treee14a25532309c88e2a33d5a7641f381a69733966 /bonnie-bee/player.scm
parentfb31282c18f33acb6de24e604059df6d05477491 (diff)
Lots of tweaks and also sprite animations!
Diffstat (limited to 'bonnie-bee/player.scm')
-rw-r--r--bonnie-bee/player.scm39
1 files changed, 33 insertions, 6 deletions
diff --git a/bonnie-bee/player.scm b/bonnie-bee/player.scm
index 0d7f1e0..f990657 100644
--- a/bonnie-bee/player.scm
+++ b/bonnie-bee/player.scm
@@ -32,8 +32,8 @@
(define %max-pollen 50)
(define-class <player> (<actor>)
- (move-left? #:accessor move-left? #:init-value #f)
- (move-right? #:accessor move-right? #:init-value #f)
+ (move-left? #:accessor move-left? #:init-value #f #:watch? #t)
+ (move-right? #:accessor move-right? #:init-value #f #:watch? #t)
(move-down? #:accessor move-down? #:init-value #f)
(move-up? #:accessor move-up? #:init-value #f)
(shoot? #:accessor shoot? #:init-value #f #:watch? #t)
@@ -48,16 +48,43 @@
(define-method (on-boot (player <player>))
(attach-to player
- (make <atlas-sprite>
+ (make <animated-sprite>
+ #:name 'sprite
#:atlas bee-atlas
- #:index 12
- #:origin (vec2 16.0 16.0))))
+ #:origin (vec2 16.0 16.0)
+ #:animations `((default . ,(make <animation>
+ #:frames #(0 1)
+ #:frame-duration 0.05))
+ (move-left . ,(make <animation>
+ #:frames #(2 3)
+ #:frame-duration 0.05))
+ (move-right . ,(make <animation>
+ #:frames #(4 5)
+ #:frame-duration 0.05))
+ (idle . ,(make <animation>
+ #:frames #(0 1)
+ #:frame-duration 0.75))))))
+
+(define-method (update-animation (player <player>))
+ (change-animation (& player sprite)
+ (cond
+ ((and (move-left? player)
+ (not (move-right? player)))
+ 'move-left)
+ ((and (not (move-left? player))
+ (move-right? player))
+ 'move-right)
+ (else
+ 'default))))
(define-method (on-change (player <player>) slot-name old new)
(case slot-name
((shoot?)
(when (and new (not (and old new)))
- (set! (last-shot player) 0)))))
+ (set! (last-shot player) 0)))
+ ((move-left? move-right?)
+ (unless (eq? old new)
+ (update-animation player)))))
(define-method (after-move (player <player>))
(let ((p (position player)))