So right now I have player
Code: Select all
player = {}
player.gridx = 64
player.gridy = 64
player.acty = 200
player.speed = 32
Because I'm using grid but I would also like add
Code: Select all
world = love.physics.newWorld(0, 0, true)
In love.load()
Code: Select all
player = {}
player.body = love.physics.newBody(world, 200, 550, "dynamic")
player.body:setMass(100) -- make it pretty light
player.shape = love.physics.newRectangleShape(0, 0, 30, 15)
player.fixture = love.physics.newFixture(player.body, player.shape, 2)
player.fixture:setRestitution(0.4) -- make it bouncy
and then use
Code: Select all
if love.keyboard.isDown("right") then
player.body:applyForce(10, 0.0)
print("moving right")
elseif love.keyboard.isDown("left") then
player.body:applyForce(-10, 0.0)
print("moving left")
end
if love.keyboard.isDown("up") then
player.body:applyForce(0, -500)
elseif love.keyboard.isDown("down") then
player.body:applyForce(0, 100)
end
Code: Select all
function love.keypressed(key)
if key == "up" then
if testMap(0, -1) then
player.gridy = player.gridy - 32
end
elseif key == "down" then
if testMap(0, 1) then
player.gridy = player.gridy + 32
end
elseif key == "left" then
if testMap(-1, 0) then
player.gridx = player.gridx - 32
end
elseif key == "right" then
if testMap(1, 0) then
player.gridx = player.gridx + 32
end
end
end