objects.lua
· 626 B · Lua
Bruto
Playground
local player = Thing()
:has { t = 0, x = 0, y = 0, w = 32, h = 32 }
:is { "player", "solid" }
:when "dead"
:on_start(function(self)
self:broadcast "player died"
end)
:mimic "alive" "draw"
:when "alive"
:does "update" (function(self, dt)
self.t = self.t + dt
self.x = self.x + math.cos(self.t) * 100
self.y = self.y + math.sin(self.t) * 100
end):unless(function(self) return self.world.paused end)
:does "draw" (function(self)
love.graphics.rectangle("fill", self.x, self.y, self.w, self.h)
end)
:does "die" (function(self)
self:become "dead"
end)
1 | local player = Thing() |
2 | :has { t = 0, x = 0, y = 0, w = 32, h = 32 } |
3 | :is { "player", "solid" } |
4 | :when "dead" |
5 | :on_start(function(self) |
6 | self:broadcast "player died" |
7 | end) |
8 | :mimic "alive" "draw" |
9 | :when "alive" |
10 | :does "update" (function(self, dt) |
11 | self.t = self.t + dt |
12 | self.x = self.x + math.cos(self.t) * 100 |
13 | self.y = self.y + math.sin(self.t) * 100 |
14 | end):unless(function(self) return self.world.paused end) |
15 | :does "draw" (function(self) |
16 | love.graphics.rectangle("fill", self.x, self.y, self.w, self.h) |
17 | end) |
18 | :does "die" (function(self) |
19 | self:become "dead" |
20 | end) |