summaryrefslogtreecommitdiff
path: root/scenes/intro.scm
blob: 15a25c076710d289bd64539a96fae7f7a6f16494 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
;;; The Inevitable Game
;;; Copyright © 2018, 2021 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; 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
;;; <http://www.gnu.org/licenses/>.

(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))