Contact

 
Google
Web www.alanphipps.com

 
   
 
   
www.alanphipps.com

.: Game Aesthetics

 
 

This tutorial will simply make the game look and sound better and hence give the player a more pleasant experience. So, as normal, source code, last tutorial and now we will begin. First of all, being a Sci-Fi fan and having a degree in Physics I chose a theme based on the planets in our solar system, four planets to be precise, each representing a different colour. The Sun was yellow, Earth was Blue, Mars was Red and Uranus was green, I then downloaded some photos from the Solar Views website and using Paint.NET , created the designs that would be used i the final version of the game. I wont explain how to use these programs because there are plenty of tutorials on the net, but I will explain the code that was used to display them in the game.

When the theme objects were created they were initialized at the same time as the other objects and are given the blue theme. The other theme versions were selected at random during the GameState = "Loading" process of the game. Every time a game is lost or won the theme is randomly changed. I chose this method for simplicity but you could change this so that the theme is changed whenever you like, such as after a certain number of levels have been played, it is entirely your choice.

 

This theme change was implemented with the following code in the Graphics Module:

'Sub that selects the pictures used
Public Sub SelectTheme()
Dim x As Integer = RandomizePub.Next(1, 4)

Select Case x
Case Is = 1
ThemeTex = Texture2D.FromFile(Device, "../../images/Earth.png", NonBallTexCreationParams)
RoofTex = Texture2D.FromFile(Device, "../../images/RoofTexEarth.png", NonBallTexCreationParams)
BallLauncherTex = Texture2D.FromFile(Device, "../../images/BallLauncherEarth.png", NonBallTexCreationParams)
BackgroundTex = Texture2D.FromFile(Device, "../../images/BackGroundEarth.png", NonBallTexCreationParams)
Case Is = 2
ThemeTex = Texture2D.FromFile(Device, "../../images/Sun.png", NonBallTexCreationParams)
RoofTex = Texture2D.FromFile(Device, "../../images/RoofTexSun.png", NonBallTexCreationParams)
BallLauncherTex = Texture2D.FromFile(Device, "../../images/BallLauncherSun.png", NonBallTexCreationParams)
BackgroundTex = Texture2D.FromFile(Device, "../../images/BackGroundSun.png", NonBallTexCreationParams)
Case Is = 3
ThemeTex = Texture2D.FromFile(Device, "../../images/Mars.png", NonBallTexCreationParams)
RoofTex = Texture2D.FromFile(Device, "../../images/RoofTexMars.png", NonBallTexCreationParams)
BallLauncherTex = Texture2D.FromFile(Device, "../../images/BallLauncherMars.png", NonBallTexCreationParams)
BackgroundTex = Texture2D.FromFile(Device, "../../images/BackGroundMars.png", NonBallTexCreationParams)
Case Is = 4
ThemeTex = Texture2D.FromFile(Device, "../../images/Uranus.png", NonBallTexCreationParams)
RoofTex = Texture2D.FromFile(Device, "../../images/RoofTexUranus.png", NonBallTexCreationParams)
BallLauncherTex = Texture2D.FromFile(Device, "../../images/BallLauncherUranus.png", NonBallTexCreationParams)
BackgroundTex = Texture2D.FromFile(Device, "../../images/BackGroundUranus.png", NonBallTexCreationParams)
End Select
x = Nothing
End Sub

This sub is called during the GameState = "Loading" section of the Render loop.

In the last tutorial I did not include the complete wavebank as it included a large wav file. This wav file made the wavebank 45 Mb and hence I chose to have the file removed from the source code. Having done a little research, I have found that the entire wavebank or an individual file can be compressed using the XACT tool, however the wavebank was still 9Mb and still too big. The XACT tool only uses wav files and the music I have are Midi files.

So, until the XACT tool supports Midi files, I will be using DirectX to play the background music. This code was added in the sound class as follows:

Module SoundModule
Public AudioEngine As AudioEngine
Public WaveBank As WaveBank
Public SoundBank As SoundBank
' Thread and Sound to be used for playing the background music
Public MusicThread As Thread
Public MusicTrack As New Sound

'Temporary DirectX Audio object to play Midi files
Public DirectXAudio As New Microsoft.DirectX.AudioVideoPlayback.Audio("..\..\Audio\Sonic.mid")

'Sub that selects which music to play
Public Sub SelectMusic()
DirectXAudio.Volume = -3000
Dim x As Integer = RandomizePub.Next(1, 4)
Select Case x
Case Is = 1
DirectXAudio.Open("..\..\Audio\GoldenAxe.mid", True)
Case Is = 2
DirectXAudio.Open("..\..\Audio\Sonic.mid", True)
Case Is = 3
DirectXAudio.Open("..\..\Audio\StarFox-Corneria.mid", True)
Case Is = 4
DirectXAudio.Open("..\..\Audio\Zelda.mid", True)
End Select
x = Nothing
End Sub

End Module

As you can see the new code is actually in the sound module and not the sound class. The DirectXAudio object is initialized using one of the midi files that are included with the project, when the SelectMusic sub is called, the next Midi file is randomly chosen. This sub is called from the Render loop as its last operation:

'Check if Audio is playing
If DirectXAudio.CurrentPosition >= DirectXAudio.Duration Then
SelectMusic()
End If

End Sub

As you can see this sub comes right before the render loop ends. Please note that this new code requires that you add the Microsoft.DirectX.AudioVideoPlayback reference in the project properties. The SelectMusic sub is initially called from the Form1_Load sub as shown below:

'Play Background Music
SelectMusic()

New code has also been added to the Form1_KeyDown event:

Case Is = Keys.Pause
If GameState = "Playing" Then ' If a game is in progress
GameState = "Paused"
'Check if Audio is playing
If DirectXAudio.Playing = True Then
DirectXAudio.Pause()
End If
GameStopWatch.Reset()
GameStopWatch.Start()
ElseIf GameState = "Paused" Then ' If a game is in Paused
GameState = "Playing"
'Check if Audio is playing
If DirectXAudio.Paused = True Then
DirectXAudio.Play()
End If
GameStopWatch.Reset()
GameStopWatch.Start()
End If

'Pause the background music with the enter key
Case Is = Keys.Enter
If DirectXAudio.Playing = True Then
DirectXAudio.Pause()
ElseIf DirectXAudio.Paused = True Then
DirectXAudio.Play()
End If

This ensures that when the game is paused, the music stops playing too. A new key has also been added, the enter key gives the player the option to turn the music on and off, just in case they don't like it.

With the exception of a few changes that affect game play , that's all the code changes for this tutorial, the rest of the time was spent in Paint.NET. Feel free to create your own theme or to use mine. When you play the game you should see this:

XNA in VB.NET - Earth Theme

XNA in VB.NET - Sun Theme

XNA in VB.NET - Mars Theme

and lastly

XNA in VB.NET - Uranus Theme

Doesn't it look nice :)

That's basically the game finished, with the exception of the content pipeline. The content pipeline is something that is built-in to Game Studio Express and hence I don't know how easy it's going to be to incorporate it into our project. However, on the plus side, I do enjoy a challenge and will give it a shot. I don't know how long this will take, but as usual when I'm done, I'll upload it to the tutorial page, Enjoy.

 

GameAesthetics Source Code - 2,791Kb
Next Tutorial - Adding Microsoft.XNA.Framework.Game

 

     
 
 
     

 

Web site contents © Copyright Alan Phipps 2006, All rights reserved.
Website templates
   
 
 

 

__PayPal

PayPal - Any Amount is Welcome
 
Please Donate to the Nvidia Geforce Go 7950 GTX Fund, All donations welcome. Thanks.

 

XNA in C#

 
 

 

Games at Amazon