4 #include "nlohmann/json.hpp" 5 #include "../gui/entity_sfml/player_sfml/player_sfml.h" 6 #include "../gui/entity_sfml/ball_sfml/ball_sfml.h" 7 #include "../gui/entity_sfml/wall_sfml/wall_sfml.h" 8 #include "../gui/entity_sfml/block_sfml/block_sfml.h" 9 #include "../gui/entity_sfml/block_sfml/special_block_sfml/ball_speed_block_sfml.h" 10 #include "../gui/entity_sfml/block_sfml/special_block_sfml/player_speed_block_sfml.h" 11 #include "../gui/entity_sfml/block_sfml/special_block_sfml/invis_block_sfml.h" 18 #include <unordered_map> 21 using json = nlohmann::json;
32 vector<unique_ptr<arkanoid::Wall>> walls;
35 for(
double y = 0.0; y < 700.0; y += 32.0) {
38 walls.push_back(std::move(wall));
42 walls.push_back(std::move(wall));
46 for(
double x = 0.0; x < 900.0; x += 32) {
48 walls.push_back(std::move(wall));
56 ifstream stream(file);
59 throw runtime_error(
"Couldn't open " + file);
66 throw runtime_error(
"Couldn't parse " + file);
69 vector<unique_ptr<arkanoid::Block>> blocks;
73 vector<vector<string>> data = jsonFile[
"blocks"].get<vector<vector<string>>>();
75 constexpr
double offset = 32.0;
76 constexpr
double blockSizeW = 64.0;
77 constexpr
double blockSizeH = 32.0;
78 for(
double r = 0; r < data.size(); r++) {
79 for(
double c = 0; c < data[r].size(); c++) {
82 if(data[r][c] ==
"Y" || data[r][c] ==
"P") {
85 double speedFactor = 0.0;
87 if(data[r][c] ==
"Y") {
95 unique_ptr<arkanoid::Block> block(
new arkanoidSFML::BallSpeedBlockSFML(offset + blockSizeW*c, offset + blockSizeH*r, windowSFML, speedFactor,
"data/sprites/blocks/" + color +
"_block.png"));
96 blocks.push_back(std::move(block));
98 }
else if(data[r][c] ==
"R") {
100 unique_ptr<arkanoid::Block> block(
new arkanoidSFML::InvisBlockSFML(offset + blockSizeW*c, offset + blockSizeH*r, windowSFML,
"data/sprites/blocks/red_block.png"));
101 blocks.push_back(std::move(block));
103 }
else if(data[r][c] ==
"G") {
105 unique_ptr<arkanoid::Block> block(
new arkanoidSFML::PlayerSpeedBlockSFML(offset + blockSizeW*c, offset + blockSizeH*r, windowSFML, 2.0,
"data/sprites/blocks/green_block.png"));
106 blocks.push_back(std::move(block));
108 }
else if(data[r][c] ==
"B") {
110 unique_ptr<arkanoid::Block> block(
new arkanoidSFML::BlockSFML(offset + blockSizeW*c, offset + blockSizeH*r, windowSFML,
"data/sprites/blocks/blue_block.png"));
111 blocks.push_back(std::move(block));
118 throw runtime_error(
"Invalid data in " + file);
The SFML element that represents the arkanoid::Ball in the game.
unique_ptr< arkanoid::Player > createPlayer()
The SFML element that represents the arkanoid::InvisBlock in the game.
vector< unique_ptr< arkanoid::Wall > > createWalls()
The SFML element that represents the arkanoid::Block in the game.
The SFML element that represents the arkanoid::Player in the game.
SFMLFactory(sf::RenderWindow &window)
vector< unique_ptr< arkanoid::Block > > createBlocks(const string &file)
The SFML element that represents the arkanoid::PlayerSpeedBlock in the game.
The SFML element that represents the arkanoid::Wall in the game.
The SFML element that represents the arkanoid::BallSpeedBlock in the game.
unique_ptr< arkanoid::Ball > createBall()