0.3.0-beta • Published 2 years ago

minojs v0.3.0-beta

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
2 years ago

MinoJS

MinoJS is a lightweight javascript library for building block-stacking games such as Tetris. MinoJS provides a layer of abstraction around core game logic, and your app handles graphics/UI updates based on the emitted events. Implement one of the game modes that are ready use, or extend MinoCore/TetraCore to handle your own timing and scoring logic without starting from the ground up.

Reference Hard Drop's glossary of Tetris jargon for terms used in this doc

Installation

npm install minojs

MinoCore

MinoCore maintains the game state and implements base functionality that should be applicable to most games. When you call a function to request some action, it will return a list of resulting events. MinoCore handles:

  • Playfield, next preview, and hold queue state management
  • Generating UI-friendly grid arrays
  • Piece queuing, spawning, "Random Generator" (ie 7-bag randomization)
  • Piece movement: left/right shifting, collisions, dropping and locking, hard drops, support logic for rotation implementations
  • Clearing lines
  • Ghost/shadow piece tracking
  • Game end detection: Block out and lock out
  • Coming soon: Finesse
  • Configurations available: number of rows/columns on the playfield, size of next preview, piece shapes, and randomization method (see core/core.json for the defaults)

TetraCore

Extension of MinoCore.js meant for games which use 4-block tetrominos, such as Tetris. Here's what TetraCore handles:

  • All features from MinoCore.js
  • SRS rotation
  • Coming soon: T-spin detection
  • Configurations available: Rotation offsets for SRS (see core/core.json for the defaults)

Game modes

Complete game classes which are built around TetraCore and handle user input processing and game timing. They also handle:

  • Implementing DAS, ARR, auto-dropping, hard/soft drops, etc.
  • Reporting statistics/game info including formatted game time, PPS, KPP, cleared lines, number of blocks dropped, etc.
  • Configurations available for all modes (all lintervals and delays are in milliseconds): DAS, ARR, game clock interval, drop interval, drop lock delay, max allowed active time, soft drop interval, DAS-preservation enabled, DAS-interuption enabled, and scoring point values. See modes/modes.json for the defaults)

Sandbox

MinoJS includes a barebones implementation of TetraminoGame.js written in Svelte. It's used for developing/testing this library and could be a good resource. Here's how to run it.

git clone https://github.com/jspin-dev/minojs.git
cd minojs/sandbox
npm install
npm run dev

Tip: To set your preferred game settings and keybindings, modify sandbox/sandboxLocal.json