• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Snake

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Tralli!

I'm moving this to our Games forum...
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Tralli Lalli
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic