integrated the mirroring part

This commit is contained in:
2021-05-08 17:33:00 +02:00
parent 686f085f5b
commit 050157a47e
2 changed files with 28 additions and 1 deletions

View File

@@ -6,7 +6,8 @@ local CONST_ITERATIONS_RESOLVE = 1
local Crates = {
world = nil,
player = nil,
list = { }
list = { },
attached = { }
}
local Crate = { }
@@ -55,11 +56,16 @@ function Crates:update(dt)
curContact = self.list[key].contact
self.world:addJoint('revolute', self.player.collider, self.list[key].collider, curContact.x, curContact.y, true)
self.list[key].resolver = nil
table.insert(self.attached, self.list[key])
end
end
end
end
function Crates:getAttached()
return self.attached
end
return setmetatable(Crates, {
__call = function(_, ...) return new(...) end
})

View File

@@ -39,6 +39,8 @@ local side = {
local velocity = {0, 0}
local current = { }
local tempAttached = nil
function love.load()
love.window.setMode(512, 512)
@@ -83,6 +85,25 @@ function love.update(dt)
-- this is temp, ofc, it's ugly af
if input:pressed('switch') then
velocity = {0, 0}
-- first, let's take care of the attached crates
for key in pairs(crates:getAttached()) do
current.x, current.y = crates.attached[key].collider:getPosition()
if magnet.side == 'LEFT' then
current.x = current.x - CONST_SIDES.LEFT[1]
-- then, we need to mirror it onto the other side
current.x = CONST_SIDES.RIGHT[1] + CONST_SIDES.WIDTH - current.x
else
current.x = current.x - CONST_SIDES.RIGHT[1]
current.x = CONST_SIDES.LEFT[1] + CONST_SIDES.WIDTH - current.x
end
crates.attached[key].collider:setPosition(current.x, current.y)
end
current.x, current.y = magnet.collider:getPosition()
-- i want a relative x position, for easier use, so first