diff options
author | equa <equaa@protonmail.com> | 2021-04-22 14:23:39 -0500 |
---|---|---|
committer | equa <equaa@protonmail.com> | 2021-04-22 14:23:39 -0500 |
commit | d699b9a38da59bc32982db0c8a69c02cd595cdbc (patch) | |
tree | 37eba087eee569be5dca97bad25f29213df1f22b | |
parent | 3c98f936af7754e9deb4912e54ec12a3df9b5938 (diff) |
better? bullet rendering
-rw-r--r-- | lib/bullet.fnl | 11 | ||||
-rw-r--r-- | lib/player.fnl | 10 |
2 files changed, 14 insertions, 7 deletions
diff --git a/lib/bullet.fnl b/lib/bullet.fnl index d7f1b62..0fe1737 100644 --- a/lib/bullet.fnl +++ b/lib/bullet.fnl @@ -3,18 +3,19 @@ (local cell (require :lib.cell)) (local cells (require :lib.cells)) -(fn init [self pos vel] +(fn init [self pos vel dir] (setmetatable {entity.position pos entity.velocity vel - entity.duration 120} + entity.duration 120 + :direction dir} self)) (fn draw [self game id] (love.graphics.setColor 1 1 1 (/ (entity.duration self) 120)) - (love.graphics.setLineWidth 0.3) + (love.graphics.setLineWidth 0.2) (love.graphics.line 0 0 - (. self entity.velocity :x) - (. self entity.velocity :y))) + (* (math.cos self.direction) (vec.mag (. self entity.velocity))) + (* (math.sin self.direction) (vec.mag (. self entity.velocity))))) (fn collide [self game id x y] (when (> (cell.aliveness (. game.grid x y)) 0) diff --git a/lib/player.fnl b/lib/player.fnl index 1b10b51..4693d2e 100644 --- a/lib/player.fnl +++ b/lib/player.fnl @@ -38,12 +38,18 @@ bullet (vec.clone (entity.position self)) {:x (+ v.x (* (math.cos self.direction) 0.6)) - :y (+ v.y (* (math.sin self.direction) 0.6))})))) + :y (+ v.y (* (math.sin self.direction) 0.6))} + self.direction)))) (fn draw [self game id] (love.graphics.setColor 1 1 1) (love.graphics.rotate self.direction) - (love.graphics.polygon :fill -0.6 -0.4 0.6 0 -0.6 0.4)) + (love.graphics.polygon :fill -0.6 -0.4 0.6 0 -0.6 0.4) + (love.graphics.setLineWidth 0.1) + ;; (love.graphics.setColor 1 1 1 0.4) + ;; (love.graphics.arc :line :open 0 0 1.5 -0.3 0.3 13) + ;; (love.graphics.line 1.4 0 1.6 0) + (love.graphics.circle :fill 0.9 0 0.1)) (fn collide [self game id x y] (tset game.entities id nil) |