The Road Not Taken: An XNA tutorial covering color key path collision

road I've posted a new tutorial at XNADevelopment.com. This one covers doing path collision using a color key. This was a really fun project to do this weekend. Really learned a lot so I thought I would share.

 
I have also added a couple simpler tutorials for both my benefit and yours. I was finding myself repeating certain steps over and over in each tutorial. Particularly walking a reader through creating a new game project and adding images to game project. So in an effort to stop repeating myself, I refactored (you can refactor tutorials right?)

 
There is now a tutorial specifically covering each of those activities and in the future I will just reference those tutorials instead of saying the same thing over and over. I think they both turned out pretty well and contain quite a bit of useful information. I am hoping this helps speed up both the tutorial process and moving through the tutorials so people can skip steps they are familiar with. So if you need a refresher, here is a tutorial covering creating a new Windows game project and how to add images to a game project.


Well, it is late and it has been a long weekend so that's all I have for now. Let me know what you think of the new tutorial The Road Not Taken. I always appreciate any comments or feedback you might have.

 
Have fun!

Print | posted @ Sunday, October 28, 2007 11:08 PM

Comments on this entry:

Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by Chris Williams at 10/29/2007 12:56 PM

Really cool George! I think this could make a very interesting concept for a marble game or Line-Rider type of game. I look forward to experimenting with it more later.
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by Cryovat at 10/29/2007 7:57 PM

Nice piece!

Though I'm seeing a disturbing trend of your game titles becoming shorter... ;D
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by ZMan at 10/29/2007 8:35 PM

Free Viagra and diet coke - check out my website...
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by boki at 11/1/2007 4:44 PM

The above comment by ZMan is properly comment spam by someone impersonating The ZMan...
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by Jim Perry at 11/1/2007 4:46 PM

Nice alien face track. I'm still waiting for "The One About the Ship That Shoots At Aliens That Attack From a Formation Above It"! (stupid italics button didn't work :( )
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by Anthony at 11/7/2007 1:45 PM

The tutorial looks great, but in the LoadGraphicsContent(bool loadAllContent) method the following line of code won't work: mTrack = content.Load<Texture2D>("Track");

Intelesense doesn't like 'content'. I don't know if I need to use a using statement, or if my version of the software (downloaded today) is newer than yours, and that's causing the problem.

Thanks!
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by George Clingerman at 11/7/2007 2:43 PM

Anthony, you need to make sure you create a new Windows Game project when you start working.

"content" is an object that is created automatically by the XNA framework when you create a a new Windows game project so it should already be there for you to use.

Just follow the tutorial on my site for making a new Windows game project first if you need some help figuring that out.

Glad you like the tutorials and I hope that helps!
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by Anthony at 11/7/2007 4:47 PM

Wow, you are prompt! I originally did create a Window’s Game Project, and I don’t know if C# was just having a brain fart or what. I created a new project, copied, and pasted my code from the last project, and all works well.
On a side note you have some of the finest tutorials I’ve seen for XNA game development (that is coming from a former computer programming college prof.)
I read you Bio, and you seem like a cool guy. I also professionally program in VB.Net, and C++, and I have two daughters that love games! I started progamming on an Apple II, and C-64. I’m using XNA to play around with, and get a handle on C#.
Keep up the good fight!

Anthony
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by joris at 12/6/2007 5:35 AM

I use the same way of collisiondetection as you do in a 3d game. But i want to bounce back in the right direction when a collision occurs. Do you have any idea's for this? i have some troubles with defining the right direction.
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by Evgeni Petrov at 1/3/2008 8:02 AM

Great project! Some extra things that can be added. Instead of going at constant speed add speed variable that increase with Up/Down keys. When collision occurs just decrease speed of car instead of just stopping it. That way has some feel of real game. Just make collision check not to get out of the window.

Otherwise the collision detection is a little bit murky. Maybe a tutorial that shows some funky stuff with this "fake" drawing would be cool.

Kudos for the tutorial. Its my first real game :))
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by George Clingerman at 1/3/2008 8:55 AM

@Evgeni - Thanks! Glad you enjoyed it. This was just meant to be a demo for how to do the collision and not a game I was working on myself, but I highly encourage you to go ahead and play with adding any enhancements you can imagine!

I'll have to think about how to make the "collision detection" part less murky. I really wanted to try and make this concept more approachable for beginners so it sounds like I need some more work.

Thanks again for the feedback!
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by Laguna Lore at 1/8/2008 6:59 AM

Thank you very much for your tutorials, I'm a begginer in XNA and I have to do a videogame for the proyect of computer science, and they are helping me a lot. I look forward to seeing some more tutorials. Bye!
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by Bos at 1/10/2008 3:29 AM

Awesome tutorial, i'm having trouble with the
"graphics.GraphicsDevice.ResolveRenderTarget(0);"

In XNA 2.0 it doesn't exist. How can i get around this?
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by Bos at 1/10/2008 3:57 AM

Looking on the net, there is alot of talk about this change from 1.0 to 2.0
The problem seems to ly with preserveContents, when the RenderTarget is changed and thus removed
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by Bos at 1/10/2008 4:46 AM

Ok, after converting back to 1.0, and still getting some funky errors, I rechecked the code, and realized I was using the wrong renderTarget in the collision code. Went back to 2.0 and jst removed the code for ResolveRenderTarget(0);
and put the right texture target in.

Thanks >.<

Peace out!
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by Pasko at 1/21/2008 3:23 AM

Isn' the collision detection algorithm a bit expensive?
Is there some other way, i dunno, for instance checking only the boundaries of the rectangle instead of the whole rectangle?
Anyway, great tutorial, i think i will use it to make some little game. :)
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by Pasko at 2/2/2008 12:49 PM

Hi, that's still me.
I just finished my game, for anybody interested, i can give a little refining to the collision algorithm. As i said in my previous post, we actually need to check only the bounds of the car, and, assuming no obstacle smaller than the car itself, only the SIDES of the car. Thus, the algorithm becomes:
for (int x = 0; x < mCarWidth; x++)
{
boolCrashLeft |= CheckTerrain(myColors[x], ...);
boolCrashRight |= CheckTerrain((myColors[aPixels - x - 1], ...);
}

thus distinguishing between left and right crashes (so we know where we should move the car).

Bye, Pasko
Gravatar # re: The Road Not Taken: An XNA tutorial covering color key path collision
by antibiotic pharmacy at 7/10/2008 4:55 AM

antibiotic pharmacy, antibiotic drugs, buy zithromax, buy amoxil, buy bactrim, buy biaxin, buy ceclor, buy cipro

Your comment:

Title:
Name:
Email:
Website:
 
Italic Underline Blockquote Hyperlink
 
 
Please add 4 and 6 and type the answer here:
 
Twitter