summary refs log tree commit diff
path: root/lib/game.fnl
diff options
context:
space:
mode:
authorequa <equaa@protonmail.com>2021-04-22 22:18:58 -0500
committerequa <equaa@protonmail.com>2021-04-22 22:18:58 -0500
commit5473d5d303b55b06438d65c4b3abd2fc0b0f86fc (patch)
treedea5e968dd6097b30c7f78ce10a628a2cfa83dfd /lib/game.fnl
parentd699b9a38da59bc32982db0c8a69c02cd595cdbc (diff)
very messy music
Diffstat (limited to 'lib/game.fnl')
-rw-r--r--lib/game.fnl37
1 files changed, 27 insertions, 10 deletions
diff --git a/lib/game.fnl b/lib/game.fnl
index d07f58c..833de6b 100644
--- a/lib/game.fnl
+++ b/lib/game.fnl
@@ -6,6 +6,7 @@
 (local player (require :lib.player))
 (local transition (require :lib.transition))
 (local fv (require :fennel.view))
+(local music-state (require :lib.music-state))
 
 (fn lerp* [a b c d x]
   (+ c (* (/ (- x a) (- b a)) (- d c))))
@@ -19,6 +20,7 @@
   t)
 
 (fn update [self]
+  (set music-state.screen :game)
   ;; (set ship-pos.x (+ self.ship.x 0.02))
   ;; (set ship-pos.y (+ self.ship.y 0.005))
   (var grid-alive? true)
@@ -26,6 +28,8 @@
 
   (when (= self.tick 0)
     (set grid-alive? false)
+    (set music-state.fire 0)
+    (set music-state.alive 0)
     (for [x 0 (- self.width 1)]
       (for [y 0 (- self.height 1)]
         (fn get [v]
@@ -37,7 +41,8 @@
             (do
               (tset self.grid-alt x y (cell.update (. self.grid x y)
                                                  get))
-              (set grid-alive? true))
+              (set grid-alive? true)
+              (set music-state.alive (+ music-state.alive 1)))
             ;; check for neighbors and then use one at random
             (do
               (var neighbors [])
@@ -88,7 +93,7 @@
                   :death
                   self
                   ((. (getmetatable self) :inner-init)
-                   (getmetatable self) 1 self)
+                   (getmetatable self) (if (> self.level 0) 1 0) self)
                   self.level)
       (not grid-alive?)
       (state.init transition
@@ -204,6 +209,24 @@
              self.max-radius
              (+ self.target-radius 4))))))
 
+(fn make-level [level width height]
+  (if (= level 0)
+      (new-grid width height
+                #(if (or (and (= $2 61) (or (= $1 61) (= $1 62) (= $1 63)))
+                         (and (= $2 62) (= $1 61))
+                         (and (= $2 63) (= $1 62)))
+                     (cell.init cells.life)
+                     nil))
+      true
+      (new-grid width height
+                #(if (= (math.random 6) 1)
+                     (if (> $1 44)
+                         (cell.init cells.life)
+                         (< $1 10)
+                         (cell.init cells.brain)
+                         nil)
+                     nil))))
+
 (fn inner-init [self level past]
   (let [past (or past {})
         width 64
@@ -222,13 +245,7 @@
        :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)
-                                             (< $1 10)
-                                             (cell.init cells.brain)
-                                             nil)
-                                         nil))
+       :grid (make-level level width height)
        :grid-alt (new-grid width height #nil)
        }
       self)))
@@ -238,6 +255,6 @@
   (state.init transition
               :menu
               (self.inner-init self -1)
-              (self.inner-init self 1)))
+              (self.inner-init self 0)))
 
 {: inner-init state.draw draw state.init init state.update update state.keypressed keypressed}