im making a Snake game in C++ with SDL2. When the snake moves towards the right and the user presses the down arrow key, im removing the tail and adding a new head like this:
void SnakeGame::TransitionDown() {
for (SnakePart snakePart : parts) {
RemoveTail();
NewHead();
}
direction = 3;
}
void SnakeGame::RemoveTail() {
parts.erase(parts.end() - 1);
}
void SnakeGame::NewHead() {
SnakePart sp;
sp.LoadPart(GameWindow, GameRenderer, GetHeadXPosition(), GetHeadYPosition() + 18);
parts.insert(parts.begin(), sp);
}
If i put a for loop inside the TransitionDown() function and increment it just a portion of the snake size, i can see that it transitions the way i want - just that its doing it way too fast! Is there any way i can remove the tail and add a new head, and then wait abit before repeating?