PSD Summer Scholarship 2006

Thursday, December 21, 2006

Werewolf Project

The Werewolf Project

The Werewolf Project is an online PHP application (game) created by "The Howlers" (Eyal Gross, Allan Jones, and Joost Funke Kupper). The game is based on lies and strategically plan who you are going to be friends with and who your enemies are.
The game is forum based, meaning you have to discuss and read the forum to stay on-top of the game.
The game starts of in a small village somewhere in eastern Europe. Your village is being terrorist by werewolves. As good citizens you try to kill the werewolves before they eat all of you. But the werewolves also live among you. So, the question is. Are your friends the enemy or not?

With this application you are able to:
  • register
  • login/logout
  • create new games
  • join the games
  • reply upon posts
  • vote for people who you want to kill
  • upload avatars
  • search the webpage
These are the main features that we had to work on. Also we had to create a solid database that can still be extended if we create new versions.
But before we could start creating the applications our first milestone were a couple (by which I mean 4) spikes to get us up to scratch on how to use PHP and MySQL. We have learned PHP before in Internet Technologies, but it was very very minimal, and MySQL in Database Analysis, and Design, but never how to use MySQL over command line or with PHP. So that was our first week.
If you want to have a look at our spikes you can go to our Scholarship groups website.

Our second week was preparing the application. The Planning and Design stage. This took a long time, just because we had to plan out the entire (or most of the) application. This also includes delegation of who is doing what and when.

Here is an image of the first initial database that we designed. It's a bit messy, but most of what we needed was one there. We made some alternations the more we worked on it, but this version worked fairly well.

After we had delegated all the tasks we started creating the basic pages that we needed. We decided (from some help of Clinton) that we were going to include php files into one index file. This way you are able to easily extend on it.

Ones we figured out how to use all the different php files to create a single page, it became very easy to build the different functionalities without having to write an entire new page. Pretty cool. So much more efficient.

After two weeks (3 days a week, so 6 days. WHO THINKS OF SUCH A TIME SCHEDULE!!) of coding we ended up with the product you see on the right. We didnt complete it, but we were very very close. The only thing that needed to be done, is when you join a game that you get the right role assigned to you, and fix up some small bugs like error checking and fixing the style sheet. And that would have been it. But we will complete it, no matter what, it's just to awesome, and we are way to dedicated :)

Tuesday, December 19, 2006

Finish line sighted, Escape From Swinburne progresses

Its been a while since any of us updated the blog; all the teams suddenly realised that their projects were a heck of a lot bigger than they thought they were. Features and documentation are being dropped left, right and centre to help bring the projects back on track. Frequent blogging was the first thing to go!

My project, Escape From Swinburne (EFS), has shed some features including multiple AIs and more complex animations such as skidding-to-a-halt. However, all is not lost. In fact, over the last three weeks great progress was made (remembering that a "week" is three days plus some voluntary time at home, for this Scholarship).

EFS has evolved into a side-scrolling 2D game that lets the player use a jetpack to jump over gaps in the floor and (hopefully soon) avoid enemies.

EFS now features:
  • Animated graphics
  • Collision system
  • World-scrolling
  • Sound and music
  • Dynamic frames-per-second (FPS) load-balancing
  • Loading from a file (dynamic map creation)
  • Jetpacking

Animated Graphics

EFS has implemented an animation system that allows any world object (an object in the game world such as the player or a floor piece) to have animations for certain actions. A world object, when loaded, can load as many image frames as it likes, then can specify what ranges of frames make a certain animation (eg. frames 10-19 are the left walk animation).

EFS provides the following animation hooks for world objects:

  • Walk left
  • Walk right
  • Stand still left
  • Stand still right
  • Jetpack left (no horizontal movement)
  • Jetpack right (no horizontal movement)
  • Jetpack left (horizontal movement)
  • Jetpack right (horizontal movement)

A small "fudge" has to be made with the current animation system because of a limitation in the collision system. The collision system can't deal with world objects that change width as they animate (since they might change width into a wall and get stuck). Hence, when animating, the player's (or any other world object's) width can never change and transparency must be used as padding. However, this means that players can seem to be able to step off an edge without falling (they are being caught on their transparent part). This is gotten around by putting a "shield" around the player at the edges of his bitmaps. It looks poor at the moment, but I hope to improve it.

Collision System

I wrote a complicated collision and movement system that uses vectors to control movement and some basic vector math (unit vectors etc) to detect collisions. Thank god I kept my Specialist Maths notes from school!

A main problem was that world objects could collide with something, but never butt right up to it (since their movement was cancelled because a collision would occur if it continued); there was always a gap. I resolved this by "growing" a movement vector pixel by pixel (using unit vectors) until the object either collided with something, or it was able to move by its whole vector. This meant that objects could "move as close as possible" to other objects, removing that gap.

World Scrolling

EFS lets you load a large wide image as a background to a level and will size the level to that image. It then lets the player move left and right around the level, scrolling the view as necessary.

A problem with this method is that every frame that is rendered has had the entire large background image painted. This is a very inefficient method, since only a fraction of the background is visible at a time, yet all of it is being painted. I have calculated that the painting of the whole background takes around 40-50% of the entire frame's rendering time: a massive inefficiency.
However, I lack the time to rewrite that system, what with the deadline fast approaching. Lucky today's modern computers can handle it.

Sound and Music

This part of EFS was cut back considerably. Originally I wanted each game object to be able to have their own individual sounds, but now there can be only three sounds: the background music, the player's walking sound, and the player's jetpack sound.

I grabbed some free sounds off the Internet and bashed them with a wave editor to make them sound slightly reasonable. However, they aren't the best; if you listen carefully you can hear artefacts and the sound repeating harshly. But they are quite okay.

However, as heavily cut back as this feature is, it still sounds great and does not detract from the experience.

Dynamic Frames-Per-Second Load Balancing

This part of EFS took me a long time (relatively) to do. The game speed in games should be constant and shouldn't be faster on faster computers. Old DOS games often have this problem. EFS has a dynamic load balancer that calculates data updates such as movement and collision every 16 milliseconds (62.5 fps) and the rest of the CPU's time is spent on rendering graphics frames as fast as possible (with a hard-coded max of 125fps to stop flickering). However, when the rendering framerate drops beneath 30fps, EFS will start sacrificing game data fps to speed up the rendering. The result: the game plays slower, but with a higher (but not that high) framerate. Modern computers almost never experience this.

This was achieved by using a "performance counter" from the Win32 API that counts time in microseconds (as opposed to a normal time getting function which get time accurate to around 10ms: not good enough). The game goes into a tight loop (maxing out your CPU) and only runs the data update once 16ms has passed. It will then only run a frame render when:

  • There enough time until the next data update is due taking into account how long it takes to render a frame (the renderer times itself so it knows how long it takes to render a frame) OR
  • The framerate has dropped below 31.25fps (a render hasn't run for 32ms)

However, it will skip renders if the framerate is over 125fps (a render was last run in the last 8ms).

My laptop manages around 80fps on one of my testing levels, and my main computer (much more powerful) managed 180fps until I put a cap on that to 125fps to prevent the flickering that occurs at very high framerates.

I created fps meters in the top-left corner of EFS, to show the player their current, highest, and lowest fps for the game data and the graphics rendering.

Loading from a File

EFS will load its levels from map files. This means you can create levels on the fly without changing the source code of EFS just by editing a few text files.

Unfortunately, EFS has become so complicated that creating these text files is time-consuming and difficult. I had to create a template in Excel to help myself since the files get very complicated. A visual level editor is needed, but I don't have time to create one. :(

Jetpacking

The earlier revisions of EFS did jumping by adding an upwards movement vector against the downward vector of gravity. By holding down spacebar, you were able to continue adding that upwards vector against gravity and accelerate upwards at a great rate. I liked the "feature" so much, I decided to dump "jumping" and keep this "jetpacking" functionality instead. However, to limit their usefulness (otherwise the game would be ridiculously easy as you would be able to just fly across the top of the level), I implemented "jetpack fuel" which uses up as you fly and recharges when you don't. An onscreen progress bar is painted to show the jetpack fuel status.

TODO: Real Map(s)

At moment, I've created a simple dodgy testing map with my stellar (read: awful) drawing skills in MS Paint. It looks like a drawing out of a kindergartener's book. Even my dear old mother thinks its poor. Take a look at the screenshots to see what I mean.

The plan is, for the real maps, to take a picture of outside in Swinburne somewhere with a panoramic camera (for the wide angle) and then gaussian blur it in Photoshop to create a nice background for the levels. I have tried this before with Eyal's camera phone and it came up nicely. It is a technique I am pinching for some webcomics that use it for the backgrounds on the panels.

Then I will have to create the levels, which will be a pain because of the file format. Hopefully I can make something good in the time I have left. :|

TODO: AI

The very last feature of EFS I aim to get in before the deadline is a really stupid AI enemy. This AI will move left and right (changing direction when it hits something) and when the player touches it, the player will die.

This will require not only new code for AIs, but also changes in the collision system that will allow something to happen when the player collides with an AI, and allow the AI to detect when it hits a wall so it can move the other way.

I'll probably hack these changes into the code nastily just to get the feature done in time. I have a feeling that to get it done "properly" (ie not completely crap and limited) I will need a serious revamp of a lot of EFS (collisions, the game loop, etc). So we will see whether this feature makes the final version or not.

Wish me luck.

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:

Tuesday, November 28, 2006

The PSD Project Team


Welcome! We are the PSD Project Team, a small group of students participating in the current 2006 PSD Summer Scholarship program.

The PSD Summer Scholarship program is a four week program designed to improve and refine the skills of a select group of students. The basic structure includes the creatiion of small programs, websites, databases, tutorials and documentation. The three projects that are created are the "Escape from Swinburne", "Minesweeper", and "Werewolf Project".
To view more information about the Scholarship projects you can go to the 2006 PSD Scholarship website.

The "Werewolf Project" is produced by the Howlers. The three students that are in this group are Eyal Gross, Allan Jones, and Joost Funke Kupper.
The project is an online game developed using HTML, PHP and MySQL. This game will allow user to create an account, selecting different formats of the web-page, and join several games at the same time.
To view more information about the creation of the project you can go to the Werewolf Project website.


Monday, November 27, 2006

PSD Summer Scholarship 2006 Pict Blog

Welcome to the PSD Summer Scholarship program for 2006. This blog will contain pictures related to the work undertaken as part of this project. Further details of this project can be found on SwinBrain.

This program was undertaken by