summary refs log tree commit diff
path: root/lib/game.fnl
diff options
context:
space:
mode:
authorequa <equaa@protonmail.com>2021-04-19 20:39:21 -0500
committerequa <equaa@protonmail.com>2021-04-19 20:39:21 -0500
commit00af64d4e503dd82abf4657ec6fd44b0a418adb2 (patch)
tree4e864337769f5ddd792db95be3bc761159748af4 /lib/game.fnl
parentca870dab91daee38b8d55ac6d2f2b4fd6959c6ac (diff)
cool bullets
Diffstat (limited to 'lib/game.fnl')
-rw-r--r--lib/game.fnl18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/game.fnl b/lib/game.fnl
index b75a254..3f99550 100644
--- a/lib/game.fnl
+++ b/lib/game.fnl
@@ -51,7 +51,9 @@
                   :player
                   {:up (love.keyboard.isDown :up)
                    :right (love.keyboard.isDown :right)
-                   :left (love.keyboard.isDown :left)}))
+                   :left (love.keyboard.isDown :left)
+                   :shoot (love.keyboard.isDown :z)
+                   }))
   ;; entities
   (each [id e (pairs self.entities)]
     (tset e entity.position (vec.wrap
@@ -62,7 +64,10 @@
           t (. self.grid x y)]
       (when t
         (entity.collide e self id x y)))
-    )
+    (when (entity.duration e)
+      (tset e entity.duration (- (entity.duration e) 1))
+      (if (= (entity.duration e) 0)
+          (tset self.entities id nil))))
   )
 
 (fn id [x] x)
@@ -128,7 +133,10 @@
     (each [id v (pairs self.entities)]
       (love.graphics.push)
       (let [pos (entity.position v)
-            render-pos (vec.lerp camera-a camera-b display-a display-b pos)]
+            render-pos (vec.lerp camera-a camera-b display-a display-b
+                                 (vec.add camera-a
+                                          (vec.wrap (vec.sub pos camera-a)
+                                                    (vec.sub camera-b camera-a))))]
         (love.graphics.translate render-pos.x render-pos.y)
         (love.graphics.scale cell-box.x
                              cell-box.y))
@@ -172,9 +180,9 @@
      :rate 6
      :entities {:player (entity.init player {:x 32 :y 32})}
      :grid (new-grid width height #(if (= (math.random 6) 1)
-                                (if (> $1 34)
+                                (if (> $1 44)
                                     (cell.init cells.life)
-                                    (< $1 00)
+                                    (< $1 10)
                                     (cell.init cells.brain)
                                     nil)
                                 nil))