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:
Dim ScoreRed As Integer ScoreRed = 0 Dim ScorePurple As Integer ScorePurple = 0
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:
ScoreRed = ScoreRed + 10
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.
Text.DrawText "Red Score", black, GameFont("Courier"), 5, 5 Text.DrawText Str(ScoreRed), black, GameFont("Courier"), 150, 5
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.Ballgame.zip
- First Step VB6 - Getting started and compiling "Hello World"
- Adding an Image - How to add an image and draw it
- Sprites and Movement - Getting the image to move
- Playing Sounds - Loading and playing a sound
- Keyboard Input - Moving a sprite with keys
- Sprite Collisions - Adding a "bounce" to the game
- Scoring - Adding a score to your game
- Mouse Input - Clicking sprites in your game