summaryrefslogtreecommitdiff
path: root/scenes
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2018-07-24 23:04:24 +0200
committerRicardo Wurmus <rekado@elephly.net>2018-07-27 17:15:48 +0200
commit41445ed2a2fff494f552e18801000b3a5623fd5d (patch)
tree2f35df75590727db1ba72a1ced610cfea4178adf /scenes
parentd7496041423731bc2396bdbb2e5483e5fe1e57f9 (diff)
Finish death/credits scene.
Diffstat (limited to 'scenes')
-rw-r--r--scenes/credits.scm47
-rw-r--r--scenes/death.scm276
2 files changed, 256 insertions, 67 deletions
diff --git a/scenes/credits.scm b/scenes/credits.scm
deleted file mode 100644
index c6159df..0000000
--- a/scenes/credits.scm
+++ /dev/null
@@ -1,47 +0,0 @@
-;;; 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 credits)
- #:use-module (chickadee)
- #:use-module (chickadee math vector)
- #:use-module (chickadee render font)
- #:use-module (engine assets)
- #:use-module (engine node)
- #:use-module (engine node-2d)
- #:use-module (engine scene)
- #:use-module (scenes game)
- #:use-module (oop goops)
- #:export (credits))
-
-(define-class <credits> (<scene>))
-
-(define-asset credits-font
- (load-tile-font "assets/fonts/bubblemad_8x8.png" 8 8
- " !\"©_%❤'()*+,-./0123456789:←<=>?@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))
-
-(define-method (populate (credits <credits>))
- (list
- (make <label>
- #:name 'press-enter
- #:font credits-font
- #:text "Press any key to quit."
- #:position (vec2 72.0 50.0))))
-
-(define-method (on-key-press (credits <credits>) key mods repeat?)
- (abort-game))
-
-(define (credits) (make <credits>))
diff --git a/scenes/death.scm b/scenes/death.scm
index 4682217..29d006f 100644
--- a/scenes/death.scm
+++ b/scenes/death.scm
@@ -16,23 +16,37 @@
;;; <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 audio)
+ #:use-module (chickadee math rect)
#:use-module (chickadee math vector)
+ #:use-module (chickadee render color)
#:use-module (chickadee render font)
+ #:use-module (chickadee render texture)
+ #:use-module (chickadee render shader)
+ #:use-module (chickadee render tiled)
+ #:use-module (chickadee scripting)
#:use-module (engine assets)
#:use-module (engine node)
#:use-module (engine node-2d)
#:use-module (engine scene)
- #:use-module (engine shell)
- #:use-module (scenes credits)
#:use-module (oop goops)
+ #:use-module (config)
+ #:use-module (characters)
+ #:use-module (characters lorenzo)
+ #:use-module (characters reaper)
#:export (death))
-(define-class <death> (<scene>))
+(define-asset death-map (load-tile-map "assets/maps/death.tmx"))
+
+(define-class <death> (<scene>)
+ (tile-map #:accessor tile-map #:init-form death-map)
+ (pretend-walking? #:accessor pretend-walking? #:init-form #f))
(define-asset death-font
- (load-tile-font "assets/fonts/bubblemad_8x8.png" 8 8
- " !\"©_%❤'()*+,-./0123456789:←<=>?@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))
+ (load-font "assets/fonts/good_neighbors_starling.xml"))
(define-asset music-death (load-music "assets/music/death.ogg"))
@@ -75,31 +89,253 @@ to fight. Let go."
Life is hard, but thankfully
quite short."))
+(define credits
+ '(("The Inevitable Game"
+ "Made by Ricardo Wurmus"
+ "For Lorenzo")
+ ("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\"")
+ ("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))
+;; This shader renders the texture after blending each pixel with a
+;; 0.1 opacity pixel, thereby rendering everything with increased
+;; transparency.
+(define ghost-shader
+ (delay
+ (strings->shader
+ "
+#version 130
+
+in vec2 position;
+in vec2 tex;
+out vec2 frag_tex;
+uniform mat4 mvp;
+
+void main(void) {
+ frag_tex = tex;
+ gl_Position = mvp * vec4(position.xy, 0.0, 1.0);
+}
+"
+ "
+#version 130
+
+in vec2 frag_tex;
+uniform sampler2D color_texture;
+
+void main (void) {
+ vec4 original = texture2D(color_texture, frag_tex);
+ vec4 g;
+
+ g = vec4(1, 1, 1, 0.1);
+ g = mix(g, original, 0.5);
+ gl_FragColor = vec4(original.rgb, min(g.a,original.a));
+ if (gl_FragColor.a < 0.5)
+ {
+ discard;
+ }
+}
+")))
+
(define-method (populate (death <death>))
(cons
- (make <label>
- #:name 'press-enter
- #:font death-font
- #:text "Press any key to quit."
- #:position (vec2 72.0 50.0))
(let* ((text (list-ref texts (random (length texts))))
(parts (string-split text #\newline)))
- (map (lambda (part i)
- (make <label>
- #:name 'death
- #:font death-font
- #:text part
- #:position (vec2 16.0 (- 150.0 (* 12 i)))))
- parts (iota (length parts))))))
+ (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)
+ #:shader ghost-shader)))
+ (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?)
- (switch-scene (root-node)
- (credits)))
+ (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)
(play-music (load-music "assets/music/death.ogg") #:loop? #t)
- (make <death>))
+ (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 <label>
+ #:name 'press-enter
+ #:font death-font
+ #:text "Press any key to quit."
+ #:position (vec2 72.0 20.0))
+ (make <node-2d>
+ #:name 'credits-container
+ #:origin (vec2 (- (/ %width 2))
+ (- (/ %height 2)))))))
+ (credits-container
+ (child-ref container 'credits-container)))
+ (with-agenda
+ (agenda death)
+ (script
+ (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)))