Results 1 to 5 of 5

Thread: Pong game.. make the ball go faster..

  1. #1
    Linette
    Guest

    Arrow Pong game.. make the ball go faster..

    Hi everyone,

    I'm wondering if there's a way to make the ball in a pong game go faster with time (i.e. accelerate).. Right now in my program the movement of the ball is in accordance with a timer, but I don't think I can make it go any faster using a timer.. Any suggestions?

    Thank you

    Linette

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Say you add + XSpeed (the speed of the X direction) and + YSpeed (the speed of the Y direction) in each Timer interval. If you want it to accelerate, just add (for example) + XSpeed * 1.2 and + YSpeed * 1.2.

    This will make the ball accelerate by 1.2 times the YSpeed. It wouldn't get any faster than this.

    But you can go this way:

    XSpeed = XSpeed * 1.2
    YSpeed ... etc.

    And it will add 1.2 times XSpeed to Xspeed every time your timer goes - the ball will keep getting faster.

    Now if you want, say, for the ball to get faster every time you block, just add that code when the ball hits your board.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    Lively Member
    Join Date
    Aug 1999
    Posts
    89
    Hi,
    Instead of putting things into a timer, you could place the code into a game loop. After you load things up you'd want to enter the game loop
    Code:
    sub GameLoop()
      dim RUNNING as boolean
      RUNNING = true ' when it equals false, the game is over
      do
        RUNNING = Input() ' get user input, I have it so if they press  escape the game quits
        Blt() ' draw stuff onto the screen 
      Wait(TimeBetween frames) ' here you can determine how much time you want the system to wait, its somewhat like a timer 
      while(RUNNING)
      Cleanup() ' cleanup phase if you use DirectDraw
      ' then you can quit the game now or play again
    end sub
    Private Declare Function GetTickCount& Lib "kernel32" ()
    function Wait(int Time)
      dim tb as long, tn as long
      tb=GetTickCount()
      do 
         tn = GetTickCount()
      while(abs(tn-tb)<Time)
    end function
    thats what you pretty much follow for a game loop, you just keep doing things over and over until its done, and forgive me if some of the syntax is wrong, I cut it out from C++ and tried to convert most of it, not sure if I did the loops right.
    Hope that helps

  4. #4
    Linette
    Guest
    I think I'll try that, thank you

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The problem is that under Win9x the timer control has a maximal resolution of 15 ticks/second. The GetTickCount method on the other hand is accurate to the millisecond. But I would modify the loop a little bit:
    VB Code:
    1. Private Declare Function GetTickCount Lib "kernel32" () as Long
    2. 'I find this syntax more readable, I also like hungarian notation
    3.  
    4. Const lTicksPerFrame = 30 'A good value to work with
    5.  
    6. Sub GameLoop()
    7.   Dim bRun as Boolean
    8.   Dim lTicks as Long
    9.   bRun = True ' when it equals false, the game is over
    10.   do
    11.     lTicks = GetTickCount
    12.     bRun = Input() ' get user input, I have it so if they press  escape the game quits
    13.     Blt() ' draw stuff onto the screen
    14.     Repeat While (lTicks + lTicksPerFrame > GetTickCount)
    15.     End Repeat
    16.   While(bRun)
    17.   Cleanup() ' cleanup phase if you use DirectDraw
    18.   ' then you can quit the game now or play again
    19. end sub

    This takes into account that the loop itself needs time too. I too can't guarantee that this works since I've never done Vb.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width