jump around
jump around
This commit is contained in:
parent
7b30c93128
commit
ae5da288ca
18
main.lua
18
main.lua
@ -1,6 +1,7 @@
|
|||||||
--[[ LOVE STUFF ]]
|
--[[ LOVE STUFF ]]
|
||||||
function love.load()
|
function love.load()
|
||||||
myWorld = love.physics.newWorld(0, 100)
|
myWorld = love.physics.newWorld(0, 500)
|
||||||
|
myWorld:setCallbacks(beginContact, endContact, preSolve, postSolve)
|
||||||
|
|
||||||
sprites = {}
|
sprites = {}
|
||||||
sprites.coin_sheet = love.graphics.newImage('sprites/coin_sheet.png')
|
sprites.coin_sheet = love.graphics.newImage('sprites/coin_sheet.png')
|
||||||
@ -16,6 +17,7 @@ end
|
|||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
myWorld:update(dt)
|
myWorld:update(dt)
|
||||||
|
playerUpdate(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
@ -31,6 +33,12 @@ function love.draw()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function love.keypressed(key, scancode, isrepeat)
|
||||||
|
if key == "space" and player.grounded then
|
||||||
|
player.body:applyLinearImpulse(0, -2500)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function spawnPlatform(x, y, width, height)
|
function spawnPlatform(x, y, width, height)
|
||||||
local platform = {}
|
local platform = {}
|
||||||
@ -42,3 +50,11 @@ function spawnPlatform(x, y, width, height)
|
|||||||
|
|
||||||
table.insert(platforms, platform)
|
table.insert(platforms, platform)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function beginContact(a, b, coll)
|
||||||
|
player.grounded = true
|
||||||
|
end
|
||||||
|
function endContact(a, b, coll)
|
||||||
|
player.grounded = false
|
||||||
|
end
|
||||||
|
16
player.lua
16
player.lua
@ -1,4 +1,20 @@
|
|||||||
player = {}
|
player = {}
|
||||||
|
-- Physics Engine
|
||||||
player.body = love.physics.newBody(myWorld, 100, 100, 'dynamic')
|
player.body = love.physics.newBody(myWorld, 100, 100, 'dynamic')
|
||||||
player.shape = love.physics.newRectangleShape(66, 92)
|
player.shape = love.physics.newRectangleShape(66, 92)
|
||||||
player.fixture = love.physics.newFixture(player.body, player.shape)
|
player.fixture = love.physics.newFixture(player.body, player.shape)
|
||||||
|
--
|
||||||
|
player.speed = 200
|
||||||
|
player.grounded = false
|
||||||
|
|
||||||
|
|
||||||
|
function playerUpdate(dt)
|
||||||
|
|
||||||
|
if love.keyboard.isDown('a') then
|
||||||
|
player.body:setX(player.body:getX() - player.speed * dt)
|
||||||
|
end
|
||||||
|
|
||||||
|
if love.keyboard.isDown('d') then
|
||||||
|
player.body:setX(player.body:getX() + player.speed * dt)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user