2018-01-18 03:51:14 +00:00
|
|
|
player = {}
|
2018-01-18 04:17:31 +00:00
|
|
|
-- Physics Engine
|
2018-01-18 04:06:17 +00:00
|
|
|
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)
|
2018-01-18 04:38:37 +00:00
|
|
|
player.body:setFixedRotation(true)
|
2018-01-18 04:17:31 +00:00
|
|
|
--
|
2018-01-18 04:21:42 +00:00
|
|
|
player.sprite = sprites.player_jump
|
2018-01-18 04:17:31 +00:00
|
|
|
player.speed = 200
|
|
|
|
player.grounded = false
|
2018-01-18 04:21:42 +00:00
|
|
|
player.direction = DIRECTION_RIGHT
|
2018-01-18 04:17:31 +00:00
|
|
|
|
|
|
|
function playerUpdate(dt)
|
2018-01-18 05:30:01 +00:00
|
|
|
if gameState == "game" then
|
|
|
|
if love.keyboard.isDown('a') then
|
|
|
|
player.body:setX(player.body:getX() - player.speed * dt)
|
|
|
|
player.direction = DIRECTION_LEFT
|
|
|
|
end
|
2018-01-18 04:17:31 +00:00
|
|
|
|
2018-01-18 05:30:01 +00:00
|
|
|
if love.keyboard.isDown('d') then
|
|
|
|
player.body:setX(player.body:getX() + player.speed * dt)
|
|
|
|
player.direction = DIRECTION_RIGHT
|
|
|
|
end
|
2018-01-18 04:23:06 +00:00
|
|
|
|
2018-01-18 05:30:01 +00:00
|
|
|
if player.grounded == true then
|
|
|
|
player.sprite = sprites.player_stand
|
|
|
|
else
|
|
|
|
player.sprite = sprites.player_jump
|
|
|
|
end
|
2018-01-18 04:23:06 +00:00
|
|
|
end
|
2018-01-18 04:17:31 +00:00
|
|
|
end
|