Air Hockey Tutorial 1

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.

You can view the final product on the Air Hockey page. This includes a promo video, screen shots, and a download of the completed game as an executable and as source code.

Things You Need

 * Motivation to create a game.
 * Knowledge of procedural programming.
 * Visual Basic 6.
 * Image manipulation program (preferably Photoshop but Gimp is also good)

Starting The Project
You will need to download the latest version of SwinGameSDK for VB6. You can obtain a copy of SDK from the Download page. Once you have downloaded the SDK you need to register the Library. This can be done by running "SGSDKVB6.reg". Now that the Library is registered we add a reference to it in VB6. To add a reference to SwinGame follow these steps The reference should now be added.
 * 1) Open the project "VB6 Starter Pack.vbp"
 * 2) Go to the "Project" menu
 * 3) Select the "References..." option
 * 4) Find "SGSDKVB6" in the list of references
 * 5) Put a tick in in the box next to SGSDKVB6
 * 6) Now click OK

Compiling The Project
To Compile the project follow these steps It is also a good idea to create a short cut to "VB6 Starter Pack.exe" and place this in the main folder.
 * 1) Have VB6 open with the "VB6 Starter Pack.vbp" loaded
 * 2) Go the "File" menu
 * 3) Select the "Make VB6 Starter Pack.exe"
 * 4) Now navigate to the folder that "VB6 Starter Pack.vbp" is in
 * 5) Click on OK
 * 6) Now go to My Computer and navigate to the folder that "VB6 Starter Pack.vbp" is in
 * 7) Open up "copyresourcesVB6.cmd".
 * 8) This has created a bin folder. In this folder is your "VB6 Starter Pack.exe"

Creating And Closing The Window
Inside GameLogic there is the Sub called "Run", this is where we will start writing some code. We are going to create a Sub called "StartUp" that "Run" will call to create a graphics window. "StartUp" will look like this This will allow the game to make sounds, open a graphics window and load all of the resources to be used in the game. Next we will create a loop that will exit when the user wants to close the window. This will go after "StartUp was called in "Run". When the user hits the X or the Esc button it will close. The ProcessEvents will allows SwinGame to process events that have happend like the user pressing a key. RefreshScreen_WithFrame(60) will refresh the screen 60 times a second. After this we need to close everything, so we will create a Sub called "ShutDown". "ShutDown" will look like this This will free the resources and close the audio. GameLogic should look like this

Setting Up Data Types
First we need to set up our data structure as this will make it a lot easer to manage the game when it gets complex. For an Air hockey game you need: A game needs: A Player needs: A Table needs: Now that we know what we need to make a Air Hockey game we can now create the data types. First we will create a new module called DataTypes. Now we will create the game type. It should look something like this Now that the game type is created we can now make the player and table types. The player type should look like this The table type should look something like this
 * A game
 * 2 Players
 * A Ball
 * A Table
 * A Bat
 * A Score
 * A Goal
 * A Background
 * A Horizontal collision edge
 * A Vertical collision edge

Download
Here is a copy of everything that is covered in this tutorial [[media:Air Hockey Tutorial 1.zip|Air Hockey Tutorial 1.zip]]

List Of Tutorials

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