direction stuff
This commit is contained in:
parent
ae5da288ca
commit
8574888e18
11
main.lua
11
main.lua
@ -12,7 +12,9 @@ function love.load()
|
|||||||
|
|
||||||
platforms = {}
|
platforms = {}
|
||||||
|
|
||||||
spawnPlatform(50, 200, 300, 30)
|
spawnPlatform(50, 500, 300, 30)
|
||||||
|
DIRECTION_LEFT = -1
|
||||||
|
DIRECTION_RIGHT = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
@ -22,10 +24,10 @@ end
|
|||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
sprites.player_stand,
|
player.sprite,
|
||||||
player.body:getX(),
|
player.body:getX(),
|
||||||
player.body:getY(),
|
player.body:getY(),
|
||||||
nil, nil, nil,
|
nil, player.direction, 1,
|
||||||
sprites.player_stand:getWidth()/2, sprites.player_stand:getHeight()/2)
|
sprites.player_stand:getWidth()/2, sprites.player_stand:getHeight()/2)
|
||||||
|
|
||||||
for i, p in ipairs(platforms) do
|
for i, p in ipairs(platforms) do
|
||||||
@ -39,7 +41,6 @@ function love.keypressed(key, scancode, isrepeat)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function spawnPlatform(x, y, width, height)
|
function spawnPlatform(x, y, width, height)
|
||||||
local platform = {}
|
local platform = {}
|
||||||
platform.body = love.physics.newBody(myWorld, x, y, 'static')
|
platform.body = love.physics.newBody(myWorld, x, y, 'static')
|
||||||
@ -54,7 +55,9 @@ end
|
|||||||
|
|
||||||
function beginContact(a, b, coll)
|
function beginContact(a, b, coll)
|
||||||
player.grounded = true
|
player.grounded = true
|
||||||
|
player.sprite = sprites.player_stand
|
||||||
end
|
end
|
||||||
function endContact(a, b, coll)
|
function endContact(a, b, coll)
|
||||||
player.grounded = false
|
player.grounded = false
|
||||||
|
player.sprite = sprites.player_jump
|
||||||
end
|
end
|
||||||
|
@ -4,17 +4,19 @@ 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.sprite = sprites.player_jump
|
||||||
player.speed = 200
|
player.speed = 200
|
||||||
player.grounded = false
|
player.grounded = false
|
||||||
|
player.direction = DIRECTION_RIGHT
|
||||||
|
|
||||||
function playerUpdate(dt)
|
function playerUpdate(dt)
|
||||||
|
|
||||||
if love.keyboard.isDown('a') then
|
if love.keyboard.isDown('a') then
|
||||||
player.body:setX(player.body:getX() - player.speed * dt)
|
player.body:setX(player.body:getX() - player.speed * dt)
|
||||||
|
player.direction = DIRECTION_LEFT
|
||||||
end
|
end
|
||||||
|
|
||||||
if love.keyboard.isDown('d') then
|
if love.keyboard.isDown('d') then
|
||||||
player.body:setX(player.body:getX() + player.speed * dt)
|
player.body:setX(player.body:getX() + player.speed * dt)
|
||||||
|
player.direction = DIRECTION_RIGHT
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user