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