From 234e2e23b0e977ff9fed415846e9796332cb0759 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 4 May 2021 08:26:53 -0400 Subject: Factor out splash screen and credits sequence into their own scenes. --- Makefile.am | 5 +- scripts/the-test-subject | 2 +- test-subject/assets.scm | 14 ++++- test-subject/common.scm | 24 ++++++++ test-subject/credits.scm | 64 ++++++++++++++++++++++ test-subject/game.scm | 140 ++++++++++------------------------------------- test-subject/splash.scm | 49 +++++++++++++++++ 7 files changed, 183 insertions(+), 115 deletions(-) create mode 100644 test-subject/common.scm create mode 100644 test-subject/credits.scm create mode 100644 test-subject/splash.scm diff --git a/Makefile.am b/Makefile.am index 724c075..238e827 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,10 +25,13 @@ bin_SCRIPTS = \ scripts/the-test-subject SOURCES = \ + test-subject/common.scm \ test-subject/assets.scm \ test-subject/text-box.scm \ test-subject/device.scm \ - test-subject/game.scm + test-subject/credits.scm \ + test-subject/game.scm \ + test-subject/splash.scm fontsdir = $(pkgdatadir)/assets/fonts dist_fonts_DATA = \ diff --git a/scripts/the-test-subject b/scripts/the-test-subject index df8e56d..a2c9976 100755 --- a/scripts/the-test-subject +++ b/scripts/the-test-subject @@ -1,3 +1,3 @@ #!/bin/sh -exec guile -c '(use-modules (test-subject game)) (launch-game)' +exec guile -c '(use-modules (test-subject splash)) (launch-game)' diff --git a/test-subject/assets.scm b/test-subject/assets.scm index 68d3101..e3604a5 100644 --- a/test-subject/assets.scm +++ b/test-subject/assets.scm @@ -25,7 +25,10 @@ key-press-sound device-sound gameplay-music - credits-music)) + credits-music + play-click-sound + play-key-press-sound + play-device-sound)) (define (scope-datadir file-name) (let ((prefix (or (getenv "TEST_SUBJECT_DATADIR") (getcwd)))) @@ -54,3 +57,12 @@ (define-asset device-sound (load-audio (scope-datadir "assets/sounds/switch38.wav"))) (define-asset gameplay-music (load-audio (scope-datadir "assets/sounds/ambientmain_0.ogg") #:mode 'stream)) (define-asset credits-music (load-audio (scope-datadir "assets/sounds/end-theme.mp3") #:mode 'stream)) + +(define (play-click-sound) + (audio-play (asset-ref click-sound))) + +(define (play-key-press-sound) + (audio-play (asset-ref key-press-sound))) + +(define (play-device-sound) + (audio-play (asset-ref device-sound))) diff --git a/test-subject/common.scm b/test-subject/common.scm new file mode 100644 index 0000000..9e756b3 --- /dev/null +++ b/test-subject/common.scm @@ -0,0 +1,24 @@ +(define-module (test-subject common) + #:use-module (chickadee graphics color) + #:use-module (chickadee graphics viewport) + #:use-module (chickadee math vector) + #:use-module (oop goops) + #:use-module (starling node-2d) + #:use-module (starling scene) + #:export (%window-width + %window-height + %game-width + %game-height + set-cameras!)) + +(define %window-width 1280) +(define %window-height 720) +(define %game-width 640) +(define %game-height 360) + +(define-method (set-cameras! (scene )) + (set! (cameras scene) + (list (make + #:resolution (vec2 %game-width %game-height) + #:viewport (make-viewport 0 0 %window-width %window-height + #:clear-color black))))) diff --git a/test-subject/credits.scm b/test-subject/credits.scm new file mode 100644 index 0000000..98c9257 --- /dev/null +++ b/test-subject/credits.scm @@ -0,0 +1,64 @@ +(define-module (test-subject credits) + #:use-module (chickadee graphics color) + #:use-module (chickadee math vector) + #:use-module (chickadee scripting) + #:use-module (oop goops) + #:use-module (starling kernel) + #:use-module (starling node) + #:use-module (starling node-2d) + #:use-module (starling scene) + #:use-module (test-subject assets) + #:use-module (test-subject common) + #:export ()) + +(define-class () + (true-ending? #:getter true-ending? #:init-keyword #:true-ending? + #:init-value #f) + (click-channel #:getter click-channel #:init-thunk make-channel)) + +(define-method (on-boot (credits )) + (set-cameras! credits) + (attach-to credits + (make + #:name 'background + #:texture lightness) + (make