Archive for the ‘ game development ’ Category

Starting off Chomper

I actually been working on Chomper piece by piece for a while. I didn’t bother posting a bunch of posts but gather it all into like “Milestones” stages.

I am starting fresh. While I have the old “working” project, I didn’t want to just cut and paste the old code into the project because I wanted to…

  • understand everything again
  • optimize the code to be better structured (as I had 2 months to make that game before)

Here are some points of the current progress.

Start of the new project

I used the MFC wizard to create the base application of Chomper. I decided to use the Visual Studio theme because it looks clean and nice. Other than the extra options on the wizard nothing much is different like the 1st time I used it with the original game.

Disabling Dockable Tool Bars

I had a problem with disabling the docking ability of the tool bars. In the code it had the following…

// TODO: Delete these five lines if you don't want the toolbar and menubar to be dockable
m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_wndMenuBar);
DockPane(&m_wndToolBar);

Sounds simple right? But commenting those 5 lines screws up the tool bar entirely! So that comment was not useful at all.

The solution was to just comment the first two lines and then the tool bars will be docked.

Disabling the registry

Another “feature” I wanted to disable was the writing to the registry. The reason why I don’t like using the registry is that

  1. This is a game. Not a program that will be used throughout the system.
  2. I prefer the settings to be in a file so that is easier for people to back up. Try telling a newbie how to backup the registry or worse backup up a specific “key” and watch them screw up their computer.
  3. There is a convenient place where each users settings are stored (C:\Documents and Settings\<USER>\Application Data\ by default)

Now I know which line does it. And that’s this…

SetRegistryKey(_T("Local AppWizard-Generated Applications"));

In my previous MFC applications, all I do is comment this line and all is well. However, not for Feature Pack though. Comment this line and you will get an assertion error. The reason I believe is because of the customizable “Workspace” feature. If you check the registry you will see that there is additional entries that store the information like the position of the window when closed, position of the tool bars, customized look, etc. On run, it has to read these entries and on exit, it saves them. Unfortunately, the new code expects them. So it is most likely hard coded to look into the registry and without the key, it fails. I have yet to disable this. I think I will have to overload the functions so that it doesn’t look into the registry. *sigh*

Additional Disabling “Features”

There are more things I disabled. Like the ability to go to the “Customize” tool bar window and such. They are easily layed out so I guess I won’t need to point them out.

Game Loop

I decided to look for a better game loop. Like I said in the previous post, the OnTimer is sufficient for a game like Pac-Man. But I wanted something that is more similar to the game loops used in DirectX games and such. I found an article that points it out.

http://www.gamedev.net/reference/articles/article2204.asp

It sums up everything pretty nicely. It overrides the Run() method, which is the message loop.

The problem however is that it uses 100% of a CPU core! This is not good for a game like Pac-Man which doesn’t even require full load of the CPU. Worse if you plan to play this on a laptop and drains your battery. The only solution, I have found is to use the Sleep function which sleeps the thread.

The New Implementation

So now I got a base application ready to go. I start to implement the features of my game. Since I am starting fresh the first thing I do are the following…

  • I added a StateManager Class to handle the states of Main Menu, Game Play, Game Over, Pause and Menu. This makes it MUCH easier to handle the various “modes of play” by just making a class for each state.
  • I make a BackBuffer Class to handle the Bliting instead of putting it in the actual frame animation method that I did before.
  • The new player class is now much more cleaner as before I put many things in the Draw() method (basically all the animations and such).

So far all is going well. When I have more free time, I will work on it again.

Re-doing Pac-Man

Since I currently have free time (still looking for a job), I decided to redo my GUI546 project which was a Pac-Man clone (which is available at my portfolio).

First of all, Why? Well first of all the original project was basically to have it finished in 2 months (the other 2 months were porting it to Managed C++ which I dreaded). At that time, MFC was totally new to me. There wasn’t much help online-wise as MFC was pretty old and not intensively used framework (especially for games). The only reference book I had was a book made in 1998. So most of the 2 months was researching which resulted in not having it up to the “standard” that I would of like it to.

So here is the game plan of what the redo will focus on…

  • The game will be called “Chomper” (to avoid copyrights lol).
  • I will be using the new MFC updates found in Visual Studio 2008.
  • I will try to find a different (and maybe better way) to do the animation. The old method was to use OnTimer which for a game like Pac-Man is okay. But I would like to see if I find a better and more “game”-standard way to do the animation.
  • NO DLLs! I hate DLLs.
  • NO Managed C++. It totally slow down my game when I ported it to Managed C++.
  • Add artificial intelligence (AI) which was not implemented in the old game. The ghost currently move randomlly.
  • Actual ghost images instead of blocks.
  • Fix the multi-threading. I added the sound effects late in the project to just get the bonus marks to up the grade in the course. Unfortunately I added it crudely where the sound was in one thread thereby stopping the previous sound effect.

There are other features I would surely like to add but for now, this is the priority. This would make the game at least feature complete compared to the old version.

So we will see how this project goes.