From bb981c561a41f6a8d8ca9e65b381eeab721a89e8 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sun, 29 Oct 2023 12:46:19 -0400 Subject: More varied flyer behavior; map tweaks. --- game.scm | 192 +++++++++++++++++++++++++++++++++++++++--------------- images/flyer0.ase | Bin 1340 -> 1334 bytes images/flyer0.png | Bin 496 -> 442 bytes level.tmx | 125 +++++++++++++++++++++-------------- todo.org | 16 ++--- 5 files changed, 225 insertions(+), 108 deletions(-) diff --git a/game.scm b/game.scm index 6820fc8..6d5b884 100644 --- a/game.scm +++ b/game.scm @@ -588,37 +588,38 @@ (define (bullet-pool-update! pool collide) (match pool (#('bullet-pool length capacity image bullets) - (let loop ((i 0) (k length)) - (when (< i k) - (let* ((offset (bullet-pool-offset i)) - (type (s32-ref bullets offset)) - (x (f64-ref bullets (+ offset 12))) - (y (f64-ref bullets (+ offset 20))) - (w (f64-ref bullets (+ offset 28))) - (h (f64-ref bullets (+ offset 36))) - (dx (f64-ref bullets (+ offset 44))) - (dy (f64-ref bullets (+ offset 52))) - (x* (+ x dx)) - (y* (+ y dy))) - (cond - ((out-of-bounds? x* y* w h) - (bullet-pool-remove! pool i) - (loop i (- k 1))) - ((collide type x* y* w h) - (let ((d 1.0) - (l 3)) - (sound-effect-play sound:bullet-hit 0.02) - (particle-pool-add! particles 'hit-wall l x* y* d d) - (particle-pool-add! particles 'hit-wall l x* y* (- d) d) - (particle-pool-add! particles 'hit-wall l x* y* (- d) (- d)) - (particle-pool-add! particles 'hit-wall l x* y* d (- d)) - #t) - (bullet-pool-remove! pool i) - (loop i (- k 1))) - (else - (f64-set! bullets (+ offset 12) x*) - (f64-set! bullets (+ offset 20) y*) - (loop (+ i 1) k))))))))) + (let ((dscroll (- *scroll* *last-scroll*))) + (let loop ((i 0) (k length)) + (when (< i k) + (let* ((offset (bullet-pool-offset i)) + (type (s32-ref bullets offset)) + (x (f64-ref bullets (+ offset 12))) + (y (f64-ref bullets (+ offset 20))) + (w (f64-ref bullets (+ offset 28))) + (h (f64-ref bullets (+ offset 36))) + (dx (f64-ref bullets (+ offset 44))) + (dy (f64-ref bullets (+ offset 52))) + (x* (+ x dx)) + (y* (+ y dy dscroll))) + (cond + ((out-of-bounds? x* y* w h) + (bullet-pool-remove! pool i) + (loop i (- k 1))) + ((collide type x* y* w h) + (let ((d 1.0) + (l 3)) + (sound-effect-play sound:bullet-hit 0.02) + (particle-pool-add! particles 'hit-wall l x* y* d d) + (particle-pool-add! particles 'hit-wall l x* y* (- d) d) + (particle-pool-add! particles 'hit-wall l x* y* (- d) (- d)) + (particle-pool-add! particles 'hit-wall l x* y* d (- d)) + #t) + (bullet-pool-remove! pool i) + (loop i (- k 1))) + (else + (f64-set! bullets (+ offset 12) x*) + (f64-set! bullets (+ offset 20) y*) + (loop (+ i 1) k)))))))))) (define (draw-bullets pool) (match pool (#('bullet-pool length capacity image bullets) @@ -728,11 +729,16 @@ (match type ('turret (spawn-turret x y)) ('popcorn (spawn-popcorn x y)) + ('popcorn-down (spawn-popcorn-down x y)) ('popcorn-swarm (spawn-popcorn-swarm x y)) ('popcorn-sweep-left (spawn-popcorn-sweep-left x y)) ('popcorn-sweep-right (spawn-popcorn-sweep-right x y)) ('flyer0 (spawn-flyer0 x y)) ('flyer1 (spawn-flyer1 x y)) + ('flyer1-tunnel (spawn-tunnel-flyer1 x y)) + ('flyer1-down (spawn-flyer1-down x y)) + ('flyer1-down-left (spawn-flyer1-down-left x y)) + ('flyer1-down-right (spawn-flyer1-down-right x y)) ('boss (spawn-boss x y)) ('scroll-speed (let ((speed (assq-ref properties 'speed)) @@ -791,6 +797,10 @@ (vec2-x (enemy-position enemy))) (define (enemy-y enemy) (vec2-y (enemy-position enemy))) + (define (set-enemy-x! enemy x) + (set-vec2-x! (enemy-position enemy) x)) + (define (set-enemy-y! enemy y) + (set-vec2-y! (enemy-position enemy) y)) (define (enemy-width enemy) (vec2-x (enemy-size enemy))) (define (enemy-height enemy) @@ -943,7 +953,7 @@ (define (spawn-popcorn* x y script) (spawn-enemy - (make-enemy 'popcorn 1 (vec2 x y) (vec2 12.0 12.0) + (make-enemy 'popcorn 2 (vec2 x y) (vec2 12.0 12.0) (vec2 0.0 0.0) script 100 #(0.0 16.0 32.0 48.0) image:popcorn (vec2 16.0 16.0)))) @@ -988,7 +998,22 @@ (spawn-turret* x y script)) (define (spawn-popcorn x y) - (spawn-popcorn* x y #f)) + (define (script popcorn) + (forever + (tween (lambda (dy) + (set-enemy-dy! popcorn dy)) + 30 -0.2 0.2 + smoothstep lerp) + (tween (lambda (dy) + (set-enemy-dy! popcorn dy)) + 30 0.2 -0.2 + smoothstep lerp))) + (spawn-popcorn* x y script)) + + (define (spawn-popcorn-down x y) + (define (script popcorn) + (set-enemy-dy! popcorn 1.1)) + (spawn-popcorn* x y script)) (define (spawn-popcorn-swarm x y) (define (script popcorn) @@ -1035,10 +1060,10 @@ (define (script flyer) (run-script (lambda () + (wait 60) (let ((speed 1.0)) - (forever - (do-circle - (lambda (theta) + (let loop ((i 0.0)) + (let ((theta (+ (* (sin i) (/ pi 3.0)) (/ pi 3.0)))) (bullet-pool-add! enemy-bullets 0 (enemy-x flyer) (enemy-y flyer) @@ -1046,17 +1071,84 @@ (* (cos theta) speed) (* (sin theta) speed)) (wait 5)) - 16))))) - (forever - (set-enemy-dx! flyer 0.5) - (wait 60) - (set-enemy-dx! flyer -0.5) - (wait 60))) + (loop (+ i 0.5)))))) + (let ((speed 0.5)) + (forever + (tween (lambda (dx) + (set-enemy-dx! flyer dx)) + 60 -0.5 0.5 + smoothstep lerp) + (tween (lambda (dx) + (set-enemy-dx! flyer dx)) + 60 0.5 -0.5 + smoothstep lerp)))) (spawn-flyer0* x y script)) (define (spawn-flyer1 x y) (spawn-flyer1* x y #f)) + (define (spawn-tunnel-flyer1 x y) + (define (script flyer) + (set-enemy-dy! flyer 1.0) + (wait 80) + (set-enemy-dx! flyer -1.0) + (set-enemy-dy! flyer 0.0) + (wait 140) + (set-enemy-dx! flyer 0.0) + (set-enemy-dy! flyer 1.0)) + (spawn-flyer1* x y script)) + + (define (spawn-flyer1-down x y) + (define (script flyer) + (define (shoot* theta) + (let ((speed 3.5)) + (bullet-pool-add! enemy-bullets 0 + (enemy-x flyer) + (enemy-y flyer) + 2.0 2.0 + (* (cos theta) speed) + (* (sin theta) speed)))) + (define (shoot) + (shoot* pi/2) + (shoot* (+ pi/2 0.1)) + (shoot* (- pi/2 0.1))) + (set-enemy-dy! flyer 1.0) + (wait 30) + (forever + (shoot) + (wait 5) + (shoot) + (wait 5) + (shoot) + (wait 45))) + (spawn-flyer1* x y script)) + + (define (spawn-flyer1-down-left x y) + (define (script flyer) + (set-enemy-dy! flyer 1.0) + (wait 60) + (set-enemy-dx! flyer -1.0) + (set-enemy-dy! flyer 0.0) + (wait 60) + (tween (lambda (dx) + (set-enemy-dx! flyer dx)) + 30 -1.0 0.0 + smoothstep lerp)) + (spawn-flyer1* x y script)) + + (define (spawn-flyer1-down-right x y) + (define (script flyer) + (set-enemy-dy! flyer 1.0) + (wait 60) + (set-enemy-dx! flyer 1.0) + (set-enemy-dy! flyer 0.0) + (wait 60) + (tween (lambda (dx) + (set-enemy-dx! flyer dx)) + 30 1.0 0.0 + smoothstep lerp)) + (spawn-flyer1* x y script)) + (define (spawn-chaser x y) (define (script flyer) (set-enemy-dy! flyer -3.0) @@ -1506,11 +1598,11 @@ (set! *game-state* 'play) (scheduler-reset! *scheduler*) (set! *scroll* 0.0) - ;; (set! *scroll* (* 335.0 tile-height)) + ;; (set! *scroll* (* 60.0 tile-height)) (set! *last-scroll* 0.0) (set! *last-row-scanned* (level-height level)) ;; (set! *last-row-scanned* (- (level-height level) - ;; 335)) + ;; 60)) (bullet-pool-reset! player-bullets) (bullet-pool-reset! enemy-bullets) (enemy-pool-reset! enemies) @@ -1542,7 +1634,8 @@ ((string-=? code "KeyZ") (set-firing! #t) (prevent-default! event)) - ((string-=? code "ShiftLeft") + ((string-=? code "KeyX";; "ShiftLeft" + ) (set-focusing! #t) (prevent-default! event))))) @@ -1564,7 +1657,8 @@ ((string-=? code "KeyZ") (set-firing! #f) (prevent-default! event)) - ((string-=? code "ShiftLeft") + ((string-=? code "KeyX";; "ShiftLeft" + ) (set-focusing! #f) (prevent-default! event)) (else @@ -1661,11 +1755,7 @@ (do-game-over))) ('game-over (set! *scroll* *last-scroll*) - (scheduler-tick! *countdown-scheduler*) - (bullet-pool-update! player-bullets player-bullet-collide) - (bullet-pool-update! enemy-bullets enemy-bullet-collide) - (particle-pool-update! particles) - (enemy-pool-update! enemies)) + (scheduler-tick! *countdown-scheduler*)) ('game-clear (scheduler-tick! *scheduler*) (bullet-pool-update! player-bullets player-bullet-collide) diff --git a/images/flyer0.ase b/images/flyer0.ase index 619b3b5..4cb6c92 100644 Binary files a/images/flyer0.ase and b/images/flyer0.ase differ diff --git a/images/flyer0.png b/images/flyer0.png index 1f8ce69..8a467c5 100644 Binary files a/images/flyer0.png and b/images/flyer0.png differ diff --git a/level.tmx b/level.tmx index be526de..288bf3f 100644 --- a/level.tmx +++ b/level.tmx @@ -1,5 +1,5 @@ - + @@ -317,15 +317,15 @@ 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,0,1, 1,1,2,0,0,0,0,0,0,0,0,0,0,0,1, -1,1,1,1,1,1,1,1,1,0,0,0,0,0,1, -1,8,1,1,1,1,1,8,1,0,0,0,0,0,9, -1,1,1,1,9,1,1,1,1,0,0,0,0,0,1, -1,1,1,1,1,1,1,1,1,0,0,0,0,0,1, +1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, +1,8,1,1,1,1,1,8,1,1,0,0,0,0,9, 1,5,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, +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,3,1, -1,0,0,0,0,0,0,0,0,0,0,0,3,1,1, +1,0,0,0,1,1,1,1,1,1,1,1,1,1,1, 9,0,0,0,1,1,1,1,1,1,1,1,1,8,1, 1,0,0,0,0,4,1,1,1,1,1,1,1,1,1, 1,0,0,0,0,0,0,4,1,1,8,1,1,1,1, @@ -821,15 +821,15 @@ 6,0,0,0,0,0,0,0,0,0,0,0,0,0,6, 6,0,0,0,0,0,0,0,0,0,0,0,0,0,6, 6,6,0,0,0,0,0,0,0,0,0,0,0,0,6, -6,6,6,6,6,6,6,6,6,0,0,0,0,0,6, -6,6,6,6,6,6,6,6,6,0,0,0,0,0,6, -6,6,6,6,6,6,6,6,6,0,0,0,0,0,6, -6,6,6,6,6,6,6,6,6,0,0,0,0,0,6, +6,6,6,6,6,6,6,6,6,6,0,0,0,0,6, +6,6,6,6,6,6,6,6,6,6,0,0,0,0,6, 6,0,0,0,0,0,0,0,0,0,0,0,0,0,6, 6,0,0,0,0,0,0,0,0,0,0,0,0,0,6, 6,0,0,0,0,0,0,0,0,0,0,0,0,0,6, 6,0,0,0,0,0,0,0,0,0,0,0,0,0,6, -6,0,0,0,0,0,0,0,0,0,0,0,0,6,6, +6,0,0,0,0,0,0,0,0,0,0,0,0,0,6, +6,0,0,0,0,0,0,0,0,0,0,0,0,0,6, +6,0,0,0,6,6,6,6,6,6,6,6,6,6,6, 6,0,0,0,6,6,6,6,6,6,6,6,6,6,6, 6,0,0,0,0,0,6,6,6,6,6,6,6,6,6, 6,0,0,0,0,0,0,0,6,6,6,6,6,6,6, @@ -1018,21 +1018,6 @@ - - - - - - - - - - - - - - - @@ -1049,24 +1034,10 @@ - - - - - - - - - - - - - - - - - + + + @@ -1183,7 +1154,6 @@ - @@ -1207,11 +1177,8 @@ - - - - - + + @@ -1271,5 +1238,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/todo.org b/todo.org index 841b91e..e135b11 100644 --- a/todo.org +++ b/todo.org @@ -2,21 +2,21 @@ * DONE tiled map compilation * DONE pause state -* TODO intro state +* DONE intro state * DONE win state * DONE focus fire * DONE per bullet hitbox -* TODO parallax tile object backgrounds -* TODO player animation +* DONE parallax backgrounds +* DONE player animation * DONE enemy animation * DONE nested scripts -* TODO turret enemy -* TODO popcorn enemy -* TODO flying enemy 1 -* TODO flying enemy 2 +* DONE turret enemy +* DONE popcorn enemy +* DONE flying enemy 1 +* DONE flying enemy 2 * TODO boss * DONE scoring -* TODO design map +* DONE design map ** phases - open space, just the player for the first screen of tiles - popcorn appear -- cgit v1.2.3