Why the stringstream 'convert'? Why not simply std::to_string()?
Why are you declaring a ton of "sf::RectangleShape bodyPartXXX" variables? Your snake will grow to indefinite length. You can't possibly pre-declare variables for all its body parts. Just use a standard container like std::vector, std::deque or std::list to hold the body parts and then allocate them on demand when the snake grows.
This:
// #, fuzzy
part17Pos = part16Pos;
part16Pos = part15Pos;
part15Pos = part14Pos;
part14Pos = part13Pos;
is just crazy...
Why is this:
sf::Vector2i res(400, 400);
(and loads more) not "const"?
if(event.key.code == sf::Keyboard::Return)
goto start;
seriously? No! You should be able to do better than that. There
are use-cases for
goto, but they are very few and very far between. I've personally only ever had to use it once or twice in the last 10 years and that was in some code where me and a coworker could prove that the "nice" version of the code unfortunately executed in 3 times the time than the code with the goto (and it happened to be performance critical), so unfortunately we had to go with the
goto version rather than the readable version
but that's rare - stay away from
goto, forget it exists in the language.
srand(time(0));
No. Don't use
srand - use the nice new stuff provided in the "
<random>" header.
gameOverRat.x = res.x / (float)gameOverSize.x;
gameOverRat.y = res.y / (float)gameOverSize.y;
Don't use C-style casts. Use C++-style casts (static_cast, dynamic_cast, const_cast, reinterpret_cast) - yes, they are longer to type and ugly to read, but that's a
good thing. It means you will be aware of them and try
not to use them. Casts can be a needed evil but they should generally be avoided and are usually a sign of a design problem in the code. C++ casts are much easier to spot than C casts - never use C-style casts.
//show bodyparts,,, if head touches tail #, fuzzy
if(snakeSize >= 1)
{
if(snakePos == part1Pos)
gameOver = true;
window.draw(bodyPart1);
}
if(snakeSize >= 2)
{
if(snakePos == part2Pos)
gameOver = true;
window.draw(bodyPart2);
}
if(snakeSize >= 3)
{
if(snakePos == part3Pos)
gameOver = true;
window.draw(bodyPart3);
}
More ridiculous code. You really need to learn about loops!
I can recommend
ClangFormat if you want to format your code consistently - makes it easier for everyone to read (including you)
And please use some classes and/or functions. Everything just crammed into main() is a certain recipe for a mess.