integrated the mirroring part
This commit is contained in:
@@ -6,7 +6,8 @@ local CONST_ITERATIONS_RESOLVE = 1
|
|||||||
local Crates = {
|
local Crates = {
|
||||||
world = nil,
|
world = nil,
|
||||||
player = nil,
|
player = nil,
|
||||||
list = { }
|
list = { },
|
||||||
|
attached = { }
|
||||||
}
|
}
|
||||||
|
|
||||||
local Crate = { }
|
local Crate = { }
|
||||||
@@ -55,11 +56,16 @@ function Crates:update(dt)
|
|||||||
curContact = self.list[key].contact
|
curContact = self.list[key].contact
|
||||||
self.world:addJoint('revolute', self.player.collider, self.list[key].collider, curContact.x, curContact.y, true)
|
self.world:addJoint('revolute', self.player.collider, self.list[key].collider, curContact.x, curContact.y, true)
|
||||||
self.list[key].resolver = nil
|
self.list[key].resolver = nil
|
||||||
|
table.insert(self.attached, self.list[key])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Crates:getAttached()
|
||||||
|
return self.attached
|
||||||
|
end
|
||||||
|
|
||||||
return setmetatable(Crates, {
|
return setmetatable(Crates, {
|
||||||
__call = function(_, ...) return new(...) end
|
__call = function(_, ...) return new(...) end
|
||||||
})
|
})
|
||||||
|
|||||||
21
main.lua
21
main.lua
@@ -39,6 +39,8 @@ local side = {
|
|||||||
local velocity = {0, 0}
|
local velocity = {0, 0}
|
||||||
local current = { }
|
local current = { }
|
||||||
|
|
||||||
|
local tempAttached = nil
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
love.window.setMode(512, 512)
|
love.window.setMode(512, 512)
|
||||||
|
|
||||||
@@ -83,6 +85,25 @@ function love.update(dt)
|
|||||||
-- this is temp, ofc, it's ugly af
|
-- this is temp, ofc, it's ugly af
|
||||||
if input:pressed('switch') then
|
if input:pressed('switch') then
|
||||||
velocity = {0, 0}
|
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()
|
current.x, current.y = magnet.collider:getPosition()
|
||||||
|
|
||||||
-- i want a relative x position, for easier use, so first
|
-- i want a relative x position, for easier use, so first
|
||||||
|
|||||||
Reference in New Issue
Block a user