Platformer X™
Posted: Sun Apr 22, 2012 6:24 am
Platformer X
Code: Select all
if pos.x > rect.x and pos.x < rect.x + rect.w and pos.y > rect.y and pos.y < rect.y + rect.h then
return
true
else
return
false
end
Code: Select all
function love.update(dt)
fps = love.timer.getFPS()
--**if player.x > 1000 and player.x < 1000 + 32 and player.y > 500 and player.y < 500 + 32 then = makes your collision a 32x32 square... try just player.y > rect.y **
if player.x > rect.x and player.x < rect.x + rect.w and player.y > rect.y and player.y < rect.y + rect.h then
player.collision = true
return true --** this returns (exits) love.update(dt) function as you are not in any other function... remove this**
else
return false -- ** use player.collision = true instead**
end
frame = dt * 30 -- I do this just because I think better this way
player.ySpeed = player.ySpeed + player.gravSecond * frame -- We add gravity to the ySpeed
player.y = player.y + player.ySpeed * frame -- We add ySpeed to the player's y position -- ** should be down at -->>
if player.collision then -- Are we on the ground?
player.y = player.y - player.ySpeed * frame -- If we are, We undo that moving down
player.ySpeed = 0 -- The ySpeed is reset --** you should have this before player.y = ...
player.inAir = false
end-- ** and add an else -->> end instead
if love.keyboard.isDown("right") then
player.x= player.x+5
end
if love.keyboard.isDown("left") then
player.x= player.x-5
end
end