Hi GameDevs,
I'm writing my own revamped version of snake with SFML and C++.
I'm not using an array board but instead store positions with vector<float> because the snake can move in 8 directions and the movement needs to be smooth.
The problem area for my tail logic is as follows:
Note, there's a function that lengthens the vector as it eats
void MakeTail()
{
//sets initial value for tail vector equal to current snake pos(x,y)
tail_x.at(0) = snake.x;
tail_y.at(0) = snake.y;
//makes next vector pos equal to the previous
//note, this vector is filled backwards
for (int i = n_tails; i > 0; i--)
//n_tails = tail segments * 6, explained after code
{
tail_x.at(i) = tail_x.at(i-1);
tail_y.at(i) = tail_y.at(i-1);
}
}
My problem:
1. I want the tail segments drawn to be ~6 pixels apart, so I draw every 6th position - which means I must add 6 vector positions for each tail segment
2. The game gets incredibly slow past 30+ tail segments due to the amount of math needed per frame
I'm wondering if anyone has any ideas on a different, more economical way to store tail positions as I've hit a brick wall trying to solve this issue.
Thanks,
AdosH