summaryrefslogtreecommitdiff
path: root/bonnie-bee/flower.scm
blob: cafa4f81389c7c2ba1a9be93402ec3a395b74ede (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(define-module (bonnie-bee flower)
  #:use-module (bonnie-bee actor)
  #:use-module (bonnie-bee assets)
  #:use-module (bonnie-bee bullet)
  #:use-module (chickadee math)
  #:use-module (chickadee math vector)
  #:use-module (chickadee scripting)
  #:use-module (chickadee utils)
  #:use-module (oop goops)
  #:use-module (starling node)
  #:use-module (starling node-2d)
  #:export (<flower>))

(define-class <flower> (<actor> <damageable>))

(define-method (on-boot (flower <flower>))
  (attach-to flower
             (make <sprite>
               #:texture flower-image
               #:origin (vec2 32.0 32.0))))

(define-method (on-collide (flower <flower>) (bullet <bullet>))
  (if (eq? (type bullet) player-primary-bullet)
      (begin
        (damage flower 1)
        (kill-bullet bullet)
        #t)
      #f))

(define-method (on-death (flower <flower>) bullets)
  (let ((p (position flower)))
    (for-range ((i 16))
      (let ((theta (- (* (random:uniform) (/ pi -2.0)) (/ pi 4.0)))
            (speed (+ (* (random:uniform) 1.0) 1.0)))
        (add-bullet bullets pollen-pickup p
                    (vec2 (* (cos theta) speed)
                          (* (sin theta) speed)))))))