|
|
|
@ -164,13 +164,6 @@ bool Board::init(const std::string& path, int splitting)
|
|
|
|
|
if (!global_texture.loadFromFile(path) )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (splitting <= 1) // If it's 1, the game is already over
|
|
|
|
|
{
|
|
|
|
|
sf::Sprite* sp = new sf::Sprite(global_texture);
|
|
|
|
|
vec_field.push_back(new Cell{0, 0, sp});
|
|
|
|
|
return true; // why not
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int width = global_texture.getSize().x;
|
|
|
|
|
const int height = global_texture.getSize().y;
|
|
|
|
|
|
|
|
|
@ -201,6 +194,37 @@ bool Board::init(const std::string& path, int splitting)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SCALING //
|
|
|
|
|
|
|
|
|
|
float scaling = 0.;
|
|
|
|
|
if (width > height && width > SCREEN_WIDTH)
|
|
|
|
|
scaling = static_cast<float>(SCREEN_WIDTH) / static_cast<float>(width);
|
|
|
|
|
if (height > width && height > SCREEN_HEIGHT)
|
|
|
|
|
scaling = static_cast<float>(SCREEN_HEIGHT) / static_cast<float>(height);
|
|
|
|
|
|
|
|
|
|
if (scaling != 0.)
|
|
|
|
|
{
|
|
|
|
|
int old_side_length = Cell::side_length;
|
|
|
|
|
Cell::side_length = static_cast<int>(static_cast<float>(Cell::side_length) * scaling);
|
|
|
|
|
int shift = Cell::side_length - old_side_length;
|
|
|
|
|
float move_x = 0.f;
|
|
|
|
|
float move_y = 0.f;
|
|
|
|
|
for (Cells::size_type i = 0; i < vec_field.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
move_x = 0.f;
|
|
|
|
|
move_y = 0.f;
|
|
|
|
|
if (!(((i % cells_on_width == 0) && (i >= cells_on_width)) || i == 0))
|
|
|
|
|
move_x = static_cast<float>(shift) * static_cast<float>((i < cells_on_width) ? i : i % cells_on_width);
|
|
|
|
|
if (i >= cells_on_width)
|
|
|
|
|
move_y = static_cast<float>(shift) * static_cast<float>(i / cells_on_width);
|
|
|
|
|
|
|
|
|
|
vec_field[i]->sprite->scale(scaling, scaling);
|
|
|
|
|
vec_field[i]->sprite->move(move_x, move_y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SHUFFLING //
|
|
|
|
|
|
|
|
|
|
srand(static_cast<unsigned int>(time(nullptr)));
|
|
|
|
|