Adding Sound and Music
Click Here To Load The Tutorial program Directly Into The Editor
SWARM-26.DBA.
Throughout the construction and testing of this game, you will have had the nagging suspicion something was missing.
It is not until you remove a thing that you realise its importance. We are of course speaking of sound effects and background music.
Replace the line REM * HERE A * to read:
rem Load and play music
load music "swarm.mid",1
loop music 1
Add these two commands and your game has continuous music, its that simple. If you are feeling ambitious, you might like to find another music track for your game. Almost all files that carry the .MID extension are known as MIDI music files and can be played as shown above.
Replace the line REM * HERE B * to read:
rem Load sound effects
load sound "wav\lasergun.wav",1
load sound "wav\edestroy.wav",2
load sound "wav\pdestroy.wav",3
load sound "wav\ping.wav",7
set sound speed 7,30000
Replace the line REM * HERE C * to read:
rem Level up sfx
play sound 7
Replace the line REM * HERE D * to read:
rem Player destroyed sfx
play sound 2
Replace the line REM * HERE E * to read:
rem Enemy destroyed sfx
play sound 3
Replace the line REM * HERE F * to read:
rem Player firing sfx
play sound 1
Simply load and play. Just as .MID files hold music information, WAV files hold sound effect information. The SET SOUND SPEED command is used to alter the pitch of the loaded PING.WAV sound effect to give it a higher tone. Pressing F5 will now present you with a game that feels a lot better than it did five minutes ago. With additional enhancements such as explosions, stellar plasma backdrop, different aliens and even a mothership you can make your game look and feel more complete. To give you some idea, try the last program in our source code series that advances what we have done in this tutorial.
Click Here To Load The Full Game Directly Into The Editor
SWARM-28.DBA.
Not only have you traversed weeks, if not month’s worth of game making knowledge, you have created a game entirely by yourself. Everything else you choose to learn from here on is merely icing on the cake. The important part of every game is the core functionality and the playability that stems from it.
This tutorial has hopefully armed you with a few basic skills, and given you an understanding of how a simple game is pieced together. With a little time and practice, there is nothing you cannot create. The principals covered here are equally valid to any type of software you can think of.
You are invited to visit the official DarkBASIC website to join a growing community of novice and expert programmers who are enjoying the freedom that comes with creating their own software. You'll be able to participate in an interactive forum, get help from fellow users, download source code and media resources, all in the comfort of your web browser.
Join in the fun at www.darkbasic.com and we hope to see you there!