added the crates and the crate object plus making them joint

This commit is contained in:
2021-05-08 17:25:31 +02:00
parent fba48548b7
commit 686f085f5b
2 changed files with 75 additions and 3 deletions

View File

@@ -3,6 +3,9 @@ Boipus = require('deps.boipushy')
Physics = require('deps.physics')
assets = require('deps.cargo').init('data')
-- my own libs
crates = require('crate')
local CONST_GRAVITY = 512
local CONST_SIDES = {
LEFT = {
@@ -22,8 +25,6 @@ local player = {
}
local magnet = {
x = 50,
y = 50,
w = 50,
h = 50,
collider = nil,
@@ -44,9 +45,10 @@ function love.load()
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')
magnet.collider = world:addRectangle(magnet.x, magnet.y, magnet.w, magnet.h):setClass('Player')
magnet.collider = world:addRectangle(50, 50, magnet.w, magnet.h):setClass('Player')
magnet.collider:setRestitution(0)
input = Boipus()
@@ -58,6 +60,10 @@ function love.load()
input:bind(love.keyboard.getKeyFromScancode('s'), 'moveDown')
input:bind(love.keyboard.getKeyFromScancode('space'), 'switch')
crates:init(world, magnet)
crates:spawn(120, 400)
crates:spawn(150, 400)
-- Gamepad
--[[input:bind('dpup', 'moveUp')
input:bind('dpleft', 'moveLeft')
@@ -67,6 +73,7 @@ end
function love.update(dt)
world:update(dt)
crates:update(dt)
--[[ if input:down('moveUp') then magnet.collider:applyLinearImpulse(0, -player.maxSpeed.y) end
if input:down('moveLeft') then magnet.collider:applyLinearImpulse(-player.maxSpeed.x, 0) end