Showing posts with label pacman. Show all posts
Showing posts with label pacman. Show all posts

Thursday, June 25, 2009

Pacman (XNA) - Update 1

I've made a little progress with the Pacman XNA game. I managed to create the Pacman character, move him, animate him and rotate him according to the direction he is going. Now, moving the character wasn't a big deal since I've done that before, but animating and rotating was new to me. I don't have much else to say, so I'll briefly run though how each works:

Animation
This is done using a sprite sheet, which I've recently learned is multiple related images all in one image file. Simply search sprite sheet on google and you'll see many examples. Of course mine wasn't as complicated as some of the others out there as it only has four different positions (though I could have gotten away with three). Anyway, basically all you have to do is organize the sheet into rectangles around each individual sprite and loop through them. There is a parameter to the draw method that asks which rectangle you'd like to display from the sheet. Check out my code, or just read some tutorials. It's not too hard to figure out.

Rotation
Rotation was also fairly easy. In the same draw method, there is a parameter for rotation. It asks for a float value and works in radians. So I just kept track of the rotation of the character, so that when it moved in a different direction the character faced in that direction as well. The MathHelper class was helpful for this, particularly since Pacman really only ever faces up, down, left or right. You'll also have to find the center around which to rotate. This can simply be done by finding the width and height of each sprite (not the entire sheet) and then dividing each by 2, and using those values as the x and y parameters of a Vector2. It's simple.

If you have any questions, just ask. Maybe one day I'll actually get the energy to put up some tutorials, but that might take a while if no one is asking for them. If you check out the code, you might find what you're looking for in there anyway. At the very least, you'll have an animated Pacman moving around your screen.

Tuesday, June 23, 2009

Pacman (XNA)

So, I haven't totally decided to give up on the Breakout game or the Pong game yet, but unless I get some feedback asking for more Breakout or Pong (which I doubt will happen) I think I'm going to move on to the next game. The previous games certainly aren't at the release stage yet, and may never will be. But my goal here wasn't to create a super-awesome Breakout game. It was to learn to program video games (and contribute to open source software). Breakout and Pong really taught me a lot about XNA and Java game creation respectively. And, when I finally hit up C++, I may have to return to these games to teach me that as well. However, since I'm staying with XNA for a while, I'm going to step it up a little and create a Pacman style game. I hear the excitement brewing.

Actually, this decision wasn't entirely my own. Personally I figured by now I am fully capable of making a decent Call of Duty replica game, however, I read this article by Geoff Howland on the gamedev.net site which goes through the steps you should take to become a decent game programmer. He says to start with Tetris and then move to Breakout. I figure Pong works well enough in place of Tetris, and I have Breakout "done". So, his next step is Pacman. Many aspects will be the same of course such as user input, collisions and sound. However, there will be a few differences like basic AI and using a map with boundaries other than a square. I think the map will be the trickiest thing to work out. Anyway, I'll let you know how it goes.