Q: Collision Detection (Snake/Tron)

Hey! I have question about collisions for simple snake game. As far as i understand there are few types of them:
a) i could make an array with all the points on the screen and test against collision -> sounds pointless(worm size 1x1px and resolution 1900x1440(no comments on that this might not exist etc -> this is an example).
b)i could read screen bits information and say for example if color is black then BOOM gameover -> how would that work in java?

Or is there a better solution to this problem?

Take care,
Kuldar

Oooh, people could go on about collision methods for years. This is one of the most difficult parts of any game.

If your snake has a fixed speed and doesn’t move too far at once, then I would just do pixel-by-pixel checks. That means if he’s trying to move 10 pixels to the right, for a for loop that goes 10 times, checking each pixel as he goes. Very simple to increment, and as long as your game isn’t too complicated, it’s reasonably fast. The color black thing would work just find for this (use the Raster of a BufferedImage), but the array would as well. 1900x1440 really is not that unreasonably large.

Indeed, there are plenty of better solutions, especially if you know the geometry of the level. But they are all rather difficult. Check these out:


http://www.harveycartel.org/metanet/tutorials/tutorialA.html

http://www.doc.ic.ac.uk/~dfg/AndysSplineTutorial/index.html

A plethora of knowledge is at your fingertips. :stuck_out_tongue:

Snake games are generally implemented with simple tile based collision.

Kev

Random thought of the day: MMO Snake ;D