Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. [Code Review] [SFML] Simple Breakout/Arkanoid Clone + Asking for some help

[Code Review] [SFML] Simple Breakout/Arkanoid Clone + Asking for some help

Scheduled Pinned Locked Moved C / C++ / MFC
helpgame-devannouncementcode-review
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Matthaeus Jumpertz
    wrote on last edited by
    #1

    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 /

    L D 2 Replies Last reply
    0
    • M Matthaeus Jumpertz

      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 /

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Please read http://www.codeproject.com/Messages/2922875/HOW-TO-ASK-A-QUESTION.aspx[^].

      1 Reply Last reply
      0
      • M Matthaeus Jumpertz

        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 /

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups