Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VB

The Old Mighty Pong

3.33/5 (3 votes)
20 Aug 2007CPOL1 min read 1   388  
A classic in game history.

Introduction

I was staring in shock at some VB6 tutorials on how to make Pong. There were shown some awful functions, libraries, and things I couldn't understand. So I thought I could simplify the code to a level which a programmer with my experience would understand. I began to code from scratch, and in a few days, I managed to accomplish the task...

Background

Well, I suppose that many of you have played Pong... it's just a classic. But in my solution, there are some tricky parts, like the controls - they are buttons which have captions with "&" in front. And when set the controls section, you will probably notice that if you delete the char "&" before the actual control, it wouldn't work...

Using the Code

The code is nothing serious as I mentioned earlier. I have replaced the currenX position with the "Left" property and currentY with "Top".

Here is a piece of the code:

VB
'timer sub 
If Ball.Top = 0 Then optDown.Checked = True
If Ball.Top = 264 Then optUp.Checked = True
If optUp.Checked = True Then Ball.Top = Ball.Top - 1
If optDown.Checked = True Then Ball.Top = Ball.Top + 1
If optLeft.Checked = True Then Ball.Left = Ball.Left - 1
If optRight.Checked = True Then Ball.Left = Ball.Left + 1
If Ball.Left < -20 Then lblP2Score.Text = lblP2Score.Text + 1
If Ball.Left > 408 Then lblP1Score.Text = lblP1Score.Text + 1

Points of Interest

I was very exited when I did it, because I got to know a new way of making objects move. And I finally made an app from which I earned :D

History

I will keep an eye on your requests for improvement. If you'd like to contact me - my e-mail is buffallo@abv.bg.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)