I’ve been experimenting with sound, and the results are pleasingly straightforward. After appropriate linking and placing of files, it takes a total of six very simple lines of code to load a .wav and play it at full volume. The code to handle sound location and such takes more, but it’s still reasonable, especially since it’s managing all the required data already for openGL. One thing that surprised me, though, is the way sources (things which can emit sound) are handled in OpenAL: they’re as close to physical objects as it gets, having position and velocity data, so it seemed natural that I’d attach one to each ship and attach and play buffers (which contain the loaded sounds) as necessary. Instead, each source can only play one sound at a time, so I guess ships will hold a variable number of sources, and I’ll add them and subtract them as necessary. Their method does make sense for things like explosions and projectiles which will only ever make one sound, though.
One thing I have learned is that there is apparently no limit to the number of times I can be surprised by the test explosion that plays when the game fully loads.
Of course, the next thing I did was spend a day on freesound looking for reasonable explosion, shooting, laser, and engine sounds. Ends up finding a good explosion is quite hard, and engine sounds are quite easy- I’m talking about that low hum you always hear on any scene in a spaceship in most science fiction shows. Perhaps because recording explosions is inherently dangerous and difficult, while recording your washing machine and running it through a few effects is something you can do without changing out of your pajamas.
Anyway, I thought, “Well, might as well have the engine sound definable in player.xml”.
But I didn’t have a player.xml yet. That was the last thing that still loaded from a white space-delimited text file. So I’d have to add that.
But then I might as well have it define what equipment the player is using, instead of raw stats like “thrust” and “size”.
But then I’ll have to write equipment.xml, to define the equipment player.xml is now using.
And of course all this requires the code to load all that .xml into more useful data structures. Special care must be taken with the equipment data, since I’ll almost certainly want all that neatly accessible by LUA at some point.
So, that’s all done now. Also done: projectiles shot by enemies can impact the player’s ship as well as each other, and explode when applicable. The AI is quite accurate with projectile fire- deciding how to write the motion-prediction code behind having the AI decide where to shoot was a significant decision, and the results are pleasing. Dodging incoming fire is difficult, but not impossible. I was thinking about adding in an acceleration term to the AI projectile aiming target path-prediction algorithm, but that might actually be a bit over the top.