Im creating a little snake game and I need help a little help. So far I have been able to create the snake head and the apple it is supposed to eat but I want the snake to grow in length when he eats the apple, I have partially solved that problem, but the extra body that is added to the snake doesn�t follow the snakes head as it should. I will include the code:
When I hit an arrow key and change direction the body does too i.e it doesn�t follow the head instead it�s like it�s stuck on the heads rear, if you get my meaning. What would solve this problem is some method to tell the body maintain the same direction for say 100 milliseconds then turn in the same direction as the head. I want the whole snake body to act like a train.
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ] [ November 27, 2004: Message edited by: Dirk Schreckmann ]
Theres a Snake project in C that I did this semester at Uni that might help you available here. It's a terminal game for an AVR microcontroller, but you might find the snake representation useful -- it was very different to how I would concieve of a snake personally, but you never know, it might help.
I made a little snake a while ago: membres.lycos.fr/sroelants/Serpent.java
It might give you some ideas, even if it's badly coded...
P.S.: "serpent" = snake, and "pomme" = apple [ December 05, 2004: Message edited by: S�bastien Roelants ]
I am belgian...
Joined: Nov 27, 2004
Originally posted by Maarten Vergouwen: The core of your problem I think is that you don't really want the body to move in the same direction as the head at all -- you want it to follow the same _path_ as the head.
Therefore, you should log the path the first segment (head) travels, and make the other (body) segments travel the same path.