summaryrefslogtreecommitdiff
path: root/bonnie-bee/flower.scm
blob: 6646eccb7a89b424950181c8a1c4d376e9d581b6 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
(define-module (bonnie-bee flower)
  #:use-module (bonnie-bee actor)
  #:use-module (bonnie-bee assets)
  #:use-module (bonnie-bee bullet)
  #:use-module (chickadee audio)
  #:use-module (chickadee graphics particles)
  #:use-module (chickadee math)
  #:use-module (chickadee math rect)
  #:use-module (chickadee math vector)
  #:use-module (chickadee scripting)
  #:use-module (chickadee utils)
  #:use-module (oop goops)
  #:use-module (catbird asset)
  #:use-module (catbird node)
  #:use-module (catbird node-2d)
  #:export (<flower>
            pollen-enabled?
            enable-pollen!
            disable-pollen!))

(define-class <flower> (<grounded> <damageable> <actor>)
  (emit-pollen? #:allocation #:class #:init-value #f))

(define-class <pollinated-flower> (<grounded> <actor>))

(define (pollen-enabled?)
  (class-slot-ref <flower> 'emit-pollen?))

(define (enable-pollen!)
  (class-slot-set! <flower> 'emit-pollen? #t))

(define (disable-pollen!)
  (class-slot-set! <flower> 'emit-pollen? #f))

(define-method (on-boot (flower <flower>))
  (attach-to flower
             (make <animated-sprite>
               #:atlas flower-atlas
               #:origin (vec2 32.0 32.0)
               #:animations `((default . ,(make <animation>
                                           #:frames #(0 1 0 2)
                                           #:frame-duration .45))))))

(define-method (on-boot (flower <pollinated-flower>))
  (attach-to flower
             (make <atlas-sprite>
               #:atlas flower-atlas
               #:origin (vec2 32.0 32.0)
               #:index 3)))

(define-method (on-collide (flower <flower>) (bullet <bullet>))
  (cond
   ((player-primary-bullet? bullet)
    (damage flower 1)
    (kill-bullet bullet)
    #t)
   ((player-bomb-bullet? bullet)
    (damage flower 5)
    (kill-bullet bullet))
   ((and (not (pollen-enabled?)) (enemy-bullet? bullet))
    (damage flower 1000)
    (kill-bullet bullet))
   (else #f)))

(define-method (on-death (flower <flower>))
  (let ((p (position flower)))
    (if (pollen-enabled?)
        (begin
          (audio-play (artifact pollen-release-sound))
          (for-range ((i 16))
            (let ((theta (- (* (- (random:uniform) 0.5) (/ pi 3.0))
                            (/ pi 2.0)))
                  (speed (+ (* (random:uniform) 1.0) 1.0)))
              (add-bullet (& (parent flower) bullets)
                          pollen-pickup p
                          (vec2 (* (cos theta) speed)
                                (* (sin theta) speed)))))
          (spawn (parent flower)
                 (make <pollinated-flower>
                   #:rank 1
                   #:position (position flower)
                   #:hitbox (make-rect -1.0 -1.0 2.0 2.0))))
        (begin
          (audio-play (artifact explosion-sound))
          (add-particle-emitter (particles (& (parent flower) particles))
                                (make-particle-emitter (make-rect (vec2-x p) (vec2-y p) 1.0 1.0)
                                                       10 5))))))