Hi, Im doing this small breakout clone for school, I've looked at heaps of people's takes on Breakout and tried to combine bits and pieces that I liked. Only problem that I'm having is getting the game to end when the ball hits the bottom window edge + sounds.. You should be able to copy/paste the code into a project, only issues being with the sound and text. Thanks a lot

void update(){//Need to make the ball bounce of the window edges shape.move(velocity);//If it's leaving on the left edge, we set a positive horizontal value.if(left()<0) velocity.x= ballVelocity;//Same for the rightelseif(right()> windowWidth) velocity.x=-ballVelocity;//Topif(top()<0) velocity.y= ballVelocity;//And bottomelseif(bottom()> windowHeight) velocity.y=-ballVelocity;

//Class for the paddlestruct Paddle :public Rectangle{//Create a variable for speed. Vector2f velocity;//Set the variables for the paddle rectangle shape. Paddle(float mX, float mY){ shape.setPosition(mX, mY); shape.setSize({ paddleWidth, paddleHeight }); shape.setFillColor(Color::Red); shape.setOrigin(paddleWidth /2.f, paddleHeight /2.f);}// Within the update function we check if the player is moving the paddlevoid update(){ shape.move(velocity);//To ensure that the paddle stays inside the window we only change the Velocity when it's inside the boundaries//Making it impossible to move outside when the initial velocity is set to zeroif(Keyboard::isKeyPressed(Keyboard::Key::Left)&& left()>0) velocity.x=-paddleVelocity;

elseif(Keyboard::isKeyPressed(Keyboard::Key::Right)&& right()< windowWidth) velocity.x= paddleVelocity;//If the player isn't pressing a buttom (legt/right) the velocity is set to zero.else velocity.x=0;}};//Another class for the bricksstruct Brick :public Rectangle{bool destroyed{false};

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: