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/death.fnl | 35 ----------------------------------- lib/game.fnl | 47 ++++++++++++++++++++++++++++++++++++++++------- lib/main.fnl | 3 ++- lib/transition.fnl | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/translation.fnl | 25 +++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 43 deletions(-) delete mode 100644 lib/death.fnl create mode 100644 lib/transition.fnl create mode 100644 lib/translation.fnl diff --git a/lib/death.fnl b/lib/death.fnl deleted file mode 100644 index 8456827..0000000 --- a/lib/death.fnl +++ /dev/null @@ -1,35 +0,0 @@ -(local state (require :lib.state)) -(local font (require :lib.font)) - -(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 "moli a" (- (/ width 2) 500) (- (/ height 2) 64) 1000 :center) - (love.graphics.setFont font.small) - (love.graphics.printf "nena Z li open e musi sin" (- (/ width 2) 500) (+ (/ height 2)) 1000 :center)) - -(fn update [self] - ;; TODO: actually update in case it returns something else - (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) (= key :z)) - (set self.transition true)) - ) - -(fn init [self present-state future-state] - (setmetatable - {: present-state - : future-state - :age 0} - self)) - -{state.draw draw state.init init state.update update state.keypressed keypressed} diff --git a/lib/game.fnl b/lib/game.fnl index 229f433..a0218b3 100644 --- a/lib/game.fnl +++ b/lib/game.fnl @@ -4,7 +4,7 @@ (local vec (require :lib.vec)) (local entity (require :lib.entity)) (local player (require :lib.player)) -(local death (require :lib.death)) +(local transition (require :lib.transition)) (local fv (require :fennel.view)) (fn lerp* [a b c d x] @@ -21,8 +21,11 @@ (fn update [self] ;; (set ship-pos.x (+ self.ship.x 0.02)) ;; (set ship-pos.y (+ self.ship.y 0.005)) + (var grid-alive? true) (set self.radius (lerp* 0 1 self.radius self.target-radius 0.3)) + (when (= self.tick 0) + (set grid-alive? false) (for [x 0 (- self.width 1)] (for [y 0 (- self.height 1)] (fn get [v] @@ -31,8 +34,10 @@ (% (+ v.y y) self.height))) (if (. self.grid x y) ;; check if alive - (tset self.grid-alt x y (cell.update (. self.grid x y) + (do + (tset self.grid-alt x y (cell.update (. self.grid x y) get)) + (set grid-alive? true)) ;; check for neighbors and then use one at random (do (var neighbors []) @@ -70,10 +75,29 @@ (if (= (entity.duration e) 0) (tset self.entities id nil)))) ;; TODO: we should do this for only the first death frame - (if (not self.entities.player) + (if self.pause + (do + (set self.pause nil) + (state.init transition + :pause + self + self)) + (not self.entities.player) ;; TODO: new game - (state.init death self ((. (getmetatable self) :inner-init) - (getmetatable self) 1 self)) + (state.init transition + :death + self + ((. (getmetatable self) :inner-init) + (getmetatable self) 1 self) + self.level) + (not grid-alive?) + (state.init transition + :win + self + ((. (getmetatable self) :inner-init) + (getmetatable self) (+ self.level 1) self) + self.level) + true nil)) (fn id [x] x) @@ -156,6 +180,8 @@ ;; (love.graphics.print :Gaming)) (fn keypressed [self key scancode repeat] + (when (= key "escape") + (set self.pause true)) (when (= key "=") (set self.target-radius (math.max @@ -185,7 +211,10 @@ :level level :tick 0 :rate 6 - :entities {:player (entity.init player {:x 31.5 :y 31.5})} + :ship-pos {:x 31.5 :y 31.5} + :entities (if (= level -1) + {} + {:player (entity.init player {:x 31.5 :y 31.5})}) :grid (new-grid width height #(if (= (math.random 6) 1) (if (> $1 44) (cell.init cells.life) @@ -197,7 +226,11 @@ } self))) +;; what the hell (fn init [self] - (self.inner-init self 1)) + (state.init transition + :menu + (self.inner-init self -1) + (self.inner-init self 1))) {: inner-init state.draw draw state.init init state.update update state.keypressed keypressed} diff --git a/lib/main.fnl b/lib/main.fnl index 9af1bb8..4a4de12 100644 --- a/lib/main.fnl +++ b/lib/main.fnl @@ -12,10 +12,11 @@ ;; TODO: ^ (local hotswap-modules [:lib.player + :lib.translation :lib.bullet :lib.cells :lib.game - :lib.death + :lib.transition :lib.main]) ;; the 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} diff --git a/lib/translation.fnl b/lib/translation.fnl new file mode 100644 index 0000000..ee19879 --- /dev/null +++ b/lib/translation.fnl @@ -0,0 +1,25 @@ +(local tp + {:death ["ike a" "sina moli lon musi nanpa %s\n\nnena Z li open e musi sin"] + :win ["pona a" "sina pini e musi nanpa %s\n\nnena Z li tawa musi kama!"] + :pause ["awen" "nena Z li open sin e musi"] + :menu ["soko" + "tan soweli nata\nhttps://equa.space/\n\nnena Z li open e musi\n\nmusi la\nnena ←↑→ li tawa e tomo\nnena Z li pana e kiwen seli"] + :number (fn [x] (string.gsub + (.. (string.rep "ale " (math.floor (/ x 100))) + (string.rep "mute " (math.floor (/ (% x 100) 20))) + (string.rep "luka " (math.floor (/ (% x 100) 5))) + (. [(if (= x 0) "ala" "") "wan" "tu" "tu wan" "tu tu"] + (+ 1 (% x 5)))) + "(.-)%s*$" + "%1"))}) + + +(local en + {:death ["ike a" "you died on level %s\n\npress Z to restart"] + :win ["pona a" "you beat level %s\n\npress Z to advance!"] + :pause ["pause" "press Z to continue"] + :menu ["soko" + "by soweli nata\nhttps://equa.space/\n\npress Z to start\n\ncontrols\nhold ←↑→ to move\npress Z to fire"] + :number tostring}) + +{: en : tp :text tp} -- cgit 1.3.0-6-gf8a5