Results 1 to 5 of 5

Thread: Pong game question....

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Posts
    2

    Question

    Hi!

    Im a complete newbie at VB (im learning it at school)
    and one of our jobs is to do a simple game.

    I want to make a Pong like game for 2 players were one uses the mouse and on uses the keyboard...

    My question is :

    How do i draw fast graphiscs for the paddles and the ball?

    And how do i use collision detection to make the ball bounce on the paddles and other hinders on the board?
    Nothing is impossible to the man who dont have to do it...

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Its not actually all that easy
    To do fast graphics you would have to use the BitBlt API function.
    You would also have to create a 'Device Context' for the paddles and ball.

    What I would suggest however is that you just use pictureboxes with an image loaded in them.

    To check for collisions between ball and paddle do something like :

    Code:
    If (ball.Left <= (paddle_left.Width + paddle_left.Left)) Or ((ball.Left + ball.Width) >= paddle_right.Left) Then
        'Collision
    End If
    You follow ?
    You basically check if the controls overlap.

    - Jamie
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Posts
    2

    Random movement...

    I dont really understand that code but i will try it...

    Next question:

    How do i do random ball movement?
    I wat the ball to start in the middle, pick a direction and move in that direction.
    Nothing is impossible to the man who dont have to do it...

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Well if you want things to move in directions other than the basic 4 directions and variations on those, then you would really want to start using trigonometry.

    To make the ball move, just do something like the followsing :

    Code:
    Public Declare Function GetTickCount Lib "kernel32" () As Long
    Dim LastTick As Long
    Dim CurrentTick As Long
    
    Private Function RunGameLoop()
        
        Do
             
            CurrentTick = GetTickCount()
            
            If ((CurrentTick - LastTick) >= 45) Then
    
                LastTick = GetTickCount()
                
                ball.Left = ball.Left + ...
                ball.Top = ball.Top + ...
    
            End If
                
        Loop
    
    End Function
    Basically, to find out what direction to go in first, throw in a little bit of the Rnd function.

    Do you know anything about UDTs ?

    - jamie
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Buy a book called 'black art of visual basic game programming' - its for VB3 (win 3.1) but it has VB4 32 (win 95) examples as well, it has a game called breakthru! in it. It isn't exactly what you said but you could use some code examples to deal with it.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

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