25 lines
782 B
Fennel
25 lines
782 B
Fennel
(local util (require :lib.util))
|
|
(local {: vec* : dir-from-key} (util.require :game.helpers))
|
|
(local rules (require :game.rules))
|
|
(local Object (require :core.object))
|
|
|
|
(local Entity (Object:extend))
|
|
(fn Entity.new [self x y]
|
|
(set self.x x)
|
|
(set self.y y)
|
|
(set self.velocity [0 0]))
|
|
(fn Entity.draw [self]
|
|
(when (= self.color nil)
|
|
(set self.color [(math.random) (math.random) (math.random)]))
|
|
(love.graphics.setColor (table.unpack self.color))
|
|
(love.graphics.circle :fill self.x self.y 16))
|
|
(fn Entity.move [self [dx dy]]
|
|
(set self.velocity [dx dy])
|
|
(set self.x (rules.collide :x self dx))
|
|
(set self.y (rules.collide :y self dy)))
|
|
(fn Entity.update [self dt]
|
|
(self:move (vec* (dir-from-key self.keymap) (* self.speed dt))))
|
|
(set Entity.speed 64)
|
|
|
|
Entity
|