put the utils stuff in game
This commit is contained in:
50
game.lua
50
game.lua
@@ -5,6 +5,7 @@ Physics = require('deps.physics')
|
||||
|
||||
-- my own libs
|
||||
crates = require('crate')
|
||||
utils = require('utils')
|
||||
|
||||
GRAVITY = 512
|
||||
PLAN_SIZE = {
|
||||
@@ -22,8 +23,6 @@ local player = {
|
||||
}
|
||||
|
||||
local magnet = {
|
||||
w = 50,
|
||||
h = 50,
|
||||
collider = nil,
|
||||
side = 'LEFT'
|
||||
}
|
||||
@@ -53,27 +52,22 @@ function Chu.new(x, y, debug)
|
||||
x - PLAN_SIZE.marginX, y + PLAN_SIZE.h + PLAN_SIZE.marginY
|
||||
}):setClass('GamePlan')
|
||||
|
||||
obj.pier = world:addRectangle(x + 80 - (PLAN_SIZE.marginX/2), y + PLAN_SIZE.h - 64, 160 + PLAN_SIZE.marginX, 128)
|
||||
obj.pier:setType('static')
|
||||
local pierWidth, pierHeight = assets.sprites.level.pier:getWidth(), assets.sprites.level.pier:getHeight()
|
||||
obj.pier = utils.spawnStaticRectangleBySize(world, x - PLAN_SIZE.marginX, y + PLAN_SIZE.h - pierHeight, pierWidth + PLAN_SIZE.marginX, pierHeight)
|
||||
|
||||
--[[obj.crane = world:addChain(true, {
|
||||
x + 36, y + 80,
|
||||
x + 36 + assets.sprites.crane:getWidth(), y + 80,
|
||||
x + 36 + assets.sprites.crane:getWidth(), y + 80 + assets.sprites.crane:getHeight(),
|
||||
x + 36, y + 80 + assets.sprites.crane:getHeight()
|
||||
}):setClass('Crane')
|
||||
local craneWidth, craneHeight = assets.sprites.crane:getWidth(), assets.sprites.crane:getHeight()
|
||||
|
||||
obj.moving = world:addRectangle(x + (36/2) + 1, y + 40 + 1, assets.sprites.movingstuff:getWidth() - 2, assets.sprites.movingstuff:getHeight() - 2)
|
||||
]]--
|
||||
obj.crane = {
|
||||
top = utils.spawnStaticRectangleBySize(world, x + 36, y + 80, craneWidth, 6),
|
||||
left = utils.spawnStaticRectangleBySize(world, x + 36, y + 86, 6, craneHeight - 12),
|
||||
right = utils.spawnStaticRectangleBySize(world, x + 30 + craneWidth, y + 86, 6, craneHeight - 12),
|
||||
bottom = utils.spawnStaticRectangleBySize(world, x + 36, y + 74 + craneHeight, craneWidth, 6)
|
||||
}
|
||||
|
||||
obj.crane = {}
|
||||
obj.crane.top = world:addRectangle(x + (assets.sprites.crane:getWidth()/2) + (18*2), y + 84, assets.sprites.crane:getWidth(), 6)
|
||||
obj.crane.top:setType('static')
|
||||
obj.crane.left = world:addRectangle(x + 36, y + 87, 6, assets.sprites.crane:getHeight() - 12)
|
||||
obj.crane.left:setType('static')
|
||||
|
||||
magnet.collider = world:addRectangle(x + 50, y + 50, magnet.w, magnet.h):setClass('Player')
|
||||
magnet.collider:setRestitution(0)
|
||||
local magnetWidth, magnetHeight = assets.sprites.movingstuff:getWidth(), assets.sprites.movingstuff:getHeight()
|
||||
local center = utils.getCenterByXY(x + 43, y + 87, magnetWidth, magnetHeight)
|
||||
magnet.collider = world:addRectangle(center.x, center.y, magnetWidth, magnetHeight):setClass('Player')
|
||||
--magnet.collider:setRestitution(0)
|
||||
|
||||
input = Boipus()
|
||||
-- Controls
|
||||
@@ -98,22 +92,6 @@ function Chu:update(dt)
|
||||
world:update(dt)
|
||||
crates:update(dt)
|
||||
|
||||
-- this is temp, ofc, it's ugly af
|
||||
--[[if input:pressed('switch') then
|
||||
velocity = {0, 0}
|
||||
|
||||
-- first, let's take care of the attached crates
|
||||
for key in pairs(crates:getAttached()) do
|
||||
mirrorCollider(crates.attached[key].collider, magnet.side)
|
||||
end
|
||||
|
||||
mirrorCollider(magnet.collider, magnet.side)
|
||||
|
||||
if magnet.side == 'LEFT' then
|
||||
magnet.side = 'RIGHT'
|
||||
else
|
||||
magnet.side = 'LEFT'
|
||||
end]]--
|
||||
if input:pressed('detach') then
|
||||
velocity = {0, 0}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user