The Making Of...: The Making of Rocktoids
by Krylar

UPDATED!

Please note that this article was updated on 7/28/2001, and so was the source code, in order to comply with the 1.50+ versions of Blitz Basic. The Sound commands changed after this article was originally published and users of later version were unable to compile the code cleanly. This should no longer be a problem for registered (and updated) users of Blitz Basic. Demo users may not be able to successfully compile this code.

Introduction:

When I thought about writing up a first game to see what I could accomplish with BlitzBasic, the obvious one was "Asteroids"! Why? Because I couldn't think of an easier game technologically that was also fun to play. No worries about tiling or scrolling the screen or AI. Simply put up a ship and a bunch of asteroids, move the asteroids around and let the ship try to shoot them.

Also, since the game has been so ingrained in my mind since childhood, I didn't have to worry about design issues. I could just jump in and code.

The Graphics

Okay, while I'm not an critically acclaimed artist, I'm not exactly terrible either. However, since I'm still learning the ins and outs of trueSpace 4, I decided to forgo my own graphics (except the asteroids themselves...though they don't really look like asteroids...sigh) and use the graphics that come with SpriteLib. SpriteLib is a collection of 2D sprite graphics developed by Ari Feldman (thanks, Ari!) for non-commercial, public-domain use. If you're looking for placement art to try things out, you should check out SpriteLib at http://www.arifeldman.com/games/spritelib.html.

Using SpriteLib, I found all the images I liked (Ship, Bullets, Explosions), cut them out and worked out the loading in BB. After loading the images, I used the RotateImage command to get the image facing all appropriate directions.

The asteroids I created using trueSpace 4 as a test. They're really strange looking, but I'm okay with that ;) My 9 year old son Jake gave the suggestions of adding the spikes to them...I think that was a great suggestion! I'll probably consult him on future endeavors ;)

The splash screens are just graphics that load up to show the player who made the game and such. The Christian Coders Network graphic was developed by my wife and I through tons of fiddling in Paint Shop Pro. The Krylar's Kreations graphic (my little game company) was developed by a REALLY amazing artist named Jeff Jumper. Jeff used to work with me at ENGAGE games online, though at the time of this writing Jeff is at Interplay.

The explosion animations were laid out in a BMP file side-by-side with accurate spacing so I could ensure that the full animation would be loaded correctly. Whenever a collision occurs, I simply draw the appropriate frame based on a timing constraint. I constrain time so the explosion animation is smooth to the eye.

The Music

I purchased a package called Fruity Loops to do the music. Using this tool, one can visually create cool rythms and such, while adding funky sounds and effects. I've been playing the guitar since I was 9, so music is pretty second-nature to me...but I don't care how little talent you may feel you have for music, you should be able to accomplish something cool with this product. To give you an idea, the little rocktoids diddy was done in 5 minutes. I know it's not amazing, but it was SIMPLE!

I actually got pretty lucky with the music timing from the initial splash screens to the game screen transition. If you watch the full splash screen intro without space-bar interruption, you'll see that the heavier section of the music bounces in right at the moment the ship appears. That was not intentional, but it sure is cool ;)

To play the music and such was accomplished through the use of the PlayMusic command. There are a couple of problems that I have with BB's music commands, and I have yet to get any response from the BB folks on these...but I'm hopeful that they're just really swamped trying to release the commercial product and will get back to me eventually.

The issues that I have are:

  • There doesn't seem to be a way to load a music file into memory. This is important because each time I call PlayMusic the .mp3 file is read from the disk, which causes a little skip on my frame rate. Because of this, I only play the .mp3 once and don't start it up again. This isn't a big deal for an Asteroids-clone, but it will become a bigger deal when trying to use music on larger, more persistent titles.
  • There doesn't seem to be a way to control the volume of the music with BB. I know that you can control the volume of sounds (like explosions and stuff), but music is as loud as it is when you save it. This is bad because each player is different in what they want their sound/music configurations set to.

The Sounds

Engines, explosions, lasers, and various other sounds are tough to create and make sound good. Most of the sound effects I've seen created are done so with painstaking detail...more detail than I'm willing to give ;) Since I wanted to use sounds that I could own the rights to use without having to pay royalties, I searched and searched the web. After much hunting, I stumbled across The Sound Effects Library.

This library has a bunch of really cool sounds and they are reasonably priced. I bought 15, royalty-free, high-quality sounds for $25. That's pretty cheap when you consider trying to make sounds yourself. Additionally, I now "own" the use of these sounds in any project that I put together.

I did find a few sound sites out there that had free stuff, and I certainly don't want to put those sites down, but there's something to be said about "owning" the rights to sounds so you can avoid legal issues in the future.

Anyways, loading and playing sounds in BB is simple. One thing to keep in mind though is that if you try to play a sound while that sound is already playing (i.e. two explosions back-to-back), you'll find that the first explosion is cut off when the second one begins. With a game like Asteroids, this is no biggie. But for better immersion, you may consider having a number of explosion pointers so they can overlap.

The new channel commands have plenty of features, but I found that when using StopChannel other sounds would stop as well. So I avoided using the Channel commands as much as possible. I have seen on the Blitz Basement boards that others have had this problem as well, so hopefully the good folks at BB are working to fix this.

Another thing I didn't do was play around with the panning and effects. Also, I didn't try to use any 3D audio stuff...to be honest I don't even know if BB supports 3D audio stuff yet.

Gameplay specifics

2D Space Physics:

Since I wanted to have some pseudo 2D space physics associated to the ship as to avoid immediate directional changes and such, I used the techniques described in the 2D Space Physics and More BlitzBasic tutorial that I wrote with this purpose in mind.

From there I changed the concept from moving the background relative to the ship, to moving the ship relative to the background.

Weapons:

In order to have a weapon look like it's firing from the ship, I had to do a couple of things. First off, I had to base the weapon's starting position to be in the middle of the ship. Secondly, I had to make sure that the missile was using a frame that was facing the same direction as the ship. Third, I had to draw the missiles FIRST and then the ship...this was to avoid having the missile appear to launch from the top of the ship. And finally, I had to add to the missile's speed to the current speed of the ship so the missile would always travel more quickly than the ship, but remain relative to the ship's speed.

I made a decision on the clipping aspect of the missiles too. In the real game of Asteroids, the bullets could fly off the screen and appear on the opposite side. I had this going, but it really looked goofy so I decided to clip the missiles at the edge of the screen. You can certainly go through the code and change this logic, but I was unhappy with the results...so I clipped ;)

Collisions:

I opted to use the ImagesCollide function for collision detection since it provided pixel-perfect detections, and since the game was really not so graphically intense that it would greatly suffer in speed.

I learned that if you're not careful, you could accidently compare the wrong images (based on your logic) and would get strange results. For example, I accidently compared the big asteroids instead of the little ones (and vice-versa) due to a logic error. So, I was able to fly through pieces of the big asteroid, but I would explode when I was a good distance from the little ones. Watch out for goofyness like that ;)

Goodies:

I wanted to have a 7 second shield when the player starts. I thought it was lame to blowup because you appeared right when an asteroid crossed your path. So I added that and updated the graphic appropriately.

Since I've always liked the power-up concept, I put in one. The little skull and crossbones image that flies around is a power-up. If the player runs into that I decrease the firing delay so bullets can really move out of the ship. Also, note that the ship image changes and a sound is played.

Finally, to keep consistent with the original game, I split up some of the asteroids into smaller pieces when hit. Not all of them, just ones randomly selected to have the "split" flag. And those asteroids that do split may have up to 3 rocks break off, all at different speeds and at different angles.

Also, you may want to note that all of the asteroids spin at different speeds. I did this so the screen would look as though there were 20 asteroids spinning in unison...that looks REALLY weird.

Scoring and Stats:

To give a little retention factor, I do some simple calculations for scoring and such. Player hits an asteroid, they get points...they blow up, they lose points. If the player clears a level, the player gets an extra ship as a bonus (up to the maximum number of ships).

For fun, I also keep track of the number of bullets fired, and the number of hits. Then, at the end of each level, I give a tally to the player so they can see how good their hit percentage is.

Conclusion

This was a fun little project that took me about 10 hours from start to finish to complete, excluding music and sound purchasing and all that. This is just another demonstration as to what an amazing tool BlitzBasic is. I would estimate that if I had done this same project from scratch, coding all of the DirectX interface routines in C/C++, debugging, etc., it would have taken me close to 6 months to do...and that's assuming I was REALLY focused on the project. Under my current schedule, I'd give it a year.

To download the game and full source (a little over 2 meg, updated on 8/11/2001): Click Here.

Anyways, feel free to play around with the code and make additions and such...most importantly, have fun!

Until next time...cya!

-Krylar


For a printable copy of this article, please click HERE.


This site is Copyright© 2000-2004, BlitzCoder. All rights reserved.