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
- This is a game. Not a program that will be used throughout the system.
- 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.
- 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.