Quick Search for:  in language:    
Makes,little,pong,style,game
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Visual Basic Stats

 Code: 3,011,557. lines
 Jobs: 115. postings

 How to support the site

 
Sponsored by:

 

You are in:

 
Login



Latest Code Ticker for Visual Basic.
AniViewer
By Jerrame Hertz on 6/30


Click here to see a screenshot of this code!Raw Packet Sniffer
By Coding Genius on 6/30

(Screen Shot)

Check the support of a record set
By Freebug on 6/30


B++ Builder - VB without runtimes
By Anthonius on 6/30


Mr Blonde - Chat Program
By Mr Blonde on 6/30


MSN Messenger Status Detector
By Ryan Cain on 6/30


MSN advanced
By alias1990 on 6/30


MSN Messenger advanced
By alias1990 on 6/30


Locate Database
By Erica Ziegler-Roberts on 6/30


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

Code for a basic Pong style game!

Print
Email
 

Submitted on: 6/4/1999
By: Matthew Eagar 
Level: Not Given
User Rating: By 101 Users
Compatibility:VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0

Users have accessed this code 8540 times.
 
 
     Makes a little pong style game
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

'**************************************
' Name: Code for a basic Pong style game
'     !
' Description:Makes a little pong style 
'     game
' By: Matthew Eagar
'
' Assumes:Nothin much, just a very basic
'     knowledge of VB programming.
'
'This code is copyrighted and has' limited warranties.Please see http://w
'     ww.Planet-Source-Code.com/vb/scripts/Sho
'     wCode.asp?txtCodeId=1971&lngWId;=1'for details.'**************************************

Dim vmom As Integer 'holds the ball's vertical momentum
Dim hmom As Integer 'holds the ball's horizontal momentum
Private Sub Form_Load()

Randomize 'make the vertical and horizontal moment ' ums 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 an ' d 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 9 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
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
6/4/1999 4:16:00 PM:Matt
Whoops! I made a mistake in the 
timer1_timer() procedure: this
If Shape2.Left + Shape2.Width >= 
Shape1.Left _
Shape2.Left <= 
Shape2.Left + 
should be changed to 
If Shape2.Left + Shape2.Width >= 
Shape1.Left _
And Shape2.Left <= 
Shape2.Left + 
The line was too long 
so I moved it down to the next one, and 
deleted a word.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/4/1999 9:37:00 PM:kyle
hey,
  I just got VB yesterday and i 
dont know what im doing so i thought i 
would start with something easy, so i 
tried this. Well i got the paddle to 
work but the ball is just sitting 
there, what should I do?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/5/1999 7:33:00 AM:Lolindrath
Set your timer interval to 1, then it 
will work
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/5/1999 12:37:00 PM:Kyle
When your supposed to to change that 
spot where you missed a word in the 
code i keep getting a syntax error. 
What do i do?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/5/1999 6:45:00 PM:Ian Ippolito
I got it to work:
Just use this code 
where you are getting the syntax 
error:
If Shape2.Left + Shape2.Width 
>= Shape1.Left _
        And 
Shape2.Left <= Shape1.Left + 
Shape1.Width Then
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/7/1999 2:49:00 AM:||ooser
everything works but the ball just goes 
right through the paddle
like it 
doesnt bounce off
can you help?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/7/1999 7:02:00 PM:Matt
Whoops, sorry people, made a major 
glitch in there.  When the ball is on 
the right side of the paddle, it 
bounces like it hits the paddle. this 
block of code:
    If (Shape2.Top + 
Shape2.Height) > Shape1.Top Then
  If Shape2.Left + Shape2.Width >= 
Shape1.Left _
        Shape2.Left <= 
Shape2.Left + Shape2.Width Then
 vmom = -vmom
    End If
should be 
changed to this:
 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
Sorry for 
any inconvenience, I don't know how I 
missed something like that.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/8/1999 2:25:00 PM:VBbob
everything works great, just one 
problem. the ball doesn't bounce of the 
side of the form! can anyone help?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/8/1999 6:39:00 PM:Craig
Just wanted to say thankyou. Stuff like 
this really helps and means a lot. 
Thanks again!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/9/1999 10:50:00 AM:Abdul
umm...this code is real messed up.  Hey 
Matt, can you repost this entire code. 
Or send me the form or something?
I 
really want to get this to work.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/11/1999 11:02:00 AM:Iwinky
I CAN'T MAKE THIS WORK!!!!
   The ball 
doesn't move at all, please e-mail me 
with the code on how to make this 
work.
Iwinky
Iwinky@fcmail.com
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/11/1999 5:31:00 PM:Nic
Hey the ball just goes off the form!!  
Could you email me the forms!! PLEASE !!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/15/1999 3:22:00 AM:PugZ
I cant even get the code to work at 
all!! no ball no paddle no nothig. just 
errors.. please repost the code
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/16/1999 10:31:00 PM:Pete
Fun code :-)  I saw a game like this 
once, put some obstacles and get some 
points for it... multiple balls!!!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/17/1999 4:38:00 AM:Stefan Grönberg
Do get the ball movin' u need add 
time1
and set the Intervall to what 
ever u whant, Remember that the 
interval in is millesecouns, and that 
means 1000 = 1 sec..
/Stefan "Trash 
Software" Grönberg
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/17/1999 2:20:00 PM:Drunk_Cowboy
Will some one please send me the forms 
and .vbx file please my email is 
The_Drunk_Cowboy@yahoo.com
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/18/1999 12:58:00 AM:Etienne
I sent your code to all people who 
asked it.
Your game is very 
funny.
Many Thanks
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/21/1999 1:19:00 PM:Tiggermcat
This wont work for me at all errors 
everywhere someone e-mail me the 
project in none .exe plz in .frm
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/21/1999 5:24:00 PM:Matt
I don't know what to tell you people! 
It works fine for me! I just cut and 
paste this code into a new project, add 
2 shapes, and a timer with an interval 
of 1! It works without a single error! 
I'm running VB 6, but I have tested 
this code in vb 3 and it works fine!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/22/1999 9:05:00 PM:Cob
Ok, im mad, i have been making my own 
pong game without knowing this one is 
here, my pong has a scoring, 2 player, 
pause, changable ball color, backround 
music that you can change, and im 
making a online portion, 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/22/1999 9:14:00 PM:Vlado
I really like all your codes this one i 
liked too it works perfect 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/23/1999 10:57:00 PM:Komodo_Dragon
send me the working code please at my 
e-Mail, because ive tried alot of 
things and this code is just not 
working for me! ok?
thanks
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/26/1999 5:41:00 AM:ccjx
I noticed something strange. When the 
ball falls to the left of the bouncer, 
it bounces in then out. Why cant it 
bounce away and gets out of the screen?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/28/1999 1:18:00 AM:ccjx
NOTE! This source code is the 
foundation of a pong game. But it is 
not complete and maybe some of you can 
go and ask Matt to complete it. But, 
for a full version of the game, come 
here for Cool 
Pong!
http://www.planet-source-code.com
/vb/scripts/ShowCode.asp?txtCodeId=2199
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/3/1999 2:30:00 AM:Stics
I'm new in VB and this code works 
fine
for a start!
Thanks for simple 
good code!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/16/1999 11:33:00 PM:Matt
I just submitted much better and more 
advanced pong game, so if you have a 
strong grasp of this basic one, then 
you should check it out!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/17/1999 11:10:00 PM:André Henn
Can you please send me the whole 
project as a zip file
Thank You Very 
Much
André
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
4/30/2000 5:54:57 AM:Rob
great start for a pong game works fine 
for me thanks
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/25/2000 9:08:33 PM:michael patterson
people are such loosers. they cant 
learn for themselves!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/24/2000 2:49:59 PM:thx
your code helped me make my games 
collision control thx :-)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/14/2001 10:45:07 AM:Simon
Can some one send me all the code I 
still can't get it to work 
Simonshugar@hotmail.com
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/11/2002 9:05:50 PM:
what do i put on the acual form
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/11/2002 9:07:26 PM:
what do i put on the accual form
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Visual Basic Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.