5.3 KiB
Game logic
This section will detail how the player's action are interpreted into the game.
We will only talk about pieces and not polyominos. In this project, pieces are an abstraction of a polyomino. Though if you want to know more the polyominos in this project, check this other file.
Order of operations
Each frame, the UI will translate the user's input into a series of action to apply to the game. The list of action is the following:
- Pause
- Retry
- Hold
- Move left
- Move right
- Rotate clockwise (CW)
- Rotate 180°
- Rotate counter-clockwise (CCW)
- Soft drop
- Hard drop
Pausing and retrying are managed by the UI.
IHS and IRS are always tested first (see the leniency mechanics section).
Then the rest of actions will be tested in the list's order.
Finally, gravity and lock delay are applied last.
Moving and soft dropping can be held but hard dropping, holding and rotating needs to be released and pressed again to happen.
Leniency mechanics
In a general sense, we try to be kind to the players. Some of the following mechanics are just standards in a lot of stacker games, while other have been added because of this game using polyominos of high sizes and thus being way harder to play.
When a piece touches the ground, there is a short time period before she automatically locks. This period is called lock delay. Lock delay is reset everytime the piece move. To not allow for infinite stalling, there is another longer period called forced lock delay that does not reset when moving the piece.
The player as a hold box in which they can temporarly store a piece. In this game, we allow the player to swap between the held piece and the active piece as much as they want. Once again to not allow for infinite stalling, forced lock delay does not reset when holding a piece.
If either holding or rotating happens during frames where no piece is in the board, they will be memorized and immediately applied upon spawning the next piece. This can sometime prevent the player from loosing when the default spawn would have lost the game. This is called IRS and IHS, for Instant Rotation/Hold System.
IRS and IHS will fail if they actually loose the player the game when it would have not happened otherwise. In the same sense, holding always fails if it would loose the game.
Kicking pieces
A common mechanic of stacker games is kicking. This happen when rotating a piece makes it collide with a wall. The game will try to move the piece in a few predetermined spot close to the current position until one of them allow the piece to not be in a wall again. If no positions allow for that, the rotation is simply cancelled.
This concept works very well for games with up to tetrominos or pentominos, but when using polyominos of any size we can't choose a few predetermined spots for each piece.
Since this game uses polyomino of high sizes which are very unplayable, we will try to be complaisant to the player and allow as much kicking spots as possible, while trying not to make him feel like the piece is going through walls. To solve this problem, this game introduce a new Rotation System called AutoRS, which does not have a predetermined list of spots to fit the piece but instead adapt to its shape. Its algorithm goes as follow:
- Before rotating, mark every cell containing the piece or touching the piece, we will call the set of all theses cells the
safeCells - Rotate the piece, if it fit stop the algorithm
- Try fitting the piece, going from the center to the sides, that means we try to move the piece 1 cell right, then 1 cell left, then 2 cell right, etc. until it fit (and then stop the algorithm), if at one point a position doesn't touch one of the
safeCellswe stop trying in this direction - Move the piece one line down, and repeat step 3 again, until we hit a line were the first position (shifted by 0 cells horizontally) touched none of the
safeCells - Do the same as step 4 but now we move the piece one line up every time
- Cancel the rotation
Detecting spins
Another common mechanic of stacker games that goes alongside kicking is spinning. A spin is a special move (a move is calculated once a piece has been locked to the board) which usually happen when the last move a piece did was a kick or a rotation and the piece is locked in place, but the rules varies a lot from game to game.
Since we deal with a great deal of different size and shapes, the rules for spin dectection have been simplified greatly:
- A move is a spin if the piece is locked in place, that is it can't be moved one cell up, down, left or right without hitting a wall
- A move is a mini spin if the move isn't a spin and the last action of the piece was a kick (dropping down because of gravity counts as an action)
Score calculation
- For every cell soft dropped, add 1 to the score
- For every cell hard dropped, add 2 to the score
- When clearing one line, add 100 to the score, 200 for 2 lines, 400 for 3 lines, 800 for 4 lines, 1600 for 5 lines, etc.
- If the line clear is a spin, count the score like a normal clear of 2x more line (200 for 1-line spin, 800 for 2, 3200 for 3, etc.)
- When performing a spin, a mini spin, or clearing 4 or more lines, B2B is activated, every subsequent line clear that is a spin, a mini spin, or clear 4 or more lines, scores twice as much