I am creating a snake game for a project and am massively stuck on something.
I'm trying to make the snake move in a 2D grid array. To explain this further, i'm using a game board space of 768x768 and want to implement a 20x20 grid for the snake and all other objects to be limited to.
I've currently got a snake head shape with user control but the way it is coded means that the shape moves 1 pixel at a time.
I'm completely at a loss as to what to do and would appreciate any help or suggestions.
Why not put coords (I would use std::pair of ints) into a queue, every time you move, you put a new one in and pop the last one. You would also want an int as a buffer when your snake extends, so it would check if you have anything in the buffer before popping the last one.
STL lists are a pretty basic concept, just look at some examples in this website's reference section.
Also, I realized that you are not looking for a queue, because you can't iterate through it, what you need is a deque, so you use push_front, and pop_back.
For pairs, you can totally just write a class called point or whatever and make it contain 2 ints called x, and y. But if you want to use std::pairs, it is in the header <utility>, but note that the <map> header also contains pairs.
So your snake trail list would look like this: std::deque<std::pair<int,int>> snake_trail;
But pairs are not very pretty, because whenever you want to insert you have to do: snake_trail.push_front(std::pair<int,int>(x,y));
And also to access the values, you have to call "first" and "second".
But I just like it because I don't have to make a class.
Thanks poteto, that's really helpful, i've had a go at making a snake trail list like you mentioned but have no idea where and how to put it. Could you point me to how it should look?