lua-love-platformer/player.lua

38 lines
1007 B
Lua
Raw Normal View History

2018-01-18 03:51:14 +00:00
player = {}
2018-01-18 05:41:26 +00:00
player.start_x = 106
player.start_y = 465
2018-01-18 04:17:31 +00:00
-- Physics Engine
2018-01-18 05:41:26 +00:00
player.body = love.physics.newBody(myWorld, 0, 0, 'dynamic')
2018-01-18 04:06:17 +00:00
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
2018-01-18 05:41:26 +00:00
function resetPlayerPosition()
player.body:setPosition(player.start_x, player.start_y)
end