changed the constants format and added debug mode
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
-- Crates are the main thing so here we go
|
-- Crates are the main thing so here we go
|
||||||
local Timer = require('deps.knife.timer')
|
local Timer = require('deps.knife.timer')
|
||||||
|
|
||||||
local CONST_ITERATIONS_RESOLVE = .01
|
ITERATIONS_RESOLVE = .01
|
||||||
local CONST_TIME_TO_RELOAD = .4
|
TIME_TO_RELOAD = .4
|
||||||
|
|
||||||
local Crates = {
|
local Crates = {
|
||||||
world = nil,
|
world = nil,
|
||||||
@@ -30,7 +30,7 @@ function Crate.new(world, x, y)
|
|||||||
contact:setEnabled(false)
|
contact:setEnabled(false)
|
||||||
object.contact.x, object.contact.y = contact:getPositions()
|
object.contact.x, object.contact.y = contact:getPositions()
|
||||||
object.attached = true
|
object.attached = true
|
||||||
Timer.after(CONST_ITERATIONS_RESOLVE, function ()
|
Timer.after(ITERATIONS_RESOLVE, function ()
|
||||||
object.joint = Crates.world:addJoint('revolute', Crates.player.collider, object.collider, object.contact.x, object.contact.y, true)
|
object.joint = Crates.world:addJoint('revolute', Crates.player.collider, object.collider, object.contact.x, object.contact.y, true)
|
||||||
table.insert(Crates.attached, object)
|
table.insert(Crates.attached, object)
|
||||||
end)
|
end)
|
||||||
@@ -61,7 +61,7 @@ end
|
|||||||
|
|
||||||
function Crates:detach(key)
|
function Crates:detach(key)
|
||||||
self.attached[key].joint._joint:destroy()
|
self.attached[key].joint._joint:destroy()
|
||||||
Timer.after(CONST_TIME_TO_RELOAD, function ()
|
Timer.after(TIME_TO_RELOAD, function ()
|
||||||
self.attached[key].attached = false
|
self.attached[key].attached = false
|
||||||
table.remove(self.attached, key)
|
table.remove(self.attached, key)
|
||||||
end)
|
end)
|
||||||
|
|||||||
23
main.lua
23
main.lua
@@ -6,8 +6,10 @@ assets = require('deps.cargo').init('data')
|
|||||||
-- my own libs
|
-- my own libs
|
||||||
crates = require('crate')
|
crates = require('crate')
|
||||||
|
|
||||||
local CONST_GRAVITY = 512
|
DEBUG_MODE = true
|
||||||
local CONST_SIDES = {
|
|
||||||
|
GRAVITY = 512
|
||||||
|
SIDES = {
|
||||||
LEFT = {
|
LEFT = {
|
||||||
10, 10, 200, 10, 200, 500, 10, 500
|
10, 10, 200, 10, 200, 500, 10, 500
|
||||||
},
|
},
|
||||||
@@ -40,14 +42,15 @@ local velocity = {0, 0}
|
|||||||
local current = { }
|
local current = { }
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
love.window.setMode(512, 512)
|
if DEBUG_MODE then love.window.setMode(1024, 900)
|
||||||
|
else love.window.setMode(512, 512) end
|
||||||
|
|
||||||
world = Physics(0, 0)
|
world = Physics(0, 0)
|
||||||
world:addClass('Player')
|
world:addClass('Player')
|
||||||
world:addClass('Side')
|
world:addClass('Side')
|
||||||
world:addClass('Crate')
|
world:addClass('Crate')
|
||||||
side.left = world:addChain(true, CONST_SIDES.LEFT):setClass('Side')
|
side.left = world:addChain(true, SIDES.LEFT):setClass('Side')
|
||||||
side.right = world:addChain(true, CONST_SIDES.RIGHT):setClass('Side')
|
side.right = world:addChain(true, SIDES.RIGHT):setClass('Side')
|
||||||
magnet.collider = world:addRectangle(50, 50, magnet.w, magnet.h):setClass('Player')
|
magnet.collider = world:addRectangle(50, 50, magnet.w, magnet.h):setClass('Player')
|
||||||
magnet.collider:setRestitution(0)
|
magnet.collider:setRestitution(0)
|
||||||
|
|
||||||
@@ -117,16 +120,18 @@ end
|
|||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
world:draw()
|
world:draw()
|
||||||
|
|
||||||
|
if DEBUG_MODE then love.graphics.print('DEBUG MODE IS ENABLED', 850, 10) end
|
||||||
end
|
end
|
||||||
|
|
||||||
function mirrorCollider(collider, side)
|
function mirrorCollider(collider, side)
|
||||||
current.x, current.y = collider:getPosition()
|
current.x, current.y = collider:getPosition()
|
||||||
if side == 'LEFT' then
|
if side == 'LEFT' then
|
||||||
current.x = current.x - CONST_SIDES.LEFT[1]
|
current.x = current.x - SIDES.LEFT[1]
|
||||||
current.x = CONST_SIDES.RIGHT[1] + CONST_SIDES.WIDTH - current.x
|
current.x = SIDES.RIGHT[1] + SIDES.WIDTH - current.x
|
||||||
else
|
else
|
||||||
current.x = current.x - CONST_SIDES.RIGHT[1]
|
current.x = current.x - SIDES.RIGHT[1]
|
||||||
current.x = CONST_SIDES.LEFT[1] + CONST_SIDES.WIDTH - current.x
|
current.x = SIDES.LEFT[1] + SIDES.WIDTH - current.x
|
||||||
end
|
end
|
||||||
collider:setPosition(current.x, current.y)
|
collider:setPosition(current.x, current.y)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user