|
-
May 11th, 2002, 06:40 PM
#1
Thread Starter
Hyperactive Member
Pong
Yes, it's yet another Pong Game.
I'm writing a pong program for a VB course I'm doing. I've got the two paddles moving up and down in a picture box but how do I keep them from disappearing off the screen?
-
May 12th, 2002, 02:03 AM
#2
Not NoteMe
Are you moving the ball using vectors,
Or using angles?
Code:
X=X+(Sin(Angle)*Speed)
Y=Y+(Cos(Angle)*Speed)
The first is easier (for starting anyway), you'd do something like this (example is for the top paddle (has the lowest y value as the origin is at the top left):
X, Y is the position of the picbox (it's origin is also top left), and a and b are the speed vectors to add to them to create movement.
VB Code:
If Ball.Y < paddle.Y + paddle.Height And Ball.X + Ball.Width > paddle.X And Ball.X < paddle.X + paddle.Width Then
'Ball hit the paddle, so change it's y direction (a way from the paddle)
Ball.B = -Abs(Ball.B)
'Could manipulate the Ball.A value here according to where the ball hit the pad.
End If
Here is the code if you're using the angle & speed method:
VB Code:
If Ball.Y < paddle.Y + paddle.Height And Ball.X + Ball.Width > paddle.X And Ball.X < paddle.X + paddle.Width Then
Ball.Angle = 90-(Ball.Angle-270)
'Note: This will be different for all other collisions
End If
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
May 12th, 2002, 02:07 AM
#3
Not NoteMe
For a lot more info, and stuff that will get you the best grade check out this thread:
http://www.vbforums.com/showthread.p...hreadid=163044
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
May 12th, 2002, 05:15 AM
#4
Thread Starter
Hyperactive Member
Thanks, I'll go check it out.
-
May 12th, 2002, 05:27 AM
#5
Thread Starter
Hyperactive Member
I have another little prob not covered by the other thread. I want to play a sound everytime the ball hits the walls. I've used this code:
If BallX < 0 Then
BallX = 0
BallXDir = 1
RtnValue = sndPlaySound(Bounce, SND_ASYNC Or SND_MEMORY)
The sound has been stored here:
Dim Buffer As String
Dim F As Integer
Dim SoundBuffer As String
On Error GoTo NoiseGet_Error
Buffer = Space(1024)
SoundBuffer = ""
F = FreeFile
Open FileName For Binary As F
Do While Not EOF(F)
Get #F, , Buffer
SoundBuffer = SoundBuffer & Buffer
Loop
Close F
StoreSound = Trim(SoundBuffer)
Exit Function
NoiseGet_Error:
SoundBuffer = ""
Exit Function
And in the form load:
Bounce = StoreSound(App.Path + "Bounce.wav")
I think I've declared everything I should:
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Const SND_ASYNC = &H1
Private Const SND_SYNC = &H0
Private Const SND_MEMORY = &H4
But the sound won't play. Can you see where I might have gone wrong? Maybe I left something out.
-
May 12th, 2002, 06:03 AM
#6
Not NoteMe
If the ball is changing direction correctly, then the problem is with your sound code, as i havn't used sound before i can't help you
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
May 12th, 2002, 06:19 AM
#7
Thread Starter
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|