Air Hockey Tutorial 6

This tutorial will teach you how to use the SwinGameSDK to develop a simple air hockey game. At the end of this tutorial you should be able to use Visual Basic 6 to implement your game which makes use of Vectors, Sprites and SoundEffects.

GOAL!!
You many of noticed that the ball will sometimes go into the goal. We will add in a check to find out when the ball goes in a goal. In the "MoveBall" method we will add this code.

Scoring
We now need to keep track of the score. To do this we will add 1 to score that is with the player. So we will add this into the code above, like this.

Resetting the Ball
Now that the ball is in the goal we will want to reset the ball, but we wont want it reset it straight away. So to do this we will edit the "AirHockeyGame" data type so it has a resetting and a reset. Resetting will be a Boolean and reset will be a Long. The type will now be like this.

Now in "CreateGame" we will need to set Resetting to false and Reset to 0. In "Run" we will check to see if Resetting it true and if so it will wait 3 seconds before re-spawning the ball. So when the ball goes in the goal we will change the value of Resetting to true and also set Reset to 0. Now we will add this code to "Run" after the "Draw" call.

Next we will create "Reset", but first we need to load a big font as we will need to use that in "Reset".

Now for "Reset". To do this we will call the "StartBall" method that we created earlier. We will also reset the location of the bats and the vectors of the bats.

Now when the ball goes in the goal we can still see it, so to fix this we will change draw to look like this.

Displaying The Score
To display the score we will draw it in the "Draw" method we have. to do this add this code to "Draw". You will also need to load the font "CourierBigger" which has the size 25 of the font "cour.ttf".

List Of Tutorials

 * 1) Introduction
 * 2) Table
 * 3) Ball
 * 4) Player
 * 5) AI
 * 6) Scoring
 * 7) Sound
 * 8) Menu
 * 9) Finishing