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
M

Matthaeus Jumpertz

@Matthaeus Jumpertz
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • [Code Review] [SFML] Simple Breakout/Arkanoid Clone + Asking for some help
    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 /

    C / C++ / MFC help game-dev announcement code-review
  • Login

  • Don't have an account? Register

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