summaryrefslogtreecommitdiff
path: root/bonnie-bee/boss.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2021-10-21 08:28:40 -0400
committerDavid Thompson <dthompson@vistahigherlearning.com>2021-10-21 08:28:40 -0400
commit0ef4a323549ea72f4c5c3df17ac78ceda069ed03 (patch)
tree3831dd2459b626922e897d85499e359feb1f8782 /bonnie-bee/boss.scm
parentba887d36cd96e188771eda44ddfb7c31c9811fc0 (diff)
Add real boss fight.
Diffstat (limited to 'bonnie-bee/boss.scm')
-rw-r--r--bonnie-bee/boss.scm63
1 files changed, 60 insertions, 3 deletions
diff --git a/bonnie-bee/boss.scm b/bonnie-bee/boss.scm
index d19f2c2..7e4d375 100644
--- a/bonnie-bee/boss.scm
+++ b/bonnie-bee/boss.scm
@@ -3,6 +3,7 @@
#: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)
@@ -15,7 +16,8 @@
#:use-module (starling node-2d)
#:export (<boss>))
-(define-class <boss> (<grounded> <damageable> <actor>))
+(define-class <boss> (<grounded> <damageable> <actor>)
+ (invincible? #:accessor invincible? #:init-value #t))
(define-method (on-boot (boss <boss>))
(attach-to boss
@@ -23,14 +25,69 @@
#: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)
- (damage boss 1)
+ (unless (invincible? boss)
+ (damage boss 1))
(kill-bullet bullet)
#t)
((player-bomb-bullet? bullet)
- (damage boss 10)
+ (unless (invincible? boss)
+ (damage boss 10))
(kill-bullet bullet))
(else #f)))