summaryrefslogtreecommitdiff
path: root/bonnie-bee/actor.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2021-10-20 18:42:10 -0400
committerDavid Thompson <dthompson@vistahigherlearning.com>2021-10-20 18:42:10 -0400
commitae60497f7722e01ccceebe799b5820717e048eb3 (patch)
tree7977b53565d5f1e259d90903213f1add3fefabce /bonnie-bee/actor.scm
parentde833c9d524d2e47b3812612995290795d2e7b84 (diff)
Haven't committed in days, oops!
Diffstat (limited to 'bonnie-bee/actor.scm')
-rw-r--r--bonnie-bee/actor.scm89
1 files changed, 79 insertions, 10 deletions
diff --git a/bonnie-bee/actor.scm b/bonnie-bee/actor.scm
index a734d6a..1e21144 100644
--- a/bonnie-bee/actor.scm
+++ b/bonnie-bee/actor.scm
@@ -1,8 +1,12 @@
(define-module (bonnie-bee actor)
+ #:use-module (bonnie-bee assets)
+ #:use-module (bonnie-bee common)
+ #:use-module (chickadee audio)
#:use-module (chickadee data quadtree)
#:use-module (chickadee math rect)
#:use-module (chickadee math vector)
#:use-module (oop goops)
+ #:use-module (starling asset)
#:use-module (starling node)
#:use-module (starling node-2d)
#:export (<actor>
@@ -10,18 +14,45 @@
hitbox
world-hitbox
quadtree
+ change-velocity
+ direction-to
+ angle-to
+ after-move
on-collide
- <damageable>
dead?
+ out-of-bounds?
+ <damageable>
+ points
damage
- on-death))
+ on-death
+ <grounded>
+ player
+ bullets
+ scroll-speed))
(define-class <actor> (<node-2d>)
- (velocity #:getter velocity #:init-form (vec2 0.0 0.0))
+ (velocity #:getter velocity #:init-keyword #:velocity #:init-form (vec2 0.0 0.0))
(hitbox #:getter hitbox #:init-keyword #:hitbox)
(world-hitbox #:getter world-hitbox #:init-form (make-rect 0.0 0.0 0.0 0.0))
(quadtree #:accessor quadtree #:init-keyword #:quadtree))
+(define-method (change-velocity (actor <actor>) dx dy)
+ (set-vec2! (velocity actor) dx dy))
+
+(define-method (direction-to (actor <actor>) (other <actor>))
+ (let ((dir (vec2- (position other) (position actor))))
+ (vec2-normalize! dir)
+ dir))
+
+(define-method (angle-to (actor <actor>) (other <actor>))
+ (let ((p1 (position actor))
+ (p2 (position other)))
+ (atan (- (vec2-y p2) (vec2-y p1))
+ (- (vec2-x p2) (vec2-x p1)))))
+
+(define-method (scroll-speed (actor <actor>))
+ 0.0)
+
(define-method (add-to-quadtree (actor <actor>))
(quadtree-insert! (quadtree actor) (world-hitbox actor) actor))
@@ -38,7 +69,6 @@
(set-rect-height! wh (rect-height h))))
(define-method (on-collide a b)
- (pk 'unhandled-collision a b)
#f)
(define-method (on-enter (actor <actor>))
@@ -55,27 +85,66 @@
(rect-intersects? r (world-hitbox other))
(on-collide actor other))))))
+(define-method (after-move (actor <actor>))
+ #t)
+
(define-method (update (actor <actor>) dt)
(let ((p (position actor))
- (v (velocity actor)))
- (if (and (= (vec2-x v) 0.0) (= (vec2-y v) 0.0))
+ (v (velocity actor))
+ (scroll-speed (scroll-speed actor)))
+ (if (and (= (vec2-x v) 0.0)
+ (= (vec2-y v) 0.0)
+ (= scroll-speed 0.0))
(collision-check actor)
(begin
(remove-from-quadtree actor)
- (vec2-add! p v)
+ (set-vec2! p
+ (+ (vec2-x p) (vec2-x v))
+ (+ (vec2-y p) (vec2-y v) (- (* scroll-speed dt))))
+ (after-move actor)
(refresh-world-hitbox actor)
(collision-check actor)
(add-to-quadtree actor)
(dirty! actor)))))
+(define-method (dead? (actor <actor>))
+ #f)
+
+(define-method (dead? x)
+ #f)
+
+(define %bounds
+ (let ((padding 16.0))
+ (make-rect (- padding)
+ (- padding)
+ (+ %game-width (* padding 2.0))
+ (+ %game-height (* padding 2.0)))))
+
+(define-method (out-of-bounds? (actor <actor>))
+ (not (rect-intersects? (world-hitbox actor) %bounds)))
+
+(define-method (out-of-bounds? x)
+ #f)
+
(define-class <damageable> ()
- (health #:accessor health #:init-keyword #:health))
+ (health #:accessor health #:init-keyword #:health)
+ (points #:getter points #:init-keyword #:points))
(define-method (dead? (d <damageable>))
(= (health d) 0))
(define-method (damage (d <damageable>) x)
- (set! (health d) (max (- (health d) x) 0)))
+ (set! (health d) (max (- (health d) x) 0))
+ (unless (dead? d)
+ (audio-play (asset-ref enemy-hit-sound) #:volume 0.25)))
-(define-method (on-death (d <damageable>) bullets)
+(define-method (on-death (d <damageable>))
#t)
+
+(define-class <grounded> ())
+
+(define-method (scroll-speed (g <grounded>))
+ (scroll-speed (parent g)))
+
+(define-generic player)
+(define-generic bullets)