summaryrefslogtreecommitdiff
path: root/obj.lua
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2022-12-20 17:21:59 -0600
committerthe lemons <citrons@mondecitronne.com>2022-12-21 00:12:16 -0600
commit15b1b3127e636a8a63ff9cdb11dbac68f5218ffe (patch)
treeaf710fe75c1081e2d9f119ae3280d2f662eea859 /obj.lua
parent94f7fc0d3e410a7c7dc6f6cffe0ed87238608391 (diff)
objects have velocity
Diffstat (limited to 'obj.lua')
-rw-r--r--obj.lua19
1 files changed, 15 insertions, 4 deletions
diff --git a/obj.lua b/obj.lua
index adb9a3a..ae8ff59 100644
--- a/obj.lua
+++ b/obj.lua
@@ -1,8 +1,10 @@
local world = require "world"
+local pi = math.pi
local obj = {}
local types = {}
+
function obj.load_types()
for _, f in ipairs(love.filesystem.getDirectoryItems "objects") do
local ts = assert(love.filesystem.load("objects/"..f))()
@@ -12,10 +14,11 @@ function obj.load_types()
end
end
-function obj.new(type, pos, ...)
+function obj.new(type, pos, data, ...)
world.last_id = world.last_id + 1
local o = setmetatable(
- {id = world.last_id, data = {pos = pos}, type = type}, obj)
+ {id = world.last_id, data = data or {}, type = type}, obj)
+ o.data.pos = pos
o:init(...)
return o
end
@@ -51,6 +54,14 @@ function obj:tick(...)
chunk.objects[self.id] = self
self.chunk = chunk
end
+ if self.data.vel then
+ local vx, vy = unpack(self.data.vel)
+ self.data.pos[1] = self.data.pos[1] + vx
+ self.data.pos[2] = self.data.pos[2] + vy
+ end
+ if self.data.avel then
+ self.data.angle = (self.data.angle or 0) + self.data.avel / pi
+ end
return self:overload("tick", ...)
end
@@ -70,10 +81,10 @@ function obj:init(...)
return self:overload("init", ...)
end
-function obj:unload()
+function obj:remove()
self.chunk.objects[self.id] = nil
world.objects[self.id] = nil
- return self:overload "unload"
+ return self:overload "remove"
end
return obj