Re: Problem with Libraries
Posted: Tue Mar 20, 2012 11:45 am
You would need to check for collisions with platforms, rather than just the floor.
Wisdom regarding how to check collisions is manyfold and plentious, but here's a really simple procedure :
Code: Select all
local floor = false
for i, platform in pairs(platforms) do
floor = collide(ball, platform)
end
if floor then ball.y = floor.y else ball.y = ball.y + (256 * dt) end
Code: Select all
function withinrect(pos, rect)
return pos.x > rect.x and pos.x < rect.x + rect.w and pos.y > rect.y and pos.y < rect.y + rect.h
end
function collide(object, platform)
if withinrect(object, platform) then return platform else return false end
end