[Code Review] [SFML] Simple Breakout/Arkanoid Clone + Asking for some help
-
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
#include
#include
#include
#include
using namespace std;
using namespace sf;
int x = 5;
constexpr int windowWidth ( 800 ), windowHeight( 600 );
constexpr float ballRadius( 10.f ), ballVelocity( 6.f );
constexpr float paddleWidth( 100.f ), paddleHeight( 20.f ), paddleVelocity( 8.f );
constexpr float blockWidth( 60.f ), blockHeight( 20.f );
constexpr int countBlocksX( 11 ), countBlocksY( 6 );
constexpr int countBlocks2X(11), countBlocks2Y(3);
bool isPlaying = true;struct Ball
{
CircleShape shape;
Vector2f velocity{ -ballVelocity, -ballVelocity };Ball(float mX, float mY) { shape.setPosition(mX, mY); shape.setRadius(ballRadius); shape.setFillColor(Color::Yellow); shape.setOrigin(ballRadius, ballRadius); } 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 right else if (right() > windowWidth) velocity.x = -ballVelocity; //Top if (top() < 0) velocity.y = ballVelocity; //And bottom else if (bottom() > windowHeight) velocity.y = -ballVelocity; } float x() { return shape.getPosition().x; } float y() { return shape.getPosition().y; } float left() { return x() - shape.getRadius(); } float right() { return x() + shape.getRadius(); } float top() { return y() - shape.getRadius(); } float bottom() { return y() + shape.getRadius(); }
};
//Create the Rectangle shape class for the brick
struct Rectangle
{
RectangleShape shape;
float x() { return shape.getPosition().x; }
float y() { return shape.getPosition().y; }
float left() { return x() - shape.getSize().x / 2.f; }
float right() { return x() + shape.getSize().x / 2.f; }
float top() { return y() - shape.getSize().y / -
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
#include
#include
#include
#include
using namespace std;
using namespace sf;
int x = 5;
constexpr int windowWidth ( 800 ), windowHeight( 600 );
constexpr float ballRadius( 10.f ), ballVelocity( 6.f );
constexpr float paddleWidth( 100.f ), paddleHeight( 20.f ), paddleVelocity( 8.f );
constexpr float blockWidth( 60.f ), blockHeight( 20.f );
constexpr int countBlocksX( 11 ), countBlocksY( 6 );
constexpr int countBlocks2X(11), countBlocks2Y(3);
bool isPlaying = true;struct Ball
{
CircleShape shape;
Vector2f velocity{ -ballVelocity, -ballVelocity };Ball(float mX, float mY) { shape.setPosition(mX, mY); shape.setRadius(ballRadius); shape.setFillColor(Color::Yellow); shape.setOrigin(ballRadius, ballRadius); } 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 right else if (right() > windowWidth) velocity.x = -ballVelocity; //Top if (top() < 0) velocity.y = ballVelocity; //And bottom else if (bottom() > windowHeight) velocity.y = -ballVelocity; } float x() { return shape.getPosition().x; } float y() { return shape.getPosition().y; } float left() { return x() - shape.getRadius(); } float right() { return x() + shape.getRadius(); } float top() { return y() - shape.getRadius(); } float bottom() { return y() + shape.getRadius(); }
};
//Create the Rectangle shape class for the brick
struct Rectangle
{
RectangleShape shape;
float x() { return shape.getPosition().x; }
float y() { return shape.getPosition().y; }
float left() { return x() - shape.getSize().x / 2.f; }
float right() { return x() + shape.getSize().x / 2.f; }
float top() { return y() - shape.getSize().y / -
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
#include
#include
#include
#include
using namespace std;
using namespace sf;
int x = 5;
constexpr int windowWidth ( 800 ), windowHeight( 600 );
constexpr float ballRadius( 10.f ), ballVelocity( 6.f );
constexpr float paddleWidth( 100.f ), paddleHeight( 20.f ), paddleVelocity( 8.f );
constexpr float blockWidth( 60.f ), blockHeight( 20.f );
constexpr int countBlocksX( 11 ), countBlocksY( 6 );
constexpr int countBlocks2X(11), countBlocks2Y(3);
bool isPlaying = true;struct Ball
{
CircleShape shape;
Vector2f velocity{ -ballVelocity, -ballVelocity };Ball(float mX, float mY) { shape.setPosition(mX, mY); shape.setRadius(ballRadius); shape.setFillColor(Color::Yellow); shape.setOrigin(ballRadius, ballRadius); } 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 right else if (right() > windowWidth) velocity.x = -ballVelocity; //Top if (top() < 0) velocity.y = ballVelocity; //And bottom else if (bottom() > windowHeight) velocity.y = -ballVelocity; } float x() { return shape.getPosition().x; } float y() { return shape.getPosition().y; } float left() { return x() - shape.getRadius(); } float right() { return x() + shape.getRadius(); } float top() { return y() - shape.getRadius(); } float bottom() { return y() + shape.getRadius(); }
};
//Create the Rectangle shape class for the brick
struct Rectangle
{
RectangleShape shape;
float x() { return shape.getPosition().x; }
float y() { return shape.getPosition().y; }
float left() { return x() - shape.getSize().x / 2.f; }
float right() { return x() + shape.getSize().x / 2.f; }
float top() { return y() - shape.getSize().y /Matthaeus Jumpertz wrote:
You should be able to copy/paste the code into a project, only issues being with the sound and text.
:laugh:
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles