changed the constants format and added debug mode

This commit is contained in:
2021-05-09 15:18:51 +02:00
parent 55f0d2f0da
commit 9be6801ba1
2 changed files with 18 additions and 13 deletions

View File

@@ -2,8 +2,8 @@
-- Crates are the main thing so here we go
local Timer = require('deps.knife.timer')
local CONST_ITERATIONS_RESOLVE = .01
local CONST_TIME_TO_RELOAD = .4
ITERATIONS_RESOLVE = .01
TIME_TO_RELOAD = .4
local Crates = {
world = nil,
@@ -30,7 +30,7 @@ function Crate.new(world, x, y)
contact:setEnabled(false)
object.contact.x, object.contact.y = contact:getPositions()
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)
table.insert(Crates.attached, object)
end)
@@ -61,7 +61,7 @@ end
function Crates:detach(key)
self.attached[key].joint._joint:destroy()
Timer.after(CONST_TIME_TO_RELOAD, function ()
Timer.after(TIME_TO_RELOAD, function ()
self.attached[key].attached = false
table.remove(self.attached, key)
end)

View File

@@ -6,8 +6,10 @@ assets = require('deps.cargo').init('data')
-- my own libs
crates = require('crate')
local CONST_GRAVITY = 512
local CONST_SIDES = {
DEBUG_MODE = true
GRAVITY = 512
SIDES = {
LEFT = {
10, 10, 200, 10, 200, 500, 10, 500
},
@@ -40,14 +42,15 @@ local velocity = {0, 0}
local current = { }
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:addClass('Player')
world:addClass('Side')
world:addClass('Crate')
side.left = world:addChain(true, CONST_SIDES.LEFT):setClass('Side')
side.right = world:addChain(true, CONST_SIDES.RIGHT):setClass('Side')
side.left = world:addChain(true, SIDES.LEFT):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:setRestitution(0)
@@ -117,16 +120,18 @@ end
function love.draw()
world:draw()
if DEBUG_MODE then love.graphics.print('DEBUG MODE IS ENABLED', 850, 10) end
end
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
current.x = current.x - SIDES.LEFT[1]
current.x = SIDES.RIGHT[1] + SIDES.WIDTH - current.x
else
current.x = current.x - CONST_SIDES.RIGHT[1]
current.x = CONST_SIDES.LEFT[1] + CONST_SIDES.WIDTH - current.x
current.x = current.x - SIDES.RIGHT[1]
current.x = SIDES.LEFT[1] + SIDES.WIDTH - current.x
end
collider:setPosition(current.x, current.y)
end