aspose file tools*
The moose likes Game Development and the fly likes Snake Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Snake" Watch "Snake" New topic
Author

Snake

Tralli Lalli
Greenhorn

Joined: Nov 27, 2004
Posts: 3
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.

Please help

[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ November 27, 2004: Message edited by: Dirk Schreckmann ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, Tralli!

I'm moving this to our Games forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Ray Muirhead
Ranch Hand

Joined: Jun 11, 2004
Posts: 44
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.

Cheers,

ray
Maarten Vergouwen
Ranch Hand

Joined: Jan 12, 2004
Posts: 60
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.
S�bastien Roelants
Greenhorn

Joined: Dec 05, 2004
Posts: 1
Hello,

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...
Tralli Lalli
Greenhorn

Joined: Nov 27, 2004
Posts: 3
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.


How do I do that?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Snake