summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--boot.js9
-rw-r--r--game.scm35
3 files changed, 43 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 7d0db11..a1faad0 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ level.scm: level.tmx compile-map.scm
bundle: game.wasm
rm strigoform.zip || true
- zip strigoform.zip -r audio/ images/*.png fonts/ js-runtime/ boot.js game.css game.wasm index.html
+ zip strigoform.zip -r audio/*.wav images/*.png fonts/ js-runtime/ boot.js game.css game.wasm index.html
serve:
guile web-server
diff --git a/boot.js b/boot.js
index d62791e..fbb2468 100644
--- a/boot.js
+++ b/boot.js
@@ -127,11 +127,20 @@ async function load() {
play(audio) {
audio.play();
},
+ pause(audio) {
+ audio.pause();
+ },
volume(audio) {
return audio.volume;
},
setVolume(audio, vol) {
audio.volume = vol;
+ },
+ setLoop(audio, loop) {
+ audio.loop = (loop == 1);
+ },
+ seek(audio, time) {
+ audio.currentTime = time;
}
},
image: {
diff --git a/game.scm b/game.scm
index 6d5b884..d33ea54 100644
--- a/game.scm
+++ b/game.scm
@@ -121,12 +121,21 @@
(define-foreign audio-play
"audio" "play"
(ref extern) -> none)
+ (define-foreign audio-pause
+ "audio" "pause"
+ (ref extern) -> none)
(define-foreign audio-volume
"audio" "volume"
(ref extern) -> f64)
(define-foreign set-audio-volume!
"audio" "setVolume"
(ref extern) f64 -> none)
+ (define-foreign set-audio-loop!
+ "audio" "setLoop"
+ (ref extern) i32 -> none)
+ (define-foreign audio-seek
+ "audio" "seek"
+ (ref extern) f64 -> none)
(define-foreign load-image
"image" "new"
@@ -342,6 +351,18 @@
(define sound:player-death (load-sound-effect "audio/player-death.wav"))
(define sound:enemy-shoot (load-sound-effect "audio/enemy-shoot.wav"))
(define sound:bullet-hit (load-sound-effect "audio/bullet-hit.wav"))
+ ;; (define music (load-audio "audio/music.wav"))
+ ;; (set-audio-loop! music 1)
+ (define (music-play)
+ ;; (audio-play music)
+ #t)
+ (define (music-pause)
+ ;; (audio-pause music)
+ #t)
+ (define (music-stop)
+ ;; (audio-pause music)
+ ;; (audio-seek music 0.0)
+ #t)
(define *debug?* #f)
@@ -1359,6 +1380,10 @@
(vec2-normalize! v*)
v*))
+ (define (do-splash)
+ (music-stop)
+ (set! *game-state* 'splash))
+
;; Game over screen state
(define *countdown* "")
(define *countdown-scheduler* (make-scheduler 5))
@@ -1371,9 +1396,10 @@
(wait 60)
(unless (= i 0)
(loop (- i 1))))
- (set! *game-state* 'splash)))))
+ (do-splash)))))
(define (do-game-over)
(scheduler-reset! *countdown-scheduler*)
+ (music-stop)
(set! *game-state* 'game-over)
(do-countdown))
(define (do-continue)
@@ -1392,6 +1418,7 @@
(define *clear-total-score* "")
(define (do-game-clear)
(scheduler-reset! *scheduler*)
+ (music-stop)
(set! *game-state* 'game-clear)
(set! *clear-show-1cc-bonus?* #f)
(set! *clear-show-life-bonus?* #f)
@@ -1595,6 +1622,8 @@
(request-animation-frame draw)))
(define (reset!)
+ (music-stop)
+ (music-play)
(set! *game-state* 'play)
(scheduler-reset! *scheduler*)
(set! *scroll* 0.0)
@@ -1671,6 +1700,7 @@
(cond
((string-=? code "Enter")
(set! *game-state* 'pause)
+ (music-pause)
(prevent-default! event))
((string-=? code "KeyD")
(set! *debug?* (not *debug?*))
@@ -1688,11 +1718,12 @@
(cond
((string-=? code "Enter")
(set! *game-state* 'play)
+ (music-play)
(prevent-default! event))))
('game-clear
(cond
((string-=? code "Enter")
- (set! *game-state* 'splash)
+ (do-splash)
(prevent-default! event))))
('game-over
(cond