Your code is very good for beginner! Congrats. I like that you use some neat modern C++ stuff and most of your code is pretty readable.
But I can add more stuff to what
GraphicsWhale said to improve your code.
1) Don't write code like this:
if(...)
expression
This style leads to some nasty bugs when you try to add another expression after this one and you end up like this:
if(...)
expression
expression2
This compiles fine, but it doesn't behave like it should.
So, always use braces for
if,
while and
for statements even if they have a single expression.
if(...) {
expression
}
2) Your Ball struct should really be a class. You already defined some getters for most variables, why not make the rest private and define getters for them as well? The same goes for other structs.
And make member functions const, if you're not changing anything inside them.
3) Don't use magic numbers in your code. You've already defined a lot of constants, which is good, why not define constants for the rest of the numbers you use?
This line is especially unreadable.
(iX + 1) * (blockWidth + 3) + 22, (iY + 2) * (blockHeight + 3));
4) Don't implicitly convert from int to float (or from any type!) as you do in this line, for example:
velocity.x = 0;
This line is not harmful, but implicit casting is a source of bugs in more complex code.
5) And, as GraphicsWhale noted, using
goto is bad most of the time.
Define init() function instead. It will set all main variables to initial state and reset the game.
If you use
goto, not only you make your code confusing, you do lots of unneccessary work reloading resources and recreating objects where you can do less work.
6) Separate input, update and drawing. Your main loop should look like this:
while(isRunning) {
auto dt = getDelta();
handleInput();
update(dt);
draw(window);
}
This may eliminate some bugs and will give much cleaner structure to the whole program.
I highly recommend you to check out
Effective C++ and
Code Complete. This books are very important and will help you become a better programmer.
Good luck! Hope I wasn't being too harsh. Feel free to ask any questions about stuff you're not sure about/disagree with.