Results 1 to 6 of 6

Thread: Pong

  1. #1

    Pong

    Yup a simple game, and one which I have done pretty well on considering all code is mine and not 1 bit of research outside on how I would do it. Was very nice to create it myself. I am hoping to maybe make it into a "Final fantasy 7 Pong" complete with FF7 pictures, players etc.

    Anyway, problem that surfaced is that if deltatime is large the collision misses and theerfore the ball goes through the paddle.

    Now, this isnt an issue on my computer, but on a slower one it would be for certain.

    I have made the paddles thicker to compensate but this will always remain an issue.

    Is this one game where Framebased movement would be a better alternative or is there a way around this to programatically account for this problem?

    Thanks again to all, my other original game complete with music is more or less done. This one is justa bit of fun (as a kid i always wanted to make pong!!)

  2. #2

    Re: Pong

    Quote Originally Posted by seiferalmasy
    Is this one game where Framebased movement would be a better alternative or is there a way around this to programatically account for this problem?
    Before moving the ball, check if the distance between old and new ball's position is bigger then thickness of the paddle.
    If no, do standard collision detection.
    if yes, divide distance in offsets smaller then paddle's thicknes. Check collison for first offset. If there is no collision then add offset to ball's position and check with second offset and so on.

  3. #3

    Pong

    Yes this is a problem with deltatime-based engines.
    The method grudzio suggests will work.
    A variant on this is to set a MaxDeltaTimeCollision-value to say 0.1 seconds.
    So if the main loops DeltaTime is 0.25 on a slow machine, you will loop around the collision code with three times, with Deltas 0.1 , 0.1 and 0.05.

    Something like this maybe:
    Code:
    procedure CheckCollisions;
    const
      //Maximum time step for 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;
        DoCheckCollisions(DT);
        TimeLeft := TimeLeft - MaxUpdateStep;
      end;
    end;
    ZGameEditor - Develop 64kb games for Windows.
    Thrust for Vectrex - ROM-file and 6809 source code.

  4. #4

    Pong

    That is an interesting approach VilleK - haven't seen that one before I have always used the same method as grudzio's solution.

    So where is pong seiferalmasy?
    The views expressed on this programme are bloody good ones. - Fred Dagg

  5. #5

    Pong

    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
    ZGameEditor - Develop 64kb games for Windows.
    Thrust for Vectrex - ROM-file and 6809 source code.

  6. #6

    Pong

    Cheers for all that. Will study it

    Anyone else do it any other way?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •