### SFML 2.x BreakOut Help!

Hi guys, i've been trying to make the classic breakout game using SFML. I have the following problems:

1) I cant figure out an easy way to make the bricks, stacked side by side!
2) I cant figure out how to make the ball movement after collision look uhm "Natural!"

Please check my code for what i've got and suggest improvements, thanks!

This code is a modification from:
http://www.cplusplus.com/forum/general/116059/

i think i need something like this to make the bricks
 1234 bricks[0].setPosition(0,0); for ( int j = 0; j < 5; j++) for(int i = 1; i < 100; i++) bricks[i].setPosition(bricks[i-1].getPosition().x + bricks[i].getSize().x, j);
but just couldnt get it to work :(
Thanks for u help guys!
This is how I do it
 12345678910111213141516 #define BLOCK_W 60 //block width #define BLK_BUF 100 //border spacing #define BLOCK_H 20 //block height ... for (int i = 0; i < 6; ++i)//rows { float y = BLK_BUF + BLOCK_H / 2.f + (BLOCK_H + 1) * i;//calc y based on row index for (int j = 0; j < 10; ++j)//cols { float x = BLK_BUF + BLOCK_W / 2.f + (BLOCK_W + 1) * j;//calc x based on col index std::uint32_t index = static_cast(fmod(i + j, 6));//pick a color for the block blocks.emplace_back( Block({ x, y }, colors[index], (index + 1) * 10)//construct block inplace ); } }
Thanks for the reply naraku9333 though i coldnt understand the logic in your code!, m still a beginner!..

I did however manage to get my for loop working , and look like this:

 123456789 for ( int i = 0; i < 10; i++) { bricks[i+200].setPosition(0,i*13); for(int j = i*20+1; j < 20+i*20; j++) { bricks[j].setPosition(bricks[j-1].getPosition().x + bricks[j].getSize().x, i*13); } }

Thanks again!
Topic archived. No new replies allowed.