jump around

jump around
This commit is contained in:
Tyrel Souza 2018-01-17 23:17:31 -05:00
parent 7b30c93128
commit ae5da288ca
2 changed files with 38 additions and 6 deletions

View File

@ -1,6 +1,7 @@
--[[ LOVE STUFF ]]
function love.load()
myWorld = love.physics.newWorld(0, 100)
myWorld = love.physics.newWorld(0, 500)
myWorld:setCallbacks(beginContact, endContact, preSolve, postSolve)
sprites = {}
sprites.coin_sheet = love.graphics.newImage('sprites/coin_sheet.png')
@ -16,6 +17,7 @@ end
function love.update(dt)
myWorld:update(dt)
playerUpdate(dt)
end
function love.draw()
@ -31,6 +33,12 @@ function love.draw()
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)
local platform = {}
@ -42,3 +50,11 @@ function spawnPlatform(x, y, width, height)
table.insert(platforms, platform)
end
function beginContact(a, b, coll)
player.grounded = true
end
function endContact(a, b, coll)
player.grounded = false
end

View File

@ -1,4 +1,20 @@
player = {}
-- Physics Engine
player.body = love.physics.newBody(myWorld, 100, 100, 'dynamic')
player.shape = love.physics.newRectangleShape(66, 92)
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