Posted on January 13, 2008
Planet Source Code For Flash Game Development
Recently, I needed to find possible methods to create accurate movement for a maze-chase Pacman variant that I am working on (Pumpkin Man). I have been working on perfecting the method of animating my main character while he turns to an adjacent tile. It may sound simple at first thought, and in some cases it might actually be, but I seemed to have painted myself into a corner with some of the choices I made early on. The best way for a character in a Pacman style game to turn and move in a new direction is to wait until the character is in the exact middle of his current tile, and then rotate (or swap out the animation) to the new direction. I painted myself into a corner here because
1. I choose a tile size that that is an even number.
2. I chose to use all integers for my calculations. This helps speed up Bitmap display operations.
3. My character moves more than one pixel at a time.
Why did all three of these paint me in a corner? Well, given the first one, I don’t actually have a center of the tile. I could say that the center is 15 (0 based) or is it 16? 32 / 2 = 16, but since it is divisible by 2, both 15 and 16 are the center. I am using integers, so 15.5 is the 1 based center and 14.5 is the 0 based center. Any how, I can just choose to use 16, and so I did, even though it is not the exact center of the tile. Since my character moves at a rate of 3 pixels every frame, I can never be certain that he will ever actually hit the center (16) of a tile. Because of this I decided to use the speed of my character as a offset from the center. So as long as the character is with in 16+/- 3 (13-19), he is considered in the center of tile. Since Pacman is always in the middle of any passage way, no matter where the character turns from, even if it is not the exact center (in this base by foo foo center of 16), I must make sure he is in the center 16x 16y of the tile he is turing into. So, he is placed there on the next frame. This works most of the time, but occasionally, it looks strange.
Anyway, how does this relate to Planet-source-code.com? I have used the site before for .asp and some Java work, and even looked at Asteroids and Galaxian C++ code from there a while back, but for some reason, I forgot to use it with Pumpkin man. Low and behold, I found a couple decent Pacman games in C# and C++ to check out.
I don’t have the results yet, as I don’t have the right version of Visual Studio to compile either game, but I plan to install it later tonight (MSDN is a life saver sometimes).
Anyway, I just wanted anyone who is stuck on a game to check out Planet-source-code.com
It might be just the place to find what you are looking for. Even though they don’t have any Actionscript code, I find that C# and Java games are pretty close and as long as I can compile them, I usually get some good ideas if I need them.