Air Hockey Tutorial 7

From SwinGame

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.

This page contains a Tutorial. Tutorials are designed to walk you through the development of a small game.
Warning: You must have completed the previous tutorial(s) to go through this tutorial

Contents

How To Get Sound Effects For Your Game

Here is a site that I have found very useful for getting sound effects. [link] The only bad thing is its all in Japanese. To get to the sounds go to that page, then click on the ""FREE" MATERIALS" link. Now go to ""FREE" SOUNDS". All the sounds are here, but if you cant read Japanese like me its a bit hard to work out what they each sound like. To fix this you can download all of them at once. To do this click on the "zip" link. This will take you to a were you can download all the sounds easily. Now you need to download, se_pack01.exe, se_pack_06.exe and se_pacl07.exe. Run those 3 files and you will have 1377 sound effects.

New Resources

At this point in the creation of the game new images were made for it, they can be found here along with the sounds. As there the new images are different we will need to change a few things. One of the things that will need changing is the constants. Theses will now be.

Public Const TopOfTable As Long = 68
Public Const BottomOfTable As Long = 530
Public Const RightOfTable As Long = 685
Public Const LeftOfTable As Long = 315
Public Const MiddleOfTable As Long = 300
Public Const CenterOfTable As Long = 500

Next we have to change where the score is displayed. This will be changed to.

Call Text.DrawText("Red", black, GameFont("CourierBigger"), 120, 165)
Call Text.DrawText("Blue", black, GameFont("CourierBigger"), 120, 345)
Call Text.DrawText(Game.Players(1).Score, black, GameFont("CourierBigger"), 135, 210)
Call Text.DrawText(Game.Players(0).Score, black, GameFont("CourierBigger"), 135, 390)

Loading The Sounds Effects

We now need to load the sounds that we are going to use.

Private Sub LoadSounds()
    Call NewSound("Ball hit bat", "bosu06.wav")
    Call NewSound("Ball hit side", "hit15.wav")
    Call NewSound("Ball in goal", "koro00.wav")
    Call NewSound("Bat hit side", "bosu07_b.wav")
End Sub

Playing The Sounds

The first sound effect we will add is "Bat hit side", this will get checked in "MoveBat" and we will check if it has hit the side just after we call "MoveSprite".

If Physics.HaveSpritesCollided(Game.Players(i).Bat, Game.TablePics.TableHorizontal) Or Physics.HaveSpritesCollided(Game.Players(i).Bat, Game.TablePics.TableVertical) Then
    Call Audio.PlaySoundEffect(GameSound("Bat hit side"))
End If

Now we will add "Ball hit bat" this will go in "MoveBall" right after we have the "VectorCollision" if the bat and ball hit.

Call Audio.PlaySoundEffect(GameSound("Ball hit bat"))

The next sound to add is "Ball in goal" the will also be called in "MoveBall" after we check if the ball has gone in the goal. This will go in two places.

Call Audio.PlaySoundEffect(GameSound("Ball in goal"))

The last sound is "Ball hit side" and this will be called in "KeepBallOnTable", this will be called after we check if the ball has hit one of the side.

Call Audio.PlaySoundEffect(GameSound("Ball hit side"))



List Of Tutorials

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