Falling Tetromino Engine
A backend with ergonomic API for games where tetrominos fall and stack.
Installation
Add this to your Cargo.toml:
[]
= "1.2.0"
About
The engine is completely frontend-agnostic, although calls to Game::update may optionally return additional info to facilitate implementation of visual effects.
The engine allows for compile-time mods which may arbitrarily access and modify game state during gameplay.
The engine aims to compete on the order of modern tetromino stackers; It incorporates many features found in such games. Experienced players may be familiar with most of the following mechanics:
- Variable gravity/fall delay (frame-agnostic); '20G' (= 0s fall delay),
- Simple but flexible programming of custom fall and lock delay progressions (
DelayParameters), - (Arbitrary) piece preview,
- Pre-spawn actions toggle ('Initial Hold/Rotation System'),
- Rotation systems: 'Ocular' (engine-specific, playtested), 'Classic', 'Super',
- Tetromino generators: 'Uniform', 'Stock' (generalized Bag), 'Recency' (history), 'Balancerelative',
- Spawn delay (ARE),
- Delayed auto-shift (DAS),
- Auto-repeat rate (ARR),
- Soft drop factor (SDF),
- Lenient lock delay reset toggle (reset lock delay even if rotate/move fails),
- Ensure move delay less than lock delay toggle (DAS/ARR automatically shortened when lock delay is very low),
- Lock-reset-cap factor (~maximum time before lock delay cannot be reset),
- Line clear duration (LCD),
- Custom win/loss conditions based on stats: time, pieces, lines, score,
- Hold piece,
- Higher score for larger lineclears and spins ('allspin')
- Game reproducibility (PRNG),
- Available player actions: MoveLeft, MoveRight; RotateLeft, RotateRight, Rotate180; DropSoft, DropHard, TeleDown ('Sonic drop'), TeleLeft, TeleRight, HoldPiece.
Example Usage
use *;
// Starting up a game - note that in-game time starts at 0s.
let mut game = builder
.seed
/* ...Further optional configuration possible... */
.build;
// Updating the game with the info that 'left' should be pressed at second 4.2;
// If a piece is in the game, it will try to move left.
let input = Activate;
game.update;
// ...
// Updating the game with the info that no input change has occurred up to second 6.79;
// This updates the game, e.g., pieces fall and lock.
game.update;
// Read most recent game state;
// This is how a UI can know how to render the board, etc.
let State = game.state;
Internally, the game keeps its own timeline:
0s - Game start; Piece is spawned.
/ 4.2s - Player input; Piece starts moving left.
/ / 6.79s - Piece will have moved left some more,
/ / / has been affected by gravity etc.
[--------|------------¦--------------- - - - ->
Overview by Types
Much of the implementation is tightly encoded into types.
// The central engine type.
It may be instructive to simply consider the main type definitions as a tentative overview of the deeper engine mechanics.
Types used as Game fields
Other Important Types
See full documentation.