summaryrefslogtreecommitdiff
path: root/bonnie-bee/boss.scm
blob: 7e4d375406bc35990708e2ed19e545d784f2119c (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
88
89
90
91
92
93
94
95
96
97
(define-module (bonnie-bee boss)
  #:use-module (bonnie-bee actor)
  #:use-module (bonnie-bee assets)
  #:use-module (bonnie-bee bullet)
  #:use-module (chickadee audio)
  #:use-module (chickadee game-loop)
  #: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 (starling asset)
  #:use-module (starling node)
  #:use-module (starling node-2d)
  #:export (<boss>))

(define-class <boss> (<grounded> <damageable> <actor>)
  (invincible? #:accessor invincible? #:init-value #t))

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

(define-method (on-enter (boss <boss>))
  (define (circle-shot n offset speed type)
    (let loop ((i 0))
      (when (< i n)
        (let ((theta (+ (* (/ tau n) i) offset)))
          (add-bullet (bullets (parent boss))
                      type
                      (position boss)
                      (vec2 (* (cos theta) speed)
                            (* (sin theta) speed)))
          (loop (+ i 1))))))
  (define (random-shot speed)
    (let ((theta (* (- pi) (random:uniform))))
      (add-bullet (bullets (parent boss))
                  medium-enemy-bullet
                  (position boss)
                  (vec2 (* (cos theta) speed)
                        (* (sin theta) speed)))))
  (next-method)
  (run-script boss
    (sleep 5.0)
    (set! (invincible? boss) #f)
    (let ((big-speed 2.0)
          (little-speed 1.0))
      (while (> (health boss) 2000)
        (let ((d (direction-to boss (player (parent boss)))))
          (add-bullet (bullets (parent boss))
                      large-enemy-bullet
                      (position boss)
                      (vec2* d big-speed))
          (let loop ((i 0))
            (when (< i 16)
              (audio-play (asset-ref enemy-shoot-sound))
              (random-shot little-speed)
              (sleep (* (current-timestep) 2.0))
              (loop (+ i 1)))))))
    (sleep 2.5)
    (let loop ((theta 0.0))
      (unless (<= (health boss) 1000)
        (audio-play (asset-ref enemy-shoot-sound))
        (repeat 2 (random-shot 0.5))
        (circle-shot 2 theta 1.5 large-enemy-bullet)
        (circle-shot 6 (- theta) 1.0 medium-enemy-bullet)
        (sleep (* (current-timestep) 10))
        (loop (+ theta (/ pi 17.1)))))
    (sleep 2.5)
    (let loop ((theta 0.0))
      (audio-play (asset-ref enemy-shoot-sound))
      (circle-shot 10 (* theta 2.0) 1.5 large-enemy-bullet)
      (circle-shot 4 (- theta) 1.0 medium-enemy-bullet)
      (sleep (* (current-timestep) 10))
      (loop (+ theta (/ pi 37.1))))))

(define-method (on-collide (boss <boss>) (bullet <bullet>))
  (cond
   ((player-primary-bullet? bullet)
    (unless (invincible? boss)
      (damage boss 1))
    (kill-bullet bullet)
    #t)
   ((player-bomb-bullet? bullet)
    (unless (invincible? boss)
      (damage boss 10))
    (kill-bullet bullet))
   (else #f)))

(define-method (on-death (boss <boss>))
  (audio-play (asset-ref explosion-sound))
  (add-particle-emitter (particles (particles (parent boss)))
                        (make-particle-emitter (world-hitbox boss) 20 30)))