VB icon

Code for a basic Pong style game!

Submitted on: 1/2/2015 8:51:00 AM
By: Matthew Eagar (from psc cd)  
Level: Not Given
User Rating: By 4 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 18026
     Makes a little pong style game
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
' Name: Code for a basic Pong style game!
' Description:Makes a little pong style game
' By: Matthew Eagar (from psc cd)
' Assumes:Nothin much, just a very basic knowledge of VB programming.

Dim vmom As Integer 'holds the ball's vertical momentum
Dim hmom As Integer 'holds the ball's horizontal momentum
Private Sub Form_Load()
'make the vertical and horizontal momentums random
vmom = 100 + Int(Rnd * 200)
hmom = 100 + Int(Rnd * 200)
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'move the paddle to the mouse's position
Shape1.Left = X - (Shape1.Width / 2)
End Sub
Private Sub Timer1_Timer()
'move the ball, based on the virtical and horizontal momenutm
Shape2.Top = Shape2.Top + vmom
Shape2.Left = Shape2.Left + hmom
'see if the ball is hitting the surface of the paddle
 If (Shape2.Top + Shape2.Height) > Shape1.Top Then
If Shape2.Left + Shape2.Width >= Shape1.Left And Shape2.Left <= Shape1.Left + Shape1.Width Then
vmom = -vmom
End If
End If
'see if the ball has hit the edge of the screen
If (Shape2.Left + Shape2.Width) > Form1.Width Then
Shape2.Left = Form1.Width - Shape2.Width
hmom = -hmom 'this reverses it ball's direction
ElseIf Shape2.Left < 0 Then
Shape2.Left = 0
hmom = -hmom 'this reverses it ball's direction
ElseIf Shape2.Top < 0 Then
Shape2.Top = 0
vmom = -vmom 'this reverses it ball's direction
ElseIf Shape2.Top > Form1.Height Then
MsgBox "You lost!"
Timer1.Enabled = False
End If
End Sub

Other 6 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.