;;; The Inevitable Game ;;; Copyright © 2018, 2021 Ricardo Wurmus ;;; ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU General Public License as ;;; published by the Free Software Foundation, either version 3 of the ;;; License, or (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;; General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program. If not, see ;;; . (define-module (scenes intro) #:use-module (chickadee) #:use-module (chickadee audio) #:use-module (chickadee math vector) #:use-module (chickadee math rect) #:use-module ((chickadee graphics color) #:select (make-color)) #:use-module (chickadee graphics text) #:use-module (chickadee graphics path) #:use-module (chickadee graphics sprite) #:use-module (chickadee graphics texture) #:use-module (chickadee scripting) #:use-module (config) #:use-module (engine assets) #:export (scene)) (define-asset game-font (load-bitmap-font "assets/fonts/good_neighbors_starling.xml")) (define-asset intro-bg (load-image "assets/images/intro-bg.png")) (define-asset music (load-audio "assets/music/intro.ogg" #:mode 'stream)) (define agenda (make-agenda)) (define fade-box-fill (make-color 1 1 1 1.0)) (define fade-box (fill (rectangle (vec2 0 0) %width %height))) (define texts '("\ The void has been suspended for a little while. You exist now." "\ Confusion gives way to a brief burst of consciousness. Here you are. What now?" "\ The haze clears and you can see that you are here now. You did not ask for this." "\ You rise from deepest waters and take your first breath. You wonder: will this last?" "\ History yields to the present. The present crumbles underfoot. You better move." "\ A leaf has turned. The sunshine warms and blinds. The leaf begins to dry.")) (define welcome-text #false) (define (load-scene) (set! *random-state* (random-state-from-platform)) (set! welcome-text (list-ref texts (random (length texts)))) (source-play (make-source #:audio (asset-ref music) #:loop? #false)) (with-agenda agenda (spawn-script (lambda () (wait-until (key-pressed? 'return)) ;; Fade out (tween 60 0.0 1.0 (lambda (alpha) (set! fade-box-fill (make-color 0 0 0 alpha)))) (throw 'switch-scene (module-ref (resolve-interface '(scenes game)) 'scene)))) (script ;; Fade in (tween 120 1.0 0.0 (lambda (alpha) (set! fade-box-fill (make-color 1 1 1 alpha)))))) (current-agenda agenda)) (define (draw-scene alpha) ;; Background (draw-sprite (asset-ref intro-bg) (vec2 0 0)) ;; Text (let ((text "Press enter to start.")) (draw-text text (let ((width (font-line-width (asset-ref game-font) text))) (vec2 (- (/ %width 2) (/ width 2)) 30.0)) #:font (asset-ref game-font))) (let ((parts (string-split welcome-text #\newline))) (for-each (lambda (part i) (draw-text part (vec2 (- (/ %width 2) (/ (font-line-width (asset-ref game-font) part) 2)) (- 120.0 (* 15 i))) #:font (asset-ref game-font))) parts (iota (length parts)))) ;; Fade box (draw-canvas (make-canvas (with-style ((fill-color fade-box-fill)) fade-box)))) (define update-scene update-agenda) (define scene `(#:name "intro" #:load ,load-scene #:draw ,draw-scene #:update ,update-scene))