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,29 +110,31 @@ class Block {
} }
int rotated_x = x; int rotated_x = x;
int rotated_y = y; int rotated_y = y;
int center_x = type->grid[0].size() / 2; if (type->rotate) {
int center_y = type->grid.size() / 2; int center_x = type->grid[0].size() / 2;
int offset_x = x - center_x; int center_y = type->grid.size() / 2;
int offset_y = y - center_y; int offset_x = x - center_x;
switch (rotation_state) { int offset_y = y - center_y;
case 0: switch (rotation_state) {
rotated_x = x; case 0:
rotated_y = y; rotated_x = x;
break; rotated_y = y;
case 1: break;
rotated_x = center_x + offset_y; case 1:
rotated_y = center_y - offset_x; rotated_x = center_x + offset_y;
break; rotated_y = center_y - offset_x;
case 2: break;
rotated_x = center_x - offset_x; case 2:
rotated_y = center_y - offset_y; rotated_x = center_x - offset_x;
break; rotated_y = center_y - offset_y;
case 3: break;
rotated_x = center_x - offset_y; case 3:
rotated_y = center_y + offset_x; rotated_x = center_x - offset_y;
break; rotated_y = center_y + offset_x;
default: break;
rotation_state %= 4; default:
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;

Loading…
Cancel
Save