Options for collision detection with Snake Game?
-
Hi All, First post here
I'll be creating a Snake clone as my first F4NS project and am stuck on the best approach for collision detection
I have done this previously in QBasic by creating the Snake as a 2D array then mapping each trailing x,y position as the snake position updates then compare the "head of the snake" against all other positions in the array to check for collision.
Overly engineered? Is there an easier way to do this? I've been wondering if there is a getcolor function as it will be black n white to start with
Thanks
-
FUZE4Switch is fast enough to work with quite well your current method. The snake will only move a couple of times each second.
If you want a method that doesn't get "slower" when the snake gets longer, I would suggest a boolean grid for all the cells on the screen. The the head enters a new cell, the value in the boolean grid is set. When the tail leave a cell, the value is set to false. Checking against that boolean grid would result in an equal performance in the algorithm, regardless of the length of the snake.
(EDIT: Booleans are integers in FUZE4Switch.)
-
Hey Nisse5, Thanks, that's a great idea.. I'll give it a go