Prevent O block from rotating

cpp
Elnu 3 years ago
parent 20222ad686
commit 4d3e1d3b2d

@ -38,9 +38,11 @@ class BlockType {
} }
TileType* tile_type; TileType* tile_type;
std::vector<std::vector<bool>> grid; std::vector<std::vector<bool>> grid;
BlockType(TileType* _tile_type, const std::vector<std::vector<bool>> _grid) { bool rotate;
BlockType(TileType* _tile_type, const std::vector<std::vector<bool>> _grid, bool _rotate = true) {
tile_type = _tile_type; tile_type = _tile_type;
grid = _grid; grid = _grid;
rotate = _rotate;
} }
}; };
@ -64,7 +66,7 @@ BlockType BlockType::l(&TileType::green, {
BlockType BlockType::o(&TileType::blue, { BlockType BlockType::o(&TileType::blue, {
{1, 1}, {1, 1},
{1, 1} {1, 1}
}); }, false);
BlockType BlockType::s(&TileType::yellow, { BlockType BlockType::s(&TileType::yellow, {
{0, 1, 1}, {0, 1, 1},
{1, 1, 0}, {1, 1, 0},
@ -108,6 +110,7 @@ class Block {
} }
int rotated_x = x; int rotated_x = x;
int rotated_y = y; int rotated_y = y;
if (type->rotate) {
int center_x = type->grid[0].size() / 2; int center_x = type->grid[0].size() / 2;
int center_y = type->grid.size() / 2; int center_y = type->grid.size() / 2;
int offset_x = x - center_x; int offset_x = x - center_x;
@ -132,6 +135,7 @@ class Block {
default: default:
rotation_state %= 4; rotation_state %= 4;
} }
}
int global_x = rotated_x + position.x; int global_x = rotated_x + position.x;
int global_y = rotated_y + position.y; int global_y = rotated_y + position.y;
tiles.push_back(sf::Vector2i(global_x, global_y)); tiles.push_back(sf::Vector2i(global_x, global_y));

Loading…
Cancel
Save