Advertisement
Amorf

Untitled

Dec 14th, 2021
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. bool Level::rotate()
  2. {
  3.     Piece *tmp = current;
  4.     // Move the piece if it needs some space to rotate
  5.     int disX = max(posX + current->getHeight() - width, 0);
  6.     // Go to next rotation state (0-3)
  7.     int rotation = (current->getRotation() + 1) % PieceSet::NUM_ROTATIONS;
  8.     clear(*current);
  9.     current = pieceSet.getPiece(current->getId(), rotation);
  10.     // Rotate successfully
  11.     if (place(posX - disX, posY, *current))
  12.         return true;
  13.     // If the piece cannot rotate due to insufficient space, undo it
  14.     current = tmp;
  15.     place(posX, posY, *current);
  16.     return false;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement