lua-love-platformer/player.lua

23 lines
649 B
Lua
Raw Normal View History

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: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)
if love.keyboard.isDown('a') then
player.body:setX(player.body:getX() - player.speed * dt)
2018-01-18 04:21:42 +00:00
player.direction = DIRECTION_LEFT
2018-01-18 04:17:31 +00:00
end
if love.keyboard.isDown('d') then
player.body:setX(player.body:getX() + player.speed * dt)
2018-01-18 04:21:42 +00:00
player.direction = DIRECTION_RIGHT
2018-01-18 04:17:31 +00:00
end
end