physics collisions
This commit is contained in:
parent
74544db5d3
commit
7b30c93128
30
main.lua
30
main.lua
@ -1,6 +1,6 @@
|
|||||||
--[[ LOVE STUFF ]]
|
--[[ LOVE STUFF ]]
|
||||||
function love.load()
|
function love.load()
|
||||||
|
myWorld = love.physics.newWorld(0, 100)
|
||||||
|
|
||||||
sprites = {}
|
sprites = {}
|
||||||
sprites.coin_sheet = love.graphics.newImage('sprites/coin_sheet.png')
|
sprites.coin_sheet = love.graphics.newImage('sprites/coin_sheet.png')
|
||||||
@ -8,13 +8,37 @@ function love.load()
|
|||||||
sprites.player_stand = love.graphics.newImage('sprites/player_stand.png')
|
sprites.player_stand = love.graphics.newImage('sprites/player_stand.png')
|
||||||
|
|
||||||
require('player')
|
require('player')
|
||||||
|
|
||||||
|
platforms = {}
|
||||||
|
|
||||||
|
spawnPlatform(50, 200, 300, 30)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
|
myWorld:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
love.graphics.draw(sprites.player_stand, player.x, player.y)
|
love.graphics.draw(
|
||||||
|
sprites.player_stand,
|
||||||
|
player.body:getX(),
|
||||||
|
player.body:getY(),
|
||||||
|
nil, nil, nil,
|
||||||
|
sprites.player_stand:getWidth()/2, sprites.player_stand:getHeight()/2)
|
||||||
|
|
||||||
|
for i, p in ipairs(platforms) do
|
||||||
|
love.graphics.rectangle("fill", p.body:getX(), p.body:getY(), p.width, p.height)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function spawnPlatform(x, y, width, height)
|
||||||
|
local platform = {}
|
||||||
|
platform.body = love.physics.newBody(myWorld, x, y, 'static')
|
||||||
|
platform.shape = love.physics.newRectangleShape(width/2, height/2, width, height)
|
||||||
|
platform.fixture = love.physics.newFixture(platform.body, platform.shape)
|
||||||
|
platform.width = width
|
||||||
|
platform.height = height
|
||||||
|
|
||||||
|
table.insert(platforms, platform)
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
player = {}
|
player = {}
|
||||||
|
player.body = love.physics.newBody(myWorld, 100, 100, 'dynamic')
|
||||||
player.x = 100
|
player.shape = love.physics.newRectangleShape(66, 92)
|
||||||
player.y = 100
|
player.fixture = love.physics.newFixture(player.body, player.shape)
|
||||||
|
Loading…
Reference in New Issue
Block a user