summaryrefslogtreecommitdiff
path: root/scenes/death.scm
blob: 04441121929f939a926b46ddb734db2fbbbffda2 (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
;;; 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 death)
  #:use-module (srfi srfi-1)
  #:use-module (ice-9 match)
  #:use-module (chickadee)
  #: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 render tiled)
  #: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 (oop goops)
  #:use-module (config)
  #:use-module (characters)
  #:use-module (characters lorenzo)
  #:use-module (characters reaper)
  #:export (death))

(define-asset death-map (load-tile-map "assets/maps/death.tmx"))
(define-asset vignette-image (load-image "assets/images/vignette.png"))

(define-class <death> (<scene>)
  (quitting? #:accessor quitting? #:init-form #f)
  (tile-map #:accessor tile-map #:init-form death-map)
  (pretend-walking? #:accessor pretend-walking? #:init-form #f))

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

(define-asset music-death (load-music "assets/music/death.ogg"))

(define texts
  '("\
Life waits for no one, but
death is patient."

    "\
You have died.  Your points
don't matter."

    "\
Death is inevitable."

    "\
The void resumes."

    "\
It did not last."

    "\
You were busy, but none of that
matters any more."

    "\
You were mortal after all."

    "\
Nobody outruns the clock."

    "\
Life goes on, but you end here."

    "\
This is no longer your battle
to fight.  Let go."

    "\
Life is hard, but thankfully
quite short."))

(define credits
  '(("The Inevitable Game"
     "Made by Ricardo Wurmus"
     "For Lorenzo")
    ("Sky background"
     "by Paulina Riva (CC-BY 3.0)")
    ("Reaper character graphics"
     "based on \"Lil Reaper Pet\" by Tracy")
    ("Lorenzo character graphics"
     "Based on \"Small 3/4 RPG character base\""
     "by Stephen Challener (Redshrike)")
    ("Map tiles"
     "taken from \"Zelda-like tilesets and sprites\""
     "by ArMM1998")
    ("Food graphics"
     "taken from \"The Humble Food Pack\""
     "by \"The Wise Hedgehog\"")
    ("Font"
     "\"Good Neighbors Starling\""
     "by PROWNE and Clint Bellanger")
    ("All music"
     "composed and recorded"
     "by Ricardo Wurmus")
    ("Bird sounds"
     "taken from the public domain")
    ("Made with 100% Free Software including"
     "- GNU Guile"
     "- Chickadee"
     "- Guile OpenGL"
     "- SDL")
    ("Thanks for enduring this game!")))

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

(define-method (populate (death <death>))
  (cons
   (let* ((text (list-ref texts (random (length texts))))
          (parts (string-split text #\newline)))
     (make <node-2d>
       #:name 'top-text
       #:children
       (map (lambda (part i)
              (make <label>
                #:name (symbol-append 'death-text-
                                      (string->symbol
                                       (number->string i)))
                #:font death-font
                #:text part
                #:position (vec2 16.0 (- 190.0 (* 12 i)))))
            parts (iota (length parts)))))
   (list
    (make <sprite>
      #:name 'dead-lorenzo
      #:texture (texture-atlas-ref
                 (asset-ref player-atlas) 23)
      #:position (vec2 40.0 70.0))
    (make <filled-rect>
      #:name 'fade-box
      #:region (make-rect 0.0 0.0 %width %height)
      #:color (make-color 0.125 0.09 0.161 0))
    (let ((player (lorenzo #:position (vec2 40.0 70.0)
                           #:dead? #t)))
      (set! (visible? player) #f)
      (set! (walk-speed player) 0.3)
      player)
    (let ((reaper (reaper (vec2 140.0 70.0))))
      (set! (walk-speed reaper) 0.3)
      reaper))))

(define-method (on-key-press (death <death>) key mods repeat?)
  ;; Fade out
  (unless (quitting? death)
    (set! (quitting? death) #t)
    (script
     (tween 60 0.0 1.0
            (lambda (alpha)
              (set! (color (child-ref (parent death) 'fade-all))
                    (make-color 0 0 0 alpha))))
     (abort-game))))

(define-method (update (game <death>) dt)
  ;; Keep the player (and the fade box) in the centre
  (let* ((player (child-ref game 'player))
         (reaper (child-ref game 'reaper))
         (pos (position player))
         (vel (velocity player)))
    ;; Update player position
    (unless (pretend-walking? game)
      (vec2-add! pos vel)
      (vec2-add! (position reaper) (velocity reaper))
      (move-to game
               (- 0 (vec2-x pos))
               (- 0 (vec2-y pos)))
      ;; Adjust fade box
      (move-to (child-ref game 'fade-box)
               (- (vec2-x pos) (/ %width 2))
               (- (vec2-y pos) (/ %height 2)))
      ;; Adjust text
      (move-to (child-ref game 'top-text)
               (- (vec2-x pos) (/ %width 2))
               (- (vec2-y pos) (/ %height 2))))))

(define-method (draw (game <death>) alpha)
  (draw-tile-map (asset-ref (tile-map game))
                 #:position (position game)))

(define (death)
  (set-music-volume! 1.0)
  (stop-music)
  (resume-music)
  (play-music (load-music "assets/music/death.ogg") #:loop? #t)
  (let* ((death (make <death>
                  #:origin (vec2 (- (/ %width 2))
                                 (- (/ %height 2)))))
         (player (child-ref death 'player))
         (reaper (child-ref death 'reaper)))
    (let* ((container
            (make <node-2d>
              #:children
              (list death
                    (make <sprite>
                      #:name 'vignette
                      #:texture (asset-ref vignette-image))
                    (let ((text "Press any key to quit.")
                          (font death-font))
                      (make <label>
                        #:font font
                        #:text text
                        #:position
                        (let ((width (font-line-width (asset-ref font) text)))
                          (vec2 (- (/ %width 2)
                                   (/ width 2))
                                30.0))))
                    (make <node-2d>
                      #:name 'credits-container
                      #:origin (vec2 (- (/ %width 2))
                                     (- (/ %height 2))))
                    (make <filled-rect>
                      #:name 'fade-all
                      #:region (make-rect 0.0 0.0 %width %height)
                      #:color (make-color 0 0 0 1.0)))))
           (credits-container
            (child-ref container 'credits-container)))
      (with-agenda
       (agenda death)
       (script
        ;; Fade in
        (tween 15 1.0 0.0
               (lambda (alpha)
                 (set! (color (child-ref container 'fade-all))
                       (make-color 0 0 0 alpha))))
        (sleep 150)
        (set! (visible? player) #t)
        (walk player '(right))
        (sleep 250)
        (walk player '(right) 'stop)
        (walk player '(idle-front))
        (sleep 160)
        (walk player '(up))
        (walk reaper '(up))
        (sleep 200)
        ;; Slowly fade out the map and the top text.
        (tween 600 0.0 1.0 (lambda (value)
                             (set! (color (child-ref death 'fade-box))
                                   ;; That's the colour of the "black" cave tile.
                                   (make-color 0.125 0.09 0.161 value))))
        (set! (pretend-walking? death) #t)
        (sleep 100)
        (for-each
         (match-lambda
           ((first . rest)
            (let ((label1
                   (make <label>
                     #:font death-font
                     #:text first
                     #:visible? #f
                     #:origin (vec2 (/ %width 2)
                                    (/ %height 2))
                     #:position
                     (vec2 16.0 180)))
                  (other-labels
                   (map (lambda (text i)
                          (make <label>
                            #:font death-font
                            #:text text
                            #:visible? #f
                            #:origin (vec2 (/ %width 2)
                                           (/ %height 2))
                            #:position
                            (vec2 16.0 (- 180.0 (* 12 (+ i 1))))))
                        rest
                        (iota (length rest)))))
              (attach credits-container label1)
              (set! (visible? label1) #t)
              (for-each (lambda (label)
                          (attach credits-container label)
                          (set! (visible? label) #t))
                        other-labels)
              (sleep 300)
              (set! (visible? label1) #f)
              (for-each (lambda (label)
                          (set! (visible? label) #f))
                        other-labels))))
         credits)
        (sleep 600)
        (for-each (lambda (text)
                    (let ((label
                           (make <label>
                             #:font death-font
                             #:text text
                             #:visible? #f
                             #:origin (vec2 (/ %width 2)
                                            (/ %height 2))
                             #:position
                             (vec2 16.0 180))))
                      (attach credits-container label)
                      (set! (visible? label) #t)
                      (sleep 300)
                      (set! (visible? label) #f)
                      (sleep (+ (random 1000) 400))))
                  `("There is nothing more to see here."
                    "I'm serious."
                    "What are you waiting for?"
                    "Don't waste your time!"
                    "Have you learned nothing from this game?"
                    "I've got all day, but how about you?"
                    "Look, I'm programmed to just keep going."
                    "Ugh... why are you even reading this?"
                    "Let me tell you a story..."
                    "Once upon a time, there was..."
                    ,@(let ((what '(("...a squirrel." "It had a nut allergy and died.")
                                    ("...a dolphin." "It swam too far and never returned.")
                                    ("...a stupid fish." "It drowned.")
                                    ("...a long war." "Everybody died."))))
                        (list-ref what (random (length what))))
                    "End of story."
                    "Good night."
                    "Please just turn it off."
                    "I'm begging you."
                    "You're not listening, huh?"
                    "Well, I guess I'll just stop talking then."))))
      container)))