From c9b60c569f2ad015f043667c44ff9f43d50ec2e5 Mon Sep 17 00:00:00 2001 From: equa Date: Tue, 20 Apr 2021 18:20:05 -0500 Subject: death screen --- lib/game.fnl | 60 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 25 deletions(-) (limited to 'lib/game.fnl') diff --git a/lib/game.fnl b/lib/game.fnl index 3f99550..229f433 100644 --- a/lib/game.fnl +++ b/lib/game.fnl @@ -4,6 +4,7 @@ (local vec (require :lib.vec)) (local entity (require :lib.entity)) (local player (require :lib.player)) +(local death (require :lib.death)) (local fv (require :fennel.view)) (fn lerp* [a b c d x] @@ -68,7 +69,12 @@ (tset e entity.duration (- (entity.duration e) 1)) (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) + ;; TODO: new game + (state.init death self ((. (getmetatable self) :inner-init) + (getmetatable self) 1 self)) + nil)) (fn id [x] x) @@ -165,29 +171,33 @@ self.max-radius (+ self.target-radius 4)))))) +(fn inner-init [self level past] + (let [past (or past {}) + width 64 + height 64] + (setmetatable + {:width width + :height height + :radius (or past.radius 32) + :target-radius (or past.radius 32) + :max-radius (/ (math.min height width) 2) + :min-radius 16 + :level level + :tick 0 + :rate 6 + :entities {: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) + (< $1 10) + (cell.init cells.brain) + nil) + nil)) + :grid-alt (new-grid width height #nil) + } + self))) + (fn init [self] - (local width 64) - (local height 64) - (setmetatable - {:width width - :height height - :ship {:x 31 :y 31} - :radius 32 - :target-radius 32 - :max-radius (/ (math.min height width) 2) - :min-radius 16 - :tick 0 - :rate 6 - :entities {:player (entity.init player {:x 32 :y 32})} - :grid (new-grid width height #(if (= (math.random 6) 1) - (if (> $1 44) - (cell.init cells.life) - (< $1 10) - (cell.init cells.brain) - nil) - nil)) - :grid-alt (new-grid width height #nil) - } - self)) + (self.inner-init self 1)) -{state.draw draw state.init init state.update update state.keypressed keypressed} +{: inner-init state.draw draw state.init init state.update update state.keypressed keypressed} -- cgit 1.3.0-6-gf8a5