Advertisement
Amorf

Untitled

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