Noob quastion reguarding snake.c

This is a discussion on Noob quastion reguarding snake.c within the Game Programming forums, part of the General Programming Boards category; Hi all, im working on a school project, where we is supposed to build the classic game snake. to represent ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    2

    Noob quastion reguarding snake.c

    Hi all, im working on a school project, where we is supposed to build the classic game snake.
    to represent the snake Im using a linked list(*list). To move the snake ill use a function called move_snake, where ill take the last body_segment (tale) and place it in front of the snake as the new head segment. Thats works fine except for the rest of the body parts, my problem and question is regarding the rest of the snake body.. Ill need a function for moving the rest of the body segment. Ill been asked to use a pointer that points to the rest of the body (**body). But dont know how to implement it. Ill hope I posted my question in the right forum, otherwise pls let me know.


    Code:
    void move_snake(snake_body *list, body_segments *pos){
    
       snake_body *tale, *cur, *newHead;
    
       switch(pos->dir){
    
        case RIGHT : list->segment.x++; break;
    
        case DOWN  : list->segment.y++; break;
    
        case LEFT  : list->segment.x--; break;
    
        case UP    : list->segment.y--; break;
    
      }
    
      for(cur = list; cur->next != NULL; cur = cur->next){
    
        tale=cur;
    
      } 
    
      tale->next = NULL;
    
      cur->next = list;
    
      cur->segment.x = pos->x;
    
      cur->segment.y = pos->y;
    
      cur->segment.dir = pos->dir;
    
      newHead=cur;
     
    
    }

  2. #2
    Registered User
    Join Date
    Dec 2009
    Posts
    2
    Oh got it!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. noob needs help!!!!:(
    By tykenfitz in forum C Programming
    Replies: 1
    Last Post: 07-10-2005, 09:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21