c++ - Snake Game - Can't get snake body to follow snake head -


i have been working on snake game using sfml , c++ having trouble getting tail of snake follow snake head defined snake[0] in code below. have implemented code think should work doesn't following

    (int = 1; < snakesize; i++)     {         snakepartx[i] = snakepartx[i-1];         snakeparty[i] = snakeparty[i-1];     } 

the way understand (and incredibly wrong , appreciate if point out happening here) that, piece of code should set value of snake body part position of previous body part located when program loops set follow snake travels.

what happen though when snake eats apple snake gain 1 block tail, not grow farther.

in classic snake game, snake made of segments. each segment contains coordinate of segment (among other attributes).

specifically, snake container of segments. container choice, recommend queue.

with queue, new head segment added queue , tail segment removed.

here's code fragment help:

class snake_segment {   public:     int column;     int row; };  typedef std::deque<snake_segment> segment_container;  int main(void) {   segment_container snake_body;   snake_segment head;   head.row(25);   head.column(30);   snake_body.push_back(head);   snake_segment tail = head;   ++tail.column;   snake_body.push_back(tail);   return exit_success; } 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

c++ - No viable overloaded operator for references a map -

java - UML - How would you draw a try catch in a sequence diagram? -