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.

Sunday, June 21, 2009

Breakout (XNA) - Update 7: Level Creator

Remember that level creator I kept mentioning would be cool, but never actually got around to creating? Well, that's history now, because I've finally managed to build one. Ok, so it's a little basic, but a person can now go in and click where they would like to place the bricks. Then it saves it to an XML file to be used later. Right now only one level can be saved at a time, so creating a new level will kill the old one, but I hope to fix that at some point and allow the player to choose which level they'd like to use.

Creating this level creator actually wasn't too difficult... saving it was a bit of a pain though. Luckily this tutorial was there to make things a little easier. It helped a lot with reading the XML files. Then I happened across this blog that taught me how to write the XML files. Of course I was still having problems since I wanted to store a number of bricks and the information in each file. At first I was passing the individual array fields to the serializer, but that wasn't working. Then I tried passing the entire array, and that was much better, but still wasn't giving me a readable array type (you'll see what I mean if you look at the XML file and the pages I gave you). Finally, I passed a list as the parameter. For some reason, it took me way longer than it should have to figure that out, but at least now it's working. And it turns out that working with XML in XNA really isn't too much of a problem in the first place. If you find you still need help with the XML after reading those two pages and checking out my code, let me know. I'll do what I can.

So, check out the code and have a look. Maybe you can make some improvements. Maybe put in some file handling to create new files for each level, or maybe even a way to edit previous levels. Hmm, sounds like fun! Either way, I think my time with Breakout is winding down. Maybe I'll do a few more things like figure out the file handling aspect, but other than that, it may be time to move on to bigger and better things. Please let me know what you think or if you have any suggestions. I really haven't been getting much feedback and even a "what's up?" is nice sometimes! Have a good one and, good luck with the coding!

Thursday, June 18, 2009

Breakout (XNA) - Update 6: Adding Sound

I finished my 3D tutorial which was really cool. I'm starting to think that the move from 2D to 3D won't be too bad. My 3D modeling skills with Blender still aren't the greatest, but maybe they'll come along. Hopefully I'll run into someone with artistic ability before that though, since mine is certainly a long way away.

Anyway, other than being cool, the 3D tutorial taught me how to use sound with XNA Game Studio. It's really quite simple... at least for the basics. Just open up the Cross-Platform Audio Creation Tool (using the correct version), start a new project and save it in the audio content folder of your XNA project, create a new sound and wave bank, add .wav files to the wave bank, and then just copy and drag them to the sound bank. Then you just basically load them into your XNA project much like you would image files. Simple as that. If you want to know how to load sound, but don't care for the 3D aspect of game programming yet, just check out the sound section of the 3D tutorial.

I've also made a few other small improvements to how the game works. I added separate screens for the title screen, pause screen and game over screen. I also had to create class that inherits the EventArgs class so I could pass arguments (which was necessary so the game knew whether the pause button 'P' was pressed or the game was over). That took a while to figure out, but a decent example can be found in here in the MSDN Library.

Other than that, I've come across another problem. When the ball hits the top, it kind of just doesn't come back down. I think I need to find a better way to work the collision detection... actually I know I do. Maybe I'll look into that in the next little while.

Oh, and sorry the sound is kind of dull. At least it's a sound that works.

Wednesday, June 17, 2009

3D Modeling with Blender

To quote myself in a previous post, I said, "I highly doubt 3D graphics will be any easier to create than the 2D ones." Well, I'm not necessarily going to retract that statement, but I now believe that making 3D graphics may be easier than it seems... with some practice of course. This is where I introduce to you Blender, "the free open source 3D content creation suite." I stumbled upon it as I was looking for a "free, open source" program to create 3D graphics for the 3D game I'm going to develop at some point. I must say, I am impressed. Not that I know much about 3D graphics creation software, but Blender seems to be quite easy to use. At least the tutorials make me believe so. I even managed to whip up a snowman in a snow scene. Alright, it's not perfect, but remember I'm far from an artist, and that was my first try... even if I did follow a tutorial word for word. Either way, if you're interested in 3D graphics or 3D games, Blender is definitely worth checking out.

Tuesday, June 16, 2009

Breakout (XNA) - Update 5

Well, my progress through the XNA 3D tutorial was halted abruptly today as the XNA Creators Club site went down for maintenance. So, it was back to the Breakout game I've been working on for the past little while. It turns out it was worth it. I learned to create a title screen for the game... well actually, I can now create any number of screens for the game. It's really pretty cool, and quite simple if you understand how to use new class objects. The person who posted the tutorial, George Clingerman, called it changing states with "Polymorphism". I haven't really read up on polymorphism, so I'm not really sure what that means yet, but I was still able to work my way through the tutorial and understand it all. Though, now that my interest is sparked, I think I might check out a few pages on the subject anyway. Mr. Clingerman also gives a couple of other simpler ways to change states, along with a number of other helpful tutorials on XNA, so definitely give his site a look if you're interested.

As for the Breakout game, I was hoping to put in some sound effects, but that was tied directly into the 3D game tutorial since they explain it there. Needless to say, that didn't get done. I'm also thinking I'm going to create a sort of point and click level creator or something. Or maybe I'll just start making a cooler game... who knows? Check out the source here and figure out how the state changing works. It's really not to complicated.

Monday, June 15, 2009

XNA - 3D Tutorial

I've been having difficulty remaining interested in the games I create. Fortunately, I think it has more to do with the fact that I've been creating boring games than actually being bored with creating games. Either way, I figured I'd step things up a notch and try out the XNA 3D tutorial. So far, it's going quite well and is interesting. It really makes me want to jump right in and start creating complex games right away. Of course this isn't going to happen. You've gotta pour the foundation before you start building the house... or something like that. So, I'm going to go through the rest of this tutorial and then I'll start seeing if I want to work on some 3D games. Unfortunately, I highly doubt 3D graphics will be any easier to create than the 2D ones. So, who knows what I'll do... now that I think of it, maybe a neat little 2D sidescroller would be cool... you know, for 2D.