From 00af64d4e503dd82abf4657ec6fd44b0a418adb2 Mon Sep 17 00:00:00 2001 From: equa Date: Mon, 19 Apr 2021 20:39:21 -0500 Subject: cool bullets --- lib/player.fnl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib/player.fnl') diff --git a/lib/player.fnl b/lib/player.fnl index 0633727..8e31a18 100644 --- a/lib/player.fnl +++ b/lib/player.fnl @@ -2,15 +2,19 @@ (local vec (require :lib.vec)) (local cell (require :lib.cell)) (local cells (require :lib.cells)) +(local bullet (require :lib.bullet)) (fn init [self pos] (setmetatable {entity.position pos entity.velocity {:x 0 :y 0} :target-spin 0 + :shot-age 0 :direction 0} self)) (fn steer [self game id controls] + (when (> self.shot-age 0) + (set self.shot-age (- self.shot-age 1))) ;; TODO: smooth turning (when controls.left (set self.target-spin (- self.target-spin 0.15))) @@ -24,7 +28,17 @@ (set v.x (+ v.x (* (math.cos self.direction) 0.02))) (set v.y (+ v.y (* (math.sin self.direction) 0.02))) (when (> (vec.mag v) 0.8) - (tset self entity.velocity (vec.mul v (/ 0.8 (vec.mag v))))))) + (tset self entity.velocity (vec.mul v (/ 0.8 (vec.mag v)))))) + (when (and controls.shoot (= self.shot-age 0)) + (set self.shot-age 10) + (local v (entity.velocity self)) + (table.insert + game.entities + (entity.init + bullet + (vec.clone (entity.position self)) + {:x (+ (* (math.cos self.direction) 0.6)) + :y (+ (* (math.sin self.direction) 0.6))})))) (fn draw [self game id] (love.graphics.setColor 1 1 1) -- cgit 1.3.0-6-gf8a5