So I am making a snake game as final assignment for semester 1 of my game dev study.
We have to write it in C# in Visual Studio 2015. I am using the .NET 3.5 framework.
So basically how my snake works is as follows:
I made a vector2 List to store the snake parts. It starts only with the head obviously. When collission with the food occurs, I add a vector2 to the list. I draw a rectangle in the paint function and I make it take over the last position of the previous snakepart. That is how my snake works and how my snake gets longer as you eat the food.
I am having trouble with the snake collision itself though.
This is the code I came up with to check if the snake collides with itself:
for (int i = 1; i < Snake.Count; i++)
{
if (Snake[0].X > Snake[i].X + (i * 64) || (Snake[0].X + (i * 64)) < Snake[i].X || Snake[0].Y > (Snake[i].Y + (i * 64)) || (Snake[0].Y + (i * 64)) < Snake[i].Y)
{
SnakeCollission = false;
}
else
{
SnakeCollission = true;
}
}
So I check whenever the snake is NOT having collission, then snakecollission is false, else it's true.
What happens now though is that when I eat one piece of food, the snakecollission turns true, while the snake is not touching itself.
This is the link to my complete code: http://pastebin.com/gVUuazQN
Any help would be appreciated, I hope I have given an understandable description :)