Sign in to follow this  

Snake Game Collision Detection

This topic is 2856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm just starting an Anaconda clone in XNA. This is the game I'm talking about: http://www.youtube.com/watch?v=b_rpiB-jiqA I've been doing it all in primitives and have been trying to figure out a faster way to do the collision detection without checking the position of the head against a huge number of points every frame. I was thinking about checking that if a point in front of the head was any color other than black (the background color), then that would mean the snake has run into something. I figured that I'd have to make a 2D array storing all the colors of the current board, but was unsure how to do this. Can anyone help?

Share this post


Link to post
Share on other sites
Collision detection between two bitmaps can be done pretty quickly. You use a 1 bit representation of both images. The trick is to use bit shifting and bitwise AND to test 16-32 bits at a time.

Share this post


Link to post
Share on other sites
Better idea - if your snake is a long line of circles, group them. If you have a group of circles with radius r that are all within d distance from a particular one, you can just test the head against that circle as if it had radius r+d. This should eliminate a lot of checking against circles that are nowhere near the head.

I should also point out that a few thousand checks per frame is probably not a big performance issue so if you aren't actually getting slowdown you could just ignore it.

Share this post


Link to post
Share on other sites

This topic is 2856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this