From 68e58d6fce955ac07c5409b0cd062bf6cfb6cf46 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Wed, 8 Aug 2018 18:55:11 +0200 Subject: game: Trigger transitions only once. --- scenes/game.scm | 78 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/scenes/game.scm b/scenes/game.scm index fae998d..2533310 100644 --- a/scenes/game.scm +++ b/scenes/game.scm @@ -19,6 +19,7 @@ (define-module (scenes game) #:use-module (chickadee audio) #:use-module (chickadee input keyboard) + #:use-module (chickadee math easings) #:use-module (chickadee math rect) #:use-module (chickadee math vector) #:use-module (chickadee render color) @@ -210,6 +211,7 @@ positions layer." (define-method (die (game )) "Fade out and switch to death scene." (let ((fade (child-ref (parent game) 'fade-box))) + (set! (status game) 'dying) (script (tween 60 0.0 1.0 (lambda (alpha) @@ -218,14 +220,15 @@ positions layer." (switch-scene (root-node) (death))))) (define-method (on-key-press (game ) key modifiers repeat?) - (let ((player (child-ref game 'player))) - (when (eq? key 'q) (die game)) - (let ((who (talking? player))) - (cond - ((and (not who) (eq? 'space key)) - (handle-action player)) - ((and who (not repeat?)) - (handle-talking player key)))))) + (when (eq? (status game) 'playing) + (let ((player (child-ref game 'player))) + (when (eq? key 'q) (die game)) + (let ((who (talking? player))) + (cond + ((and (not who) (eq? 'space key)) + (handle-action player)) + ((and who (not repeat?)) + (handle-talking player key))))))) (define (handle-action player) "Check if the PLAYER is on any region of the map where an action can @@ -453,23 +456,42 @@ conversation." (let* ((player (child-ref game 'player)) (current-lifetime (lifetime player))) (if (< current-lifetime 0) - (set! (status game) 'game-over) - (set! (lifetime player) (- current-lifetime 1))))))) - (make - #:children - (list game - (make - #:name 'fade-box - #:region (make-rect 0.0 0.0 %width %height) - #:color (make-color 0 0 0 0)) - (make - #:name 'text-bubble - #:position (vec2 0 0) - #:visible? #f - #:children - (list (make - #:name 'text-bubble-box - #:region (make-rect 0.0 0.0 %width 80) - #:position (vec2 0 0) - #:rank -10 ; background - #:color (make-color 0 0 0 0.5)))))))) + (die game) + (set! (lifetime player) (- current-lifetime 1)))))) + (script + (tween 60 0.0 1.0 + (lambda (a) + (set-music-volume! a) + (sleep 10)) + #:ease ease-out-sine))) + (let ((container + (make + #:children + (list game + (make + #:name 'fade-box + #:region (make-rect 0.0 0.0 %width %height) + #:color (make-color 0 0 0 0)) + (make + #:name 'vignette + #:texture (asset-ref vignette-image)) + (make + #:name 'text-bubble + #:position (vec2 0 0) + #:visible? #f + #:children + (list (make + #:name 'text-bubble-box + #:region (make-rect 0.0 0.0 %width 80) + #:position (vec2 0 0) + #:rank -10 ; background + #:color (make-color 0 0 0 0.5)))))))) + (with-agenda + (agenda container) + (let ((fade (child-ref container 'fade-box))) + (script + (tween 15 1.0 0.0 + (lambda (alpha) + (set! (color fade) + (make-color 0 0 0 alpha))))))) + container))) -- cgit v1.2.3