summaryrefslogtreecommitdiff
path: root/scenes/intro.scm
blob: b1480dcadba6724a7aa35cef1c2b7182db1907b1 (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
;;; The Inevitable Game
;;; Copyright © 2018 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 math rect)
  #:use-module (chickadee math vector)
  #:use-module ((chickadee render color) #:select (make-color))
  #:use-module (chickadee render font)
  #:use-module (chickadee render texture)
  #:use-module (chickadee scripting)
  #:use-module (engine assets)
  #:use-module (engine audio)
  #:use-module (engine node)
  #:use-module (engine node-2d)
  #:use-module (engine scene)
  #:use-module (engine shell)
  #:use-module (config)
  #:use-module (scenes game)
  #:use-module (oop goops)
  #:export (intro))

(define-class <intro> (<scene>))

(define-asset game-font
  (load-font "assets/fonts/good_neighbors_starling.xml"))

(define-asset intro-bg (load-image "assets/images/intro-bg.png"))

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

(set! *random-state* (random-state-from-platform))

(define-method (populate (intro <intro>))
  (cons
   (let ((text "Press enter to start.")
         (font game-font))
     (make <label>
       #:name 'press-enter
       #:font font
       #:text text
       #:position
       (let ((width (font-line-width (asset-ref font) text)))
         (vec2 (- (/ %width 2)
                  (/ width 2))
               30.0))))
   (let* ((text (list-ref texts (random (length texts))))
          (parts (string-split text #\newline)))
     (map (lambda (part i)
            (make <label>
              #:name 'welcome
              #:font game-font
              #:text part
              #:position (vec2 (- (/ %width 2)
                                  (/ (font-line-width (asset-ref game-font) part) 2))
                               (- 120.0 (* 15 i)))))
          parts (iota (length parts))))))

(define-method (on-key-press (intro <intro>) key mods repeat?)
  (when (eq? key 'return)
    (let ((fade (child-ref (parent intro) 'fade-all)))
      (script
       (tween 60 0.0 1.0
              (lambda (alpha)
                (set! (color fade)
                      (make-color 0 0 0 alpha))))
       (switch-scene (root-node)
                     (game))))))

(define (intro)
  (set-music-volume! 1.0)
  (play-music (load-music "assets/music/intro.ogg") #:loop? #f)
  (let ((container (make <node-2d>
                     #:children
                     (list
                      (make <sprite>
                        #:name 'bg
                        #:texture (asset-ref intro-bg))
                      (make <intro>)
                      (make <filled-rect>
                        #:name 'fade-all
                        #:region (make-rect 0.0 0.0 %width %height)
                        #:color (make-color 1 1 1 1.0))))))
    ;; Fade in
    (with-agenda
     (agenda container)
     (script
      (tween 240 1.0 0.0
             (lambda (alpha)
               (set! (color (child-ref container 'fade-all))
                     (make-color 1 1 1 alpha))))))
    container))