+ 2

Tetris game, rotating near a wall

Hello , so I'm writing a Tetris game with my friend using C++, and we managed to complete the foundation, but now we're fixing the small bugs. We created a class called "Shape", which creates all the other shapes, but we're having trouble with the rotation near the walls. How can we check if a shape can rotate near a wall in the most efficient way? I mean for example, the line shape and the T shape have different rotations, so how can we somehow check for both of them in a single function? Thanks!

12th Jan 2018, 9:05 PM
Martin
Martin - avatar
2 Answers
+ 1
It depends on specific details in the code you already wrote, but one way that should work is to simulate what the result of it rotating would be without rendering, checking whether or not each block on the shape is within the boundaries, and undoing it if it is not valid. There’s probably a more efficient way to do this, but I don’t know any without seeing how shapes work in detail.
12th Jan 2018, 9:14 PM
Jacob Pembleton
Jacob Pembleton - avatar
0
Well I thought of using an enum to check each shape separately with it's own conditions on the rotation, I was just wondering if there might be some trickier way to do it ^^`` By the way, the rotations are like this: https://i.stack.imgur.com/JLRFu.png
12th Jan 2018, 10:06 PM
Martin
Martin - avatar