Dec 05 2010

Turn down that noise!

I now have fully deformable terrain! Srsly, click the read more and try the game! :)

If you didn’t guess from the title, I’ve added sound to the 16k game. This was kind of interesting. Generally, I’ve done sound by embedding mp3 files in my games. So my first attempt was to generate some sounds– shots and explosions with sfxr, then package them as 11khz mp3s in Audacity. Unfortunately, the smallest I could pack the mp3s was about 3kb.

I tried embedding one of the explosion sounds into the previous build, but the release size went up from 8.88kb to 11.9kb. I only wanted 2 sounds, so that was doable, but it would eat up all my remaining space and I’m not quite done adding features to the game.

The other option is to use FP10’s ability to dynamically generate sounds. Dr. Pettersson (the guy who wrote sfxr in the first place) gives a good overview of sound synthesis here. If you need an overview of how to actually do this in AS3, see here. After playing around with noise for a while (varying how long each amplitude was being held), I eventually got an explosion and shot sound I could live with. (EDIT: Forgot to mention, to provide some additional situational awareness to the player, the volume of the explosions and shots is proportional to the distance of the player to the sound. I did consider also adjusting the Left/Right levels based on the relative x/y of the sound and the player, but haven’t implemented that yet if at all. It’d be hard for me to test, since I’m working on a laptop.)

Unfortunately, I thought this led to a game that was a little too ‘sparse’ sounding. I needed to add a sound track. Again, this isn’t too difficult, I just used sine waves as my ‘instruments’ as depicted in the second resource. However, making 8192 (or multiples thereof) calls to Math.sin() every time the buffer needed to be refilled was a performance hit I couldn’t take. So I changed the game to pre-calculate those values for every note when it is loaded (just 3 octaves from A3->A7) and store them in an array (wavetable). This was the first performance optimization I needed to make in this entire project.

I also found I was getting a clicking sound every time the notes changed. So, switched from feeding the raw wave amplitudes to fading the notes in and out. (Apparently my speakers don’t like abrupt changes in the waveform coming to them.) That covers playing notes… to actually play a tune I store the score in a class I creatively called ‘CScore’ which also tracks where in the score the soundtrack is currently playing. A method in that class returns the indexes of the wavetable for the notes to be played.

Every time the sound buffer needs to be refilled, the next note is called. This happens every 1/5th of a second… so my CrummySynth is locked at about 240bpm. I actually designed the melody 4 bars at a time using a website for children checking to make sure they weren’t too discordant. (I don’t have composition software) Then, because CScore understands notes by semitones above A3, I encoded each melody by hand first into the lowest octave and then into the middle. To make everything string together, each 4 bar melody starts on a C (stop laughing Meg).

Honestly, in a production game where embedding or streaming wasn’t an option, I’d rather just use FLOD.

To keep everyone sane, I added a Mute at this time as well. Press M to turn off the sound.

Right, so with a soundtrack of sorts, the game was starting to look and sound good. One thing that had been bugging me is that I had set the center of my collision spheres to be the center of rotation– basically the (0,0,0) coordinate for the enemy tank models. As a result, you could shoot under the center of the tanks to kill them. Since the game did need a little more stuff going on visually, I added a check to the shot movement code, to see if the shots were moving underground. If so, I added an explosion… That looked ok, and while playing that version I realized I could decrease the height of the terrain where the shot impacted. Thus deformable terrain. Wikipedia is remarkably mealy-mouthed on the subject of which game was the first 3D game with deformable terrain. If anybody knows, leave a note.

Click the read more to play the current build. Release build is now 10.8kb. Any comments are welcome… but I’m particularly interested right now in whether the game is running smooth or not on different computers.

Read more »

Dec 03 2010

Breaking the Plane

Battlezone (1980) had a unique control system where the two joysticks on the arcade cabinet controlled the left and right treads of the tank. We can’t really duplicate that well with a keyboard, so to keep the two handed gameplay, this version of my game separates the turret and tank controls. I can’t remember seeing this in a game prior to Mechwarior (1989), but surely something had used it before.

The other major step was to take the flat terrain, and replace it with a rolling random terrain. This causes the player (and enemies) to pitch and roll as they move across the ground. As far as I know, none of the ‘action-tank-sims’ had this type of 3D movement until Arctic Fox (1986). (subLogic however, had released their first consumer flight sims by 1980, suggesting the early 8-bit machines would have been capable of it).

Since I’m getting close to done, I’d appreciate any comments. Game and instructions placed after the ‘read more’. Next step will probably be to add sound… Current release build, 8.88kb.
Read more »

Dec 02 2010

Enter the Zone

So, Battlezone was a wire-frame 3d arcade game produced by Atari, initially released in 1980. It may have been the first game to use a 3d environment of any type. If you actually want to play Battlezone, you may wish to visit and play the official web port.

What’s presented after the read more is a much more limited version of the game, developed as an intermediate step towards my entry in the 8bitrocket 16kb web game contest.
Read more »

Nov 28 2010

Hello Wire

Unless you really want me to take pictures of my (paper) notebook on which I worked out the trig for this, there’s not too much in this update.

.swf after the jump. Pretend it’s lime green and you know which game I’m patterning after. :)
Read more »

Nov 28 2010

Small World

Over at 8bitRocket, back on 19 November they announced* a contest to produce a retro web** game. Specifically, a game which is inspired by an Atari*** game, with an executable package**** not to exceed 16kb. For the non-tech types, that’s pretty small these days.

*- I need to give a shout out to Gaming After 40, because I saw the announcement repeated on his blog. I happened to be extremely busy on the weekend of the 19th, and missed 8bitRocket’s original post.

**- web being any web platform– Silverlight, Flash, HTML5, Javascript, if you could do a small enough Unity game I imagine it would be ok…

***- Atari being defined extremely broadly.

****- ie: the program and all the resources it’s going to use.

Anyway, I’m going to build an entry, and I’ll try to make posts as I progress. Click the read more for the first.
Read more »