PSD Summer Scholarship 2006

Tuesday, December 05, 2006

Escape from Swinburne First Step Completed

The Escape from Swinburne project, which I am responsible for, consists of two parts:
  • The SwinGame API: Written in Pascal, it provides an easy to use API that next year's PSDs can use in their Algorithmic problem solving subject. The API provides them with the ability to draw to the screen with images and primitives, read mouse and keyboard input, and play and mix sound.
  • The Escape from Swinburne game: A small side-scrolling 2D game similar to games such as Commander Keen, written in Pascal and demonstrating the use of the SwinGame API

Recently, I just finished the first step of the project: a spike (learning task) on drawing, input and sound in Pascal. Drawing and input were no problem (besides the inevitable revision of the Pascal syntax that I learned half a year ago (easy)) as they have been handled by the WinGraph, WinCRT and WinMouse units, but sound turned out to be more difficult than it looked.

The first approach I took to sound was to try to play it through the Win32 API. I used the PlaySound() function, only to find that PlaySound() does not play two sounds at once. It either cuts off the first sound and plays the second one, or doesn't play the second one. Pretty useless in a game that needs to be able to have background music and multiple sounds of action happening.

The next approach was the next logical step: use DirectSound. Unfortunately, because all this is written in Pascal and DirectSound is normally used from C or C++ programs, the first hurdle was getting access to the DirectSound APIs. This wasn't so hard, since I found a unit that wrapped up all the external calls nicely for me.

The next problem was figuring out how to use DirectSound. I got three books from Andrew and Clinton, one DirectX 5 (OLD!!) and two DirectX 9 books. Ironically, the DirectX 5 book was the best of the lot. The DirectX 9 books either talked about DirectMusic, a lower level DirectSound type thing that I really didn't want to get involved in, or had missing details such as how to actually load a sound (that was particularly useless).

Eventually, I came to a point where I realised the function that people use to load a wave file into memory for DirectSound isn't actually part of DirectX and is part of something else, which I couldn't access from Pascal because it was written in C++. Net result: DirectSound was a complete failure.

Then Andrew and I hunted around a bit more and found the OpenAL library and a unit for using it in Pascal. I was able to use OpenAL successfully (since it included wave file loading functions).

All these things I learned along the way culminated in a little program that lets you draw stuff (pixels or bitmaps) on its window with the mouse and play two sounds at once by pressing a keyboard key.

I then wrote a HowTo article explaining how to use WinGraph for drawing, WinCRT for keyboard input, WinMouse for mouse input, and OpenAL for sound. That is a long article!
And then, finally, to finish it all off I had to create a short 5 minute presentation showing what I did. I had to create this presentation using the "Beyond Bullet Points" presentation style. Although, during the semester, I've been imitating this style (as I've seen it presented by Andrew) in my own presentations, this time it was different since I had to do it by the book. We were given a template to fill out that details the logical steps that the presentation must take to establish itself, present its information and then conclude cleanly. That was a lot more time consuming than expected and took around half a day to do! Apparently, you get faster at it when you do it more.

You can see what I've done here:

0 Comments:

Post a Comment

<< Home