diff options
author | David Thompson <dthompson2@worcester.edu> | 2016-05-04 19:53:17 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2016-05-04 19:53:17 -0400 |
commit | f6cc44549de73e74739cc0bdad68492126cac1df (patch) | |
tree | 4946ae32526a553f047b52a24f9c7d649b014d53 | |
parent | 6ff6083308d6755a357fa7964d9ce20a25b1d413 (diff) |
Add chaining.
-rw-r--r-- | assets/images/chain.png | bin | 0 -> 698 bytes | |||
-rw-r--r-- | assets/images/chain.xcf | bin | 0 -> 3791 bytes | |||
-rw-r--r-- | game.scm | 69 |
3 files changed, 59 insertions, 10 deletions
diff --git a/assets/images/chain.png b/assets/images/chain.png Binary files differnew file mode 100644 index 0000000..dc59d12 --- /dev/null +++ b/assets/images/chain.png diff --git a/assets/images/chain.xcf b/assets/images/chain.xcf Binary files differnew file mode 100644 index 0000000..40fecd9 --- /dev/null +++ b/assets/images/chain.xcf @@ -270,7 +270,7 @@ (define max-chain-multiplier 10) -(define (add-to-score stats enemy) +(define (add-to-score enemy stats) ;; TODO: Award different points for different types of enemies. (make-stats #:inherit stats #:score (+ (stats-score stats) @@ -280,6 +280,27 @@ (min (stats-chain stats) max-chain-multiplier))))) +(define (add-to-chain enemy stats) + (let* ((enemy-polarity (enemy-polarity enemy)) + (chain-polarity (stats-chain-type stats)) + (progress (stats-chain-progress stats))) + (cond + ((or (zero? progress) (= progress 3)) + (make-stats #:inherit stats + #:chain-type enemy-polarity + #:chain-progress 1)) + ((not (eq? enemy-polarity chain-polarity)) + (make-stats #:inherit stats + #:chain-type #f + #:chain-progress 0)) + ((= progress 1) + (make-stats #:inherit stats + #:chain-progress 2)) + ((= progress 2) + (make-stats #:inherit stats + #:chain-progress 3 + #:chain (1+ (stats-chain stats))))))) + ;;; ;;; Collision detection @@ -324,24 +345,26 @@ (values enemy (reverse prev-bullets) stats explosions)) ((bullet . rest) (if (enemy/bullet-collision? (actor-ref enemy) (actor-ref bullet)) - (let ((new-enemy (call-with-actor enemy + (let* ((new-enemy (call-with-actor enemy (lambda (enemy) (damage-enemy enemy (actor-ref bullet) - time))))) + time)))) + (new-enemy* (actor-ref new-enemy))) (values new-enemy ;; Remove bullet. (append (reverse prev-bullets) rest) - (if (enemy-alive? (actor-ref new-enemy)) + (if (enemy-alive? new-enemy*) stats - ;; Enemy killed, add to player score. - (add-to-score stats (actor-ref new-enemy))) - (if (enemy-alive? (actor-ref new-enemy)) + ;; Enemy killed, add to player score and + (add-to-chain new-enemy* + (add-to-score new-enemy* stats))) + (if (enemy-alive? new-enemy*) explosions ;; Add new explosion. (cons (make-explosion #:type 'regular #:position (enemy-position - (actor-ref enemy)) + new-enemy*) #:time time) explosions)))) (loop rest (cons bullet prev-bullets) stats)))))) @@ -673,6 +696,30 @@ each time KEY is pressed." (define-signal explosion-tileset (load-tileset/live "assets/images/explosion.png" 16 16)) +(define-signal chain-tileset + (load-tileset/live "assets/images/chain.png" 24 16)) + +(define make-chain-sprite + (memoize + (lambda (tileset stats) + (make-sprite (tileset-ref tileset + (- (match (stats-chain-type stats) + ('light 2) + ('dark 5)) + (1- (stats-chain-progress stats)))) + #:anchor 'top-left)))) + +(define-signal chain-sprite + (signal-map-maybe (lambda (world tileset) + (let ((stats (world-stats world))) + (if (zero? (stats-chain-progress stats)) + render-nothing + (move (vector2 0 (- (vy resolution) 5)) + (render-sprite + (make-chain-sprite tileset stats)))))) + world + chain-tileset)) + (define-signal player-sprite (signal-map-maybe (lambda (world tileset) (make-sprite @@ -798,6 +845,7 @@ each time KEY is pressed." (framebuffer framebuffer) (framebuffer-sprite framebuffer-sprite) (player-sprite player-sprite) + (chain-sprite chain-sprite) (bullet-tileset bullet-tileset) (enemy-tileset enemy-tileset) (explosion-tileset explosion-tileset) @@ -805,7 +853,7 @@ each time KEY is pressed." (world world) (time timer)) (if (and framebuffer framebuffer-sprite batch bullet-tileset - enemy-tileset player-sprite explosion-tileset) + enemy-tileset player-sprite explosion-tileset chain-sprite) (let ((player (actor-ref (world-player world)))) (render-begin (with-framebuffer framebuffer @@ -834,7 +882,8 @@ each time KEY is pressed." render-nothing) score-text lives-text - chain-text))))) + chain-text)) + chain-sprite))) (with-camera scaled-camera (scale resolution-scale (render-sprite framebuffer-sprite))))) render-nothing))) |