Compare commits

..

No commits in common. "eb7ce44fa1084c130ea6039a0b46f04c42652b07" and "5cbd3385c8eae4563f0719624b5ca191d962ceed" have entirely different histories.

4 changed files with 5 additions and 30 deletions

View file

@ -16,14 +16,9 @@ end
---Updates area
---@param dt number
function Area:update(dt)
for i = #self.game_objects, 1, -1 do
local game_object = self.game_objects[i]
for i, game_object in ipairs(self.game_objects) do
if game_object:isDead() then table.remove(self.game_objects, i) end
game_object:update(dt)
if game_object:isDead() then
table.remove(self.game_objects, i)
end
end
end
@ -32,18 +27,6 @@ function Area:draw()
for _, game_object in ipairs(self.game_objects) do game_object:draw() end
end
---Destroys area
function Area:destroy()
for i = #self.game_objects, 1, -1 do
local game_object = self.game_objects[i]
game_object:kill()
table.remove(self.game_objects, i)
end
self.game_objects = {}
if self.world then self.world = nil end
end
---Adds game object to area
---@param game_object_type string name of game object's class
---@param x number|nil horizontal position
@ -55,9 +38,9 @@ function Area:addGameObject(game_object_type, x, y, opts)
return game_object
end
---Initializes HC collision manager as a world
---Initializes HC physics as a world
---@param cell_size number|nil
function Area:addCollisionManager(cell_size)
function Area:addPhysicsWorld(cell_size)
self.world = HC(cell_size or 100)
end

View file

@ -18,7 +18,6 @@ function GameObject:new(area, x, y, opts)
self.id = UUID()
self.dead = false
self.timer = Timer()
self.collider = nil
end
---Updates game object
@ -37,10 +36,6 @@ function GameObject:destroy()
self.timer:clear() -- cancel all tweens/after/every
self.timer = nil
end
if self.collider then
self.area.world:remove(self.collider)
self.collider = nil
end
self.dead = true
end

View file

@ -25,7 +25,6 @@ end
function Player:update(dt)
Player.super.update(self, dt)
if self:isDead() then return end
-- controls
if input:down('left') then self.r = self.r - self.rv*dt end
@ -42,8 +41,6 @@ function Player:update(dt)
-- move collision area
self.collider:moveTo(self.x, self.y)
if input:pressed('f2') then self:kill() end
end
function Player:draw()

View file

@ -3,7 +3,7 @@ local Stage = Room:extend()
function Stage:new()
Stage.super.new(self)
self.area:addCollisionManager()
self.area:addPhysicsWorld()
self.area:addGameObject('Player', gw/2, gh/2)
end