diff options
author | David Thompson <dthompson2@worcester.edu> | 2023-10-28 09:35:23 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2023-10-28 09:35:23 -0400 |
commit | ceeaae033fd119d8f7ab2bc1f8e61147cd229495 (patch) | |
tree | eb92287b61073b42946ffeea03e49f5a227b28ff | |
parent | 5a07bdf576377d8ad3b8a83eaad8e1fb738c6e6d (diff) |
Start updating assets to use Christine's sprites; add nested scripts.
-rw-r--r-- | game.scm | 125 | ||||
-rw-r--r-- | images/enemy-bullets.ase | bin | 421 -> 413 bytes | |||
-rw-r--r-- | images/flyer0.ase | bin | 692 -> 660 bytes | |||
-rw-r--r-- | images/flyer0.png | bin | 434 -> 315 bytes | |||
-rw-r--r-- | images/flyer1.ase | bin | 647 -> 759 bytes | |||
-rw-r--r-- | images/flyer1.png | bin | 314 -> 487 bytes | |||
-rw-r--r-- | images/map.ase | bin | 1096 -> 1238 bytes | |||
-rw-r--r-- | images/map.png | bin | 452 -> 659 bytes | |||
-rw-r--r-- | images/player.ase | bin | 908 -> 658 bytes | |||
-rw-r--r-- | images/player.png | bin | 285 -> 605 bytes | |||
-rw-r--r-- | images/popcorn.ase | bin | 536 -> 522 bytes | |||
-rw-r--r-- | images/popcorn.png | bin | 306 -> 355 bytes | |||
-rw-r--r-- | images/turret.ase | bin | 996 -> 470 bytes | |||
-rw-r--r-- | images/turret.png | bin | 547 -> 250 bytes | |||
-rw-r--r-- | level.tmx | 140 |
15 files changed, 224 insertions, 41 deletions
@@ -205,6 +205,11 @@ (define pi/2 (/ pi 2.0)) (define tau (* pi 2.0)) + (define (do-circle proc k) + (do ((i 0 (+ i 1))) + ((= i k)) + (proc (* tau (inexact (/ i k)))))) + (define (clamp x min max) (cond ((< x min) min) ((> x max) max) @@ -359,14 +364,16 @@ ((= i num-tasks)) (vector-set! tasks i #f))))) (define *scheduler* (make-scheduler 100)) + (define current-script (make-parameter #f)) (define %script-tag (make-prompt-tag "script")) (define-type script %make-script script? (state script-state set-script-state!) - (cont script-cont set-script-cont!)) + (cont script-cont set-script-cont!) + (children script-children set-script-children!)) (define (make-script thunk) - (%make-script 'pending thunk)) + (%make-script 'pending thunk '())) (define (script-pending? script) (eq? (script-state script) 'pending)) (define (script-running? script) @@ -374,15 +381,23 @@ (define (script-cancelled? script) (eq? (script-state script) 'cancelled)) (define (script-cancel! script) - (set-script-state! script 'cancelled)) + (set-script-state! script 'cancelled) + (for-each script-cancel! (script-children script))) (define (script-run! script) (define (run thunk) (unless (script-cancelled? script) - (call-with-prompt %script-tag thunk handler))) + (call-with-prompt %script-tag + (lambda () + (parameterize ((current-script script)) + (thunk))) + handler))) (define (handler k delay) (when delay (scheduler-add! *scheduler* (lambda () (run k)) delay))) (when (script-pending? script) + (let ((parent (current-script))) + (when parent + (set-script-children! parent (cons script (script-children parent))))) (run (lambda () (set-script-state! script 'running) @@ -398,6 +413,10 @@ script)) (define (wait delay) (abort-to-prompt %script-tag delay)) + (define-syntax-rule (forever body ...) + (let loop () + body ... + (loop))) ;; Particles: (define-type particle-pool @@ -487,11 +506,11 @@ (define (explode x y) (let ((speed 1.0)) (sound-effect-play sound:explosion) - (do ((i 0 (+ i 1))) - ((= i 16)) - (let ((theta (* tau (/ i 16.0)))) - (particle-pool-add! particles 'explosion 20 x y - (* (cos theta) speed) (* (sin theta) speed)))))) + (do-circle + (lambda (theta) + (particle-pool-add! particles 'explosion 20 x y + (* (cos theta) speed) (* (sin theta) speed))) + 16))) ;; Bullets: ;; Similar to particles... but different. @@ -728,6 +747,10 @@ (vec2-x (enemy-velocity enemy))) (define (enemy-dy enemy) (vec2-y (enemy-velocity enemy))) + (define (set-enemy-dx! enemy dx) + (set-vec2-x! (enemy-velocity enemy) dx)) + (define (set-enemy-dy! enemy dy) + (set-vec2-y! (enemy-velocity enemy) dy)) (define (enemy-damage! enemy damage) (match enemy (#('enemy type health _ _ _ _ _ _ _ _ _ _) @@ -781,11 +804,12 @@ (h (vec2-y image-size))) (draw-image context image tx 0.0 w h (- x (/ w 2.0)) (- y (/ h 2.0)) w h) - (set-fill-color! context "#ff00ff80") - (fill-rect context - (- x (/ hbw 2.0)) - (- y (/ hbh 2.0)) - hbw hbh)))))) + ;; (set-fill-color! context "#ff00ff80") + ;; (fill-rect context + ;; (- x (/ hbw 2.0)) + ;; (- y (/ hbh 2.0)) + ;; hbw hbh) + ))))) (define-type enemy-pool %make-enemy-pool @@ -836,7 +860,10 @@ (set! *player-score* (+ *player-score* (enemy-points enemy)))) (when (eq? (enemy-type enemy) 'boss) - (set! *game-state* 'game-win)) + (run-script + (lambda () + (wait 60) + (set! *game-state* 'game-win)))) (enemy-pool-remove! pool i) (loop i (- k 1))) (else @@ -862,6 +889,30 @@ (define (spawn-enemy enemy) (enemy-pool-add! enemies enemy)) + (define (spawn-turret* x y script) + (spawn-enemy + (make-enemy 'turret 10 (vec2 x y) (vec2 12.0 12.0) + #t (vec2 0.0 0.0) script 100 + #(0.0 0.0 0.0 0.0) image:turret (vec2 32.0 32.0)))) + + (define (spawn-popcorn* x y script) + (spawn-enemy + (make-enemy 'popcorn 1 (vec2 x y) (vec2 12.0 12.0) + #t (vec2 0.0 0.0) script 100 + #(0.0 0.0 0.0 0.0) image:popcorn (vec2 32.0 32.0)))) + + (define (spawn-flyer0* x y script) + (spawn-enemy + (make-enemy 'flyer0 20 (vec2 x y) (vec2 12.0 12.0) + #f (vec2 0.0 0.0) script 100 + #(0.0 0.0 0.0 0.0) image:flyer0 (vec2 32.0 32.0)))) + + (define (spawn-flyer1* x y script) + (spawn-enemy + (make-enemy 'flyer1 10 (vec2 x y) (vec2 16.0 16.0) + #f (vec2 0.0 0.0) script 100 + #(0.0 0.0 0.0 0.0) image:flyer1 (vec2 32.0 32.0)))) + (define (spawn-turret x y) (define (script enemy) (let ((speed 2.0)) @@ -878,32 +929,42 @@ (* (vec2-y v) speed))) (wait 30) (loop (+ theta 0.2))))) - (spawn-enemy - (make-enemy 'turret 10 (vec2 x y) (vec2 16.0 16.0) - #t (vec2 0.0 0.0) script 100 - #(0.0 0.0 0.0 0.0) image:turret (vec2 64.0 64.0)))) + (spawn-turret* x y script)) (define (spawn-popcorn x y) - (spawn-enemy - (make-enemy 'popcorn 1 (vec2 x y) (vec2 16.0 16.0) - #t (vec2 0.0 0.0) #f 100 - #(0.0 0.0 0.0 0.0) image:popcorn (vec2 32.0 32.0)))) + (spawn-popcorn* x y #f)) (define (spawn-flyer0 x y) - (spawn-enemy - (make-enemy 'flyer0 20 (vec2 x y) (vec2 16.0 16.0) - #t (vec2 0.0 0.0) #f 100 - #(0.0 0.0 0.0 0.0) image:flyer0 (vec2 32.0 32.0)))) + (define (script flyer) + (run-script + (lambda () + (let ((speed 1.0)) + (forever + (do-circle + (lambda (theta) + (bullet-pool-add! enemy-bullets 0 + (enemy-x flyer) + (enemy-y flyer) + 2.0 2.0 + (* (cos theta) speed) + (* (sin theta) speed)) + (wait 5)) + 16))))) + (forever + (pk 'change-velocity) + (set-enemy-dx! flyer 0.5) + (wait 60) + (pk 'change-velocity) + (set-enemy-dx! flyer -0.5) + (wait 60))) + (spawn-flyer0* x y script)) (define (spawn-flyer1 x y) - (spawn-enemy - (make-enemy 'flyer1 10 (vec2 x y) (vec2 16.0 16.0) - #t (vec2 0.0 0.0) #f 100 - #(0.0 0.0 0.0 0.0) image:flyer1 (vec2 32.0 32.0)))) + (spawn-flyer1* x y #f)) (define (spawn-boss x y) (spawn-enemy - (make-enemy 'boss 100 (vec2 x y) (vec2 100.0 40.0) + (make-enemy 'boss 300 (vec2 x y) (vec2 100.0 40.0) #t (vec2 0.0 0.0) #f 1000000 #(0.0 0.0 0.0 0.0) image:boss (vec2 120.0 80.0)))) diff --git a/images/enemy-bullets.ase b/images/enemy-bullets.ase Binary files differindex d020498..f7fc836 100644 --- a/images/enemy-bullets.ase +++ b/images/enemy-bullets.ase diff --git a/images/flyer0.ase b/images/flyer0.ase Binary files differindex f7e7ce8..17329cb 100644 --- a/images/flyer0.ase +++ b/images/flyer0.ase diff --git a/images/flyer0.png b/images/flyer0.png Binary files differindex 2566428..6505b1d 100644 --- a/images/flyer0.png +++ b/images/flyer0.png diff --git a/images/flyer1.ase b/images/flyer1.ase Binary files differindex d64c89a..42fbe42 100644 --- a/images/flyer1.ase +++ b/images/flyer1.ase diff --git a/images/flyer1.png b/images/flyer1.png Binary files differindex 4292f5b..5298bcd 100644 --- a/images/flyer1.png +++ b/images/flyer1.png diff --git a/images/map.ase b/images/map.ase Binary files differindex 8985475..9f7deb3 100644 --- a/images/map.ase +++ b/images/map.ase diff --git a/images/map.png b/images/map.png Binary files differindex 58f01d7..cdaa5ac 100644 --- a/images/map.png +++ b/images/map.png diff --git a/images/player.ase b/images/player.ase Binary files differindex 51878b1..0a688d7 100644 --- a/images/player.ase +++ b/images/player.ase diff --git a/images/player.png b/images/player.png Binary files differindex f4ac194..03f2251 100644 --- a/images/player.png +++ b/images/player.png diff --git a/images/popcorn.ase b/images/popcorn.ase Binary files differindex a9da08c..1168e17 100644 --- a/images/popcorn.ase +++ b/images/popcorn.ase diff --git a/images/popcorn.png b/images/popcorn.png Binary files differindex ad843e9..25e8f0f 100644 --- a/images/popcorn.png +++ b/images/popcorn.png diff --git a/images/turret.ase b/images/turret.ase Binary files differindex 0cfe325..80601de 100644 --- a/images/turret.ase +++ b/images/turret.ase diff --git a/images/turret.png b/images/turret.png Binary files differindex 1e068f8..8da1a03 100644 --- a/images/turret.png +++ b/images/turret.png @@ -1,8 +1,34 @@ <?xml version="1.0" encoding="UTF-8"?> -<map version="1.8" tiledversion="1.8.6" orientation="orthogonal" renderorder="right-down" width="15" height="40" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="14"> +<map version="1.8" tiledversion="1.8.6" orientation="orthogonal" renderorder="right-down" width="15" height="80" tilewidth="16" tileheight="16" infinite="0" nextlayerid="8" nextobjectid="68"> <tileset firstgid="1" source="tiles.tsx"/> - <layer id="1" name="foreground" width="15" height="40"> + <tileset firstgid="7" source="background.tsx"/> + <objectgroup id="7" name="background" visible="0" parallaxy="0.75"> + <object id="14" gid="7" x="0" y="960" width="240" height="320"/> + <object id="15" gid="7" x="0" y="640" width="240" height="320"/> + <object id="16" gid="7" x="0" y="320" width="240" height="320"/> + </objectgroup> + <layer id="1" name="foreground" width="15" height="80"> <data encoding="csv"> +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, @@ -42,11 +68,51 @@ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,2,0,0,0,0,0,0,0,0,0,0,0,3,1, -1,1,2,0,0,0,0,0,0,0,0,0,3,1,1 +1,1,2,0,0,0,0,0,0,0,0,0,3,1,1, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 </data> </layer> - <layer id="5" name="collision" width="15" height="40"> + <layer id="5" name="collision" width="15" height="80"> <data encoding="csv"> +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0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0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 </data> </layer> <objectgroup id="3" name="objects"> - <object id="10" type="enemy-a" x="16" y="336" width="16" height="16"/> - <object id="11" type="enemy-a" x="192" y="336" width="16" height="16"/> - <object id="12" type="enemy-a" x="112" y="176" width="16" height="16"/> - <object id="13" type="enemy-a" x="112" y="0" width="16" height="16"/> + <object id="10" type="turret" x="16" y="656" width="16" height="16"/> + <object id="11" type="turret" x="192" y="656" width="16" height="16"/> + <object id="17" type="flyer0" x="96" y="320" width="16" height="16"/> + <object id="19" type="popcorn" x="144" y="416" width="16" height="16"/> + <object id="20" type="popcorn" x="144" y="448" width="16" height="16"/> + <object id="21" type="popcorn" x="144" y="480" width="16" height="16"/> + <object id="22" type="popcorn" x="128" y="512" width="16" height="16"/> + <object id="23" type="popcorn" x="112" y="544" width="16" height="16"/> + <object id="24" type="popcorn" x="112" y="576" width="16" height="16"/> + <object id="25" type="popcorn" x="64" y="672" width="16" height="16"/> + <object id="26" type="popcorn" x="96" y="672" width="16" height="16"/> + <object id="27" type="popcorn" x="128" y="672" width="16" height="16"/> + <object id="28" type="popcorn" x="160" y="672" width="16" height="16"/> + <object id="29" type="popcorn" x="80" y="640" width="16" height="16"/> + <object id="30" type="popcorn" x="112" y="640" width="16" height="16"/> + <object id="31" type="popcorn" x="144" y="640" width="16" height="16"/> + <object id="32" type="flyer0" x="128" y="320" width="16" height="16"/> + <object id="33" type="flyer0" x="112" y="272" width="16" height="16"/> + <object id="34" type="flyer0" x="96" y="224" width="16" height="16"/> + <object id="35" type="flyer0" x="128" y="224" width="16" height="16"/> + <object id="36" type="boss" x="112" y="48" width="16" height="16"/> + <object id="39" type="flyer0" x="48" y="976" width="16" height="16"/> + <object id="40" type="flyer0" x="96" y="976" width="16" height="16"/> + <object id="41" type="flyer0" x="144" y="976" width="16" height="16"/> + <object id="42" type="flyer0" x="192" y="976" width="16" height="16"/> + <object id="53" type="popcorn" x="0" y="1040" width="16" height="16"/> + <object id="54" type="popcorn" x="32" y="1040" width="16" height="16"/> + <object id="55" type="popcorn" x="64" y="1040" width="16" height="16"/> + <object id="56" type="popcorn" x="96" y="1040" width="16" height="16"/> + <object id="57" type="popcorn" x="16" y="1008" width="16" height="16"/> + <object id="58" type="popcorn" x="48" y="1008" width="16" height="16"/> + <object id="59" type="popcorn" x="80" y="1008" width="16" height="16"/> + <object id="60" type="popcorn" x="128" y="1040" width="16" height="16"/> + <object id="61" type="popcorn" x="160" y="1040" width="16" height="16"/> + <object id="62" type="popcorn" x="192" y="1040" width="16" height="16"/> + <object id="63" type="popcorn" x="224" y="1040" width="16" height="16"/> + <object id="64" type="popcorn" x="144" y="1008" width="16" height="16"/> + <object id="65" type="popcorn" x="176" y="1008" width="16" height="16"/> + <object id="66" type="popcorn" x="208" y="1008" width="16" height="16"/> + <object id="67" type="popcorn" x="112" y="1008" width="16" height="16"/> </objectgroup> </map> |