From 5c4b1aba561c206744b3354478069677b3947e67 Mon Sep 17 00:00:00 2001 From: equa Date: Tue, 20 Apr 2021 22:13:13 -0500 Subject: death -> other paused/non-game screens --- lib/transition.fnl | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lib/transition.fnl (limited to 'lib/transition.fnl') diff --git a/lib/transition.fnl b/lib/transition.fnl new file mode 100644 index 0000000..376f123 --- /dev/null +++ b/lib/transition.fnl @@ -0,0 +1,53 @@ +(local state (require :lib.state)) +(local font (require :lib.font)) +(local translation (require :lib.translation)) + +(fn draw [self] + (local (width height) (love.graphics.getDimensions)) + (state.draw self.present-state) + ;; TODO: translation + (love.graphics.reset) + (love.graphics.setColor 0.8 0.8 0.8 (/ (math.max 0 (- self.age 30)) 10)) + (love.graphics.setFont font.big) + (love.graphics.printf (string.format + (. translation.text self.type 1) + (and self.level (translation.text.number self.level))) + (- (/ width 2) 500) + (- (/ height 2) 64) + 1000 + :center) + (love.graphics.setFont font.small) + (love.graphics.printf (string.format + (. translation.text self.type 2) + (and self.level (translation.text.number self.level))) + (- (/ width 2) 500) + (+ (/ height 2)) + 1000 + :center)) + +(fn update [self] + ;; TODO: actually update in case it returns something else + (when (not= self.type :pause) + (state.update self.present-state)) + (set self.age (math.min 40 (+ self.age 1))) + (if self.transition + self.future-state + nil)) + +(fn keypressed [self key scancode repeat] + (when (and (not repeat) (or (and (= self.type :pause) + (= key :escape)) + (= key :z))) + (set self.transition true)) + ) + +(fn init [self type present-state future-state level] + (setmetatable + {: type + : present-state + : level + : future-state + :age (if (or (= type :pause) (= type :menu)) 40 0)} + self)) + +{state.draw draw state.init init state.update update state.keypressed keypressed} -- cgit 1.3.0-6-gf8a5