integrated sprites
This commit is contained in:
38
crate.lua
38
crate.lua
@@ -2,6 +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 utils = require('utils')
|
||||||
|
|
||||||
ITERATIONS_RESOLVE = .01
|
ITERATIONS_RESOLVE = .01
|
||||||
TIME_TO_RELOAD = .4
|
TIME_TO_RELOAD = .4
|
||||||
|
|
||||||
@@ -16,10 +18,27 @@ local Crate = { }
|
|||||||
|
|
||||||
local curContact = nil
|
local curContact = nil
|
||||||
|
|
||||||
function Crate.new(world, x, y)
|
function Crate.new(world, x, y, size)
|
||||||
local object = {
|
local object = { }
|
||||||
collider = world:addRectangle(x, y, 20, 20)
|
object.size = {
|
||||||
|
w = 0,
|
||||||
|
h = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if size == 'small' then
|
||||||
|
object.size.w, object.size.h = assets.sprites.crates.small:getWidth(), assets.sprites.crates.small:getHeight()
|
||||||
|
object.img = assets.sprites.crates.small
|
||||||
|
elseif size == 'medium' then
|
||||||
|
object.size.w, object.size.h = assets.sprites.crates.medium:getWidth(), assets.sprites.crates.medium:getHeight()
|
||||||
|
object.img = assets.sprites.crates.medium
|
||||||
|
elseif size == 'large' then
|
||||||
|
object.size.w, object.size.h = assets.sprites.crates.large:getWidth(), assets.sprites.crates.large:getHeight()
|
||||||
|
object.img = assets.sprites.crates.large
|
||||||
|
end
|
||||||
|
|
||||||
|
local center = utils.getCenterByXY(x, y, object.size.w, object.size.h)
|
||||||
|
|
||||||
|
object.collider = world:addRectangle(x, y, object.size.w, object.size.h)
|
||||||
object.collider:setClass('Crate')
|
object.collider:setClass('Crate')
|
||||||
object.attached = false
|
object.attached = false
|
||||||
object.contact = { }
|
object.contact = { }
|
||||||
@@ -47,14 +66,23 @@ function Crates:init(world, player)
|
|||||||
self.player = player
|
self.player = player
|
||||||
end
|
end
|
||||||
|
|
||||||
function Crates:spawn(x, y)
|
function Crates:spawn(x, y, size)
|
||||||
table.insert(self.list, Crate.new(self.world, x, y))
|
table.insert(self.list, Crate.new(self.world, x, y, size))
|
||||||
end
|
end
|
||||||
|
|
||||||
function Crates:update(dt)
|
function Crates:update(dt)
|
||||||
Timer.update(dt)
|
Timer.update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Crates:draw()
|
||||||
|
local pos = {x = 0, y = 0, r = 0}
|
||||||
|
for key in pairs(self.list) do
|
||||||
|
pos.x, pos.y = self.list[key].collider:getPosition()
|
||||||
|
pos.r = self.list[key].collider:getAngle()
|
||||||
|
love.graphics.draw(self.list[key].img, pos.x, pos.y, pos.r, 1, 1, self.list[key].size.w/2, self.list[key].size.h/2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Crates:getAttached()
|
function Crates:getAttached()
|
||||||
return self.attached
|
return self.attached
|
||||||
end
|
end
|
||||||
|
|||||||
8
game.lua
8
game.lua
@@ -99,8 +99,8 @@ function Chu.new(x, y, debug)
|
|||||||
input:bind(love.keyboard.getKeyFromScancode('lshift'), 'detach')
|
input:bind(love.keyboard.getKeyFromScancode('lshift'), 'detach')
|
||||||
|
|
||||||
crates:init(world, magnet)
|
crates:init(world, magnet)
|
||||||
crates:spawn(x + 120, y + 400)
|
crates:spawn(x + 120, y + 400, 'small')
|
||||||
crates:spawn(x + 150, y + 400)
|
crates:spawn(x + 150, y + 400, 'medium')
|
||||||
|
|
||||||
return setmetatable(obj, {
|
return setmetatable(obj, {
|
||||||
__index = Chu
|
__index = Chu
|
||||||
@@ -168,7 +168,9 @@ function Chu:draw()
|
|||||||
otherPosX, otherPosY = magnet.collider:getPosition()
|
otherPosX, otherPosY = magnet.collider:getPosition()
|
||||||
love.graphics.draw(assets.sprites.magnet, otherPosX, otherPosY, magnet.collider:getAngle(), 1, 1, magnet.size.width/2, magnet.size.height/2)
|
love.graphics.draw(assets.sprites.magnet, otherPosX, otherPosY, magnet.collider:getAngle(), 1, 1, magnet.size.width/2, magnet.size.height/2)
|
||||||
|
|
||||||
--world:draw()
|
crates:draw()
|
||||||
|
|
||||||
|
world:draw()
|
||||||
|
|
||||||
if self.debug then
|
if self.debug then
|
||||||
love.graphics.setColor(255, 0, 0, .5)
|
love.graphics.setColor(255, 0, 0, .5)
|
||||||
|
|||||||
Reference in New Issue
Block a user