summary refs log tree commit diff
path: root/lib/bullet.fnl
blob: 0fe17379bfc3bebf452e415032051d501b75f368 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(local entity (require :lib.entity))
(local vec (require :lib.vec))
(local cell (require :lib.cell))
(local cells (require :lib.cells))

(fn init [self pos vel dir]
  (setmetatable {entity.position pos
                 entity.velocity vel
                 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.2)
  (love.graphics.line 0 0
                      (* (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)
    (tset game.entities id nil)
    ;; TODO: less boom-y thing?
    (tset game.grid x y (cell.init cells.boom (/ (entity.duration self) 180)))))

{entity.init init entity.draw draw entity.collide collide}