Just realized I forgot to say you of course need to update your sprite positions as well:
Code:
procedure UpdatePositionsAndCollisionTests;
const
//Maximum time step for updates and collision=1/10 second
MaxUpdateStep = 1.0 / 10;
var
TimeLeft,DT : single;
begin
TimeLeft := AppDeltaTime;
while TimeLeft>0 do
begin
if TimeLeft>MaxUpdateStep then
DT := MaxUpdateStep
else
DT := TimeLeft;
MoveObjects(DT); //Update object positions
DoCheckCollisions(); //Test collisions on current positions
TimeLeft := TimeLeft - MaxUpdateStep;
end;
end;
This is a problem with games with physics simulations too, you need to iteratively call the simulation code with small timesteps.
But a quick cheat around all this for a small game like pong is to not allow AppDeltaTime get too large. This will make the game play slower on slow machines.
Another cheat is to make the collision areas larger.
Here is a Pong clone I've made: http://www.emix8.org/static.php?page=zpong
Bookmarks