First Step VB6 - Scoring

So lets set it up so when the red player misses the ball the purple player gets 10 points and vice versa. The first thing we need to do is declare two variables (dim) as Integers (integers are just whole numbers like 1 and 50 but not 1.25). After you declare your other variabales declare these two:

After we declare them you will notice they are both initialised to 0 so that when the program starts it has something to display.

Next we just need to tell it to add to the opponents score when the ball is missed. You will remember our code already knows when the ball hits any of the walls, it is when the "boink" sound is played. We just need to find out when it hits the bottom or top and add 10 to ScoreRed or ScorePurple depending on if it is the top or the bottom. The code for adding 10 to the score is simple, lets say the ball hits the bottom border then red would get 10 points or:

Now to dispaly that score on the screen next to the red paddle in the loop after you "draw" the other items use this code (you will remember it from the "Hello World" tutorial.

Now you do this...
Repeat the code except this time for the purple score and make sure you change the position of it on the screen so it is at the bottom this time near the purple paddle.

Now your game should be fully functional and look like this:



Download a copy of the working project up to this point.[[Media:BallGameVB6.zip|Ballgame.zip]]