Notices
Results 1 to 5 of 5

Thread: Logics snake

  1. #1 Logics snake 
    Forum Freshman Aero's Avatar
    Join Date
    Nov 2008
    Posts
    34
    Ok so i have looked for a lot of topics and code online, but i can't seem to find anything decent..

    Would this be a correct logic to move the snake around in the game "Snake"? (the game is tile-based so not all 'parts' of the snake are the same: turns/head/tail/body have different graphics)

    - Move the head one forward in the direction it's going
    - if the head just went left or right, turn the second body part into a body part that's turning
    - move all the other body parts, including tail to the position of the body part that was preceding it. Some body parts could become a part that is turning and vice versa.
    - check if the part preceding the tail was a part that was turning and change the orientation of the tail accordingly


    If this isn't clear i'll try to explain it somewhat different..


    Reply With Quote  
     

  2.  
     

  3. #2  
    Forum Freshman
    Join Date
    Oct 2010
    Posts
    98
    Choice of algorithms solely depends on data structures you use. That's the general rule!

    So choose how you will store info about snake and its food. Remember choice of the data structures imparts complexity of algorithms and future extensibility of code.


    Reply With Quote  
     

  4. #3  
    Forum Freshman Aero's Avatar
    Join Date
    Nov 2008
    Posts
    34
    I'm keeping my snake in a associative container (vector in C++).

    I almost got it to work using the above logic, only that i work bottom-up:
    first i calculate the new position of the tail using the preceding part of the tail,
    then i calculate the new position of the part preceding the tail, etc. etc. untill i reach the head.
    That way it was easier to program


    This is solved for now
    Reply With Quote  
     

  5. #4  
    New Member
    Join Date
    Dec 2010
    Posts
    2
    Glad to hear you got it working.

    I made a snakes game in flash, several years ago. I ran into a similar issue. I finally had a EUREKA! moment when I realized the snake isn't "moving" at all. Essentially the snake "grows" by one section and immediately "shrinks" by one section, before the frame is drawn.
    Reply With Quote  
     

  6. #5  
    Forum Radioactive Isotope MagiMaster's Avatar
    Join Date
    Jul 2006
    Posts
    3,440
    I had a similar problem trying to make a centipede clone. I don't remember what my solution was (or if I even found a good one).
    Reply With Quote  
     

Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •