Results 1 to 5 of 5

Thread: [RESOLVED] Pong Game

  1. #1

    Thread Starter
    Addicted Member Redangel's Avatar
    Join Date
    Oct 2005
    Location
    England
    Posts
    214

    Resolved [RESOLVED] Pong Game

    i am trying to get my program (Pong) to reconize the bat on the left side of my form the ball will bounce off the bat but it also bounces of the bat when it misses if ya know what i mean??

    VB Code:
    1. Private Sub tmrMove_Timer()
    2.     If Counter1 >= 4 Then
    3.         MsgBox "Game Over...", vbInformation = vbOKOnly, "Pong"
    4.         Call Form_Load
    5.     End If
    6. 'Give focus to the scrollbar
    7.     vsbBatMove.SetFocus
    8.     imgMain.Move imgMain.Left + Xinc, imgMain.Top + Yinc
    9. 'Right
    10.     If ScaleWidth <= imgMain.Left + imgMain.Width Then _
    11.         Xinc = Xinc * -1
    12. 'Bottom
    13.     If ScaleHeight <= imgMain.Top + imgMain.Height Then _
    14.         Yinc = Yinc * -1
    15. 'Top
    16.     If ScaleTop >= imgMain.Top Then _
    17.         Yinc = Yinc * -1
    18. 'Bat   'THIS IS WHERE I AM HAVING TROUBLE'
    19.     If imgMain.Left <= shpLeftBat.Left Then _
    20.         Xinc = Xinc * -1
    21. 'Miss Bat
    22.     If ScaleLeft >= imgMain.Left + imgMain.Width Then
    23.         imgMain.Move 4800, 2400, 1095, 975
    24.         Counter1 = Counter1 + 1
    25.     End If
    26. End Sub

    Please point me in the right direction
    Thanks in advance RedAngel

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Pong Game

    Moved to Games and Graphics.

  3. #3
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Pong Game

    Timers are not accurate, and that could be the main reason why it's missing on and off. You have to use managed loops, such as a While...Wend loop or a Do loop. Also I fixed your code a bit:

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     'Set the ScaleMode to Pixels
    4.     ScaleMode = 3
    5.  
    6. End Sub
    7.  
    8. Private Sub tmrMove_Timer()
    9.  
    10.     If Counter1 >= 4 Then
    11.         MsgBox "Game Over...", vbInformation = vbOKOnly, "Pong"
    12.         Call Form_Load
    13.     End If
    14.  
    15. 'Give focus to the scrollbar
    16.     vsbBatMove.SetFocus
    17.     imgMain.Left = imgMain.Left  + Xinc
    18.     imgMain.Top = imgMain.Top + Yinc
    19. 'Right
    20.     If ScaleWidth <= (imgMain.Left + imgMain.Width) Then _
    21.         Xinc = Xinc * -1
    22. 'Bottom
    23.     If ScaleHeight <= (imgMain.Top + imgMain.Height) Then _
    24.         Yinc = Yinc * -1
    25. 'Top
    26.     If ScaleTop >= imgMain.Top Then _
    27.         Yinc = Yinc * -1
    28. 'Bat   'THIS IS WHERE I AM HAVING TROUBLE'
    29.     If imgMain.Left >= (shpLeftBat.Left) And _
    30.        imgMain.Left <= (shpLeftBat.Left + shpLeftBat.Width) And _
    31.        imgMain.Top <= (shpLeftBat.Top + shpLeftBat.Height) And _
    32.        imgMain.Top >= (shpLeftBat.Top) Then Xinc = Xinc * -1
    33.  
    34. Else
    35.         imgMain.Move 480, 240, 109, 97
    36.         Counter1 = Counter1 + 1
    37. End If
    38. End Sub

  4. #4

    Thread Starter
    Addicted Member Redangel's Avatar
    Join Date
    Oct 2005
    Location
    England
    Posts
    214

    Re: Pong Game

    Nice one Sorted Now Thanks for your time

  5. #5
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: [RESOLVED] Pong Game

    Also some tips you should know. Never use the Move method for objects, and never use a scrollbar to move the paddle. Use keyboard events instead. Here's the best way to do it in pure VB:

    http://www.vbforums.com/attachment.p...chmentid=36571

    But I normally use DirectInput myself since it's way better.

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