PDA

Click to See Complete Forum and Search --> : Pong game question....


BenderSWE
Feb 2nd, 2001, 08:59 AM
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?

plenderj
Feb 2nd, 2001, 09:05 AM
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 :


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

BenderSWE
Feb 2nd, 2001, 09:12 AM
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.

plenderj
Feb 2nd, 2001, 09:24 AM
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 :



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

Sastraxi
Feb 2nd, 2001, 08:15 PM
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.