Saturday, September 4, 2010

Sorry Been Pretty Busy on Adventure Game Design

Hey everyone I know it's been awhile since I posted and I wanted to say that I am still going to be posting some XNA tips and mini-tutorials as I find stuff to do. Tomorrow is my birthday so I've been pretty busy today as you can imagine... Stay tuned for new posts in the near future.

Thursday, August 26, 2010

Nick Gravelyn's Tile Engine Series

Hey everyone, lately I've been following Nick Gravelyn's Tile Engine Series and am nearly through it for the second time and I thought I would post up some fixes for some minor bugs that I found in my own code. This is in no way connected to Nick and I want everyone to understand that I'm not bad-mouthing him in anyway, I'm just writing about some unique bugs that I found that I was able to fix. Also, don't assume that my way is the best way to do this because it may not be, but it does work and that's what matters in the end.

So let's get started.... (If you haven't seen Nick's Tutorial then I would check it out at the link above first, that way you know what I'm talking about in this post)

Ok, so after implementing the CollisionLayer.cs class there is a unique bug that occurs when your character walks to the very bottom of the map. In this scenario, the program will crash and throw an IndexOutOfBounds exception in the CollisionLayer.GetCellIndex() method. The reason for this happening at the bottom of the map and not the top, left, or right is because of the way that we implemented our collision detection. We use the Origin for the player (in the CheckCollisionForMotion(Vector2 motion) method), which measures collision from the very bottom of the player's sprite. This is generally a very good idea, however it actually causes this problem as well as another problem that I'll mention in a minute.

The quick and easy remedy for this is to modify the Origin as you pass it to the ConvertPositionToCell method, returning a slightly modified position.

So if you followed Nick's Tutorial to the letter, your CheckCollisionForMotion method should be in the Game1 file after the Update method. The easiest way to remedy this bug and another bug that slows the player down (because the program thinks the player is in mud/lava/something that slows its speed down) is to change this line:

Point cell = Engine.ConvertPositionToCell(Origin);

which sends the exact bottom of the player's sprite to the ConvertPositionToCell() method, to this line:

Point cell = Engine.ConvertPositionToCell(
new Vector2(Origin.X, Origin.Y - 2));

which sends the exact same position (but two pixels higher up) to the ConvertPositionToCell() method.

This new Point will keep the 'cell' variable in the actual cell that the player is in without trying to go beyond the lower boundary of the map. It also eliminates the annoying case when there is a clear row at the top of the map with a row of mud/lava/something that slows the player down below it and it still slows the player down. The reason we only need to modify the Y coordinate is because we are measuring our Origin from the very center of the sprite's X-axis and the very bottom of the sprite's Y-axis.



Give this new line of code a try and be proud of yourself because you have just partially debugged an otherwise very powerful TileEngine.

Thursday, August 19, 2010

Introductions

Salutations to everyone reading this blog. I would like to say "Hello" and introduce myself a little... I am currently a web developer working for Texas Wesleyan University, just graduated from there with a B.S. in Computer Science, and play way too many video games. I remember my first console was an SNES with Donkey Kong Country as the in-box game. Those were great days...

Anyway, I have a wife and three month old son who are the two best friends I have. I am also starting to develop small video games for Windows and XBox360 with XNA Game Studio. In the future, most of my posts will probably involve game developmental progression, as well as some things I have learned along the way...

Well, that's it for this post, just a short "Hello" and "How you doin'?" to get things started. Check back often because I will be updating this blog with new posts as I find things to talk about.