title: Moving Snake in C
body: <p>We're creating a snake game on an STM32 discovery board, and displaying it on an LED screen. We're storing the snake in a linked list type of structure. We got the collision detection stuff down, and we know how to move the head of the snake, but we don't know how to grow it. Can you give us any pointers?</p>
  
  <p>Here's what we have: </p>
  
  <pre><code>void move_seg() {
    struct seg *temp = malloc(sizeof(struct seg));
    temp-&gt;x = head-&gt;x + xdir[direction]*4;
    temp-&gt;y = head-&gt;y + ydir[direction]*4;
    head-&gt;next = temp;
    head = temp;
    draw_seg(head, WHITE);
    //check if snake collided with itself..
    collision_detection();
    //check if apple was eaten
    apple_eaten();
    if (apple_was_eaten) { 
      draw_seg(tail, WHITE);
    }
    else { 
      draw_seg(tail, BLACK);
    }
    tail = tail-&gt;next;
    }
  }
  </code></pre>