Archive for August, 2008

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

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.

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.

MFC + C++ 2008 Feature Pack Overview

Like I said in my previous MFC post, I will be using the new features found in Visual Studio 2008 and the new C++ 2008 Feature Pack. The C++ 2008 Feature Pack added many new MFC features and TR1 (adding many new C++ features). I actually have been playing around with it for quite a while (just the MFC part). I haven’t used any of the TR1 features yet.

To download the 2008 Feature pack is here. The thing is I forgot to install the Windows SDK BEFORE the Feature Pack which now requires me to repair VS2008 to just install the SDK since MS didn’t put any checking in their installers as it overwrites it :/ Just a note for people who are planning to install the Windows SDK.

This Feature Pack will most likely be included in the Service Pack 1 (SP1) release of Visual Studio 2008.

These new MFC features were actually bought out from a company that makes MFC components called BCGSoft. So it was nice of Microsoft to just give this to everyone for free.

Now for a brief talk about the features it bring to MFC. A feature that most people will like is the new visual themes that let you mimic the Visual Studio and Office suites. The docking manager like in Visual Studio is also another nice feature. As well the much loved/hated ribbon found in Office 2007 is also available. Plus there are many more which I haven’t tried yet.

There are bunch of new sample applications also included (found in C:\Program Files\Microsoft Visual Studio 9.0\Samples\1033). Useful because there is almost NO tutorials or books on MFC anymore. The MSDN website has all the help documents though but there is nothing like walking through an application to see how to put it all together. Various sample applications are available such as Windows Explorer, Visual Studio, Outlook, MS Money, Word and even Internet Explorer. Other examples include like making a those nice Alert windows like from MSN Messenger and shows some customization, like a customized tooltip. I don’t know how to make a customized “theme” but I’m sure it is possible.

That’s pretty much all I have to say about. All in all, this is nice addition to Visual Studio.

Whee! Got a Web Dev job!

Was going to post this yesterday but I finally got myself a web development job. It is a junior position working at The Score Television Network. I can’t wait to start 😀

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.