summaryrefslogtreecommitdiff
path: root/lisparuga/enemy.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2020-04-12 21:59:35 -0400
committerDavid Thompson <dthompson@vistahigherlearning.com>2020-04-12 21:59:35 -0400
commit2bdb665cffff93721bbd38b3809a7c420dff2f1c (patch)
treede12f43ec1b8053f99f182d06d404a97ba62f64f /lisparuga/enemy.scm
parent729f0b687b975e60f338831bcb0d59fad776f3e1 (diff)
Day 3 progress.
Diffstat (limited to 'lisparuga/enemy.scm')
-rw-r--r--lisparuga/enemy.scm10
1 files changed, 9 insertions, 1 deletions
diff --git a/lisparuga/enemy.scm b/lisparuga/enemy.scm
index 0589d16..aa5335e 100644
--- a/lisparuga/enemy.scm
+++ b/lisparuga/enemy.scm
@@ -21,6 +21,7 @@
;;; Code:
(define-module (lisparuga enemy)
+ #:use-module (chickadee audio)
#:use-module (chickadee math)
#:use-module (chickadee math rect)
#:use-module (chickadee math vector)
@@ -46,6 +47,9 @@
;;;
;;; Base Enemy
;;;
+
+(define-asset explosion-sound (load-audio (scope-asset "sounds/explosion.wav")))
+
(define-class <enemy> (<actor>)
(health #:accessor health #:init-keyword #:health)
(points #:getter points #:init-keyword #:points)
@@ -56,7 +60,11 @@
#t)
(define-method (damage (enemy <enemy>) x)
- (set! (health enemy) (max (- (health enemy) x) 0)))
+ (let ((new-health (max (- (health enemy) x) 0)))
+ (set! (health enemy) new-health)
+ (when (zero? new-health)
+ (audio-play (asset-ref explosion-sound)
+ #:volume 0.5))))
(define-method (dead? (enemy <enemy>))
(zero? (health enemy)))