cleaned the code a bit
This commit is contained in:
40
main.lua
40
main.lua
@@ -41,6 +41,18 @@ local current = { }
|
|||||||
|
|
||||||
local tempAttached = nil
|
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()
|
function love.load()
|
||||||
love.window.setMode(512, 512)
|
love.window.setMode(512, 512)
|
||||||
|
|
||||||
@@ -88,40 +100,16 @@ function love.update(dt)
|
|||||||
|
|
||||||
-- first, let's take care of the attached crates
|
-- first, let's take care of the attached crates
|
||||||
for key in pairs(crates:getAttached()) do
|
for key in pairs(crates:getAttached()) do
|
||||||
current.x, current.y = crates.attached[key].collider:getPosition()
|
mirrorCollider(crates.attached[key].collider, magnet.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
|
|
||||||
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
|
end
|
||||||
|
|
||||||
current.x, current.y = magnet.collider:getPosition()
|
mirrorCollider(magnet.collider, magnet.side)
|
||||||
|
|
||||||
-- 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
|
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'
|
magnet.side = 'RIGHT'
|
||||||
else
|
else
|
||||||
current.x = current.x - CONST_SIDES.RIGHT[1]
|
|
||||||
|
|
||||||
current.x = CONST_SIDES.LEFT[1] + CONST_SIDES.WIDTH - current.x
|
|
||||||
magnet.side = 'LEFT'
|
magnet.side = 'LEFT'
|
||||||
end
|
end
|
||||||
|
|
||||||
magnet.collider:setPosition(current.x, current.y)
|
|
||||||
else
|
else
|
||||||
if input:down('moveUp') or input:down('moveLeft') or input:down('moveRight') or input:down('moveDown') then
|
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
|
if input:down('moveUp') then velocity[2] = -player.maxSpeed.y
|
||||||
|
|||||||
Reference in New Issue
Block a user