cleaned the code a bit

This commit is contained in:
2021-05-08 17:36:09 +02:00
parent 050157a47e
commit 7682b6d5f4

View File

@@ -41,6 +41,18 @@ local current = { }
local tempAttached = nil
function mirrorCollider(collider, side)
current.x, current.y = collider:getPosition()
if side == 'LEFT' then
current.x = current.x - CONST_SIDES.LEFT[1]
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
collider:setPosition(current.x, current.y)
end
function love.load()
love.window.setMode(512, 512)
@@ -88,40 +100,16 @@ function love.update(dt)
-- 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
mirrorCollider(crates.attached[key].collider, magnet.side)
end
crates.attached[key].collider:setPosition(current.x, current.y)
end
mirrorCollider(magnet.collider, magnet.side)
current.x, current.y = magnet.collider:getPosition()
-- i want a relative x position, for easier use, so first
-- let's substract the x position depending on the side
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
magnet.side = 'RIGHT'
else
current.x = current.x - CONST_SIDES.RIGHT[1]
current.x = CONST_SIDES.LEFT[1] + CONST_SIDES.WIDTH - current.x
magnet.side = 'LEFT'
end
magnet.collider:setPosition(current.x, current.y)
else
if input:down('moveUp') or input:down('moveLeft') or input:down('moveRight') or input:down('moveDown') then
if input:down('moveUp') then velocity[2] = -player.maxSpeed.y