Skip to content

FallingBoard

A falling-block board, with no code: pieces of four blocks drop in at the top one after another, the player slides and turns them as they fall, and each locks where it lands. A row filled from side to side clears and the rows above drop down; every so many rows the game speeds up, and it’s over once a new piece has no room to come in. The blocks that have landed are the tiles of its entity’s Tilemap.

Part of the Falling Blocks module: Boards that pieces fall into, to be slid, turned and dropped so full rows clear (FallingBoard), the Falling Blocks template, and Create Falling Board in the Entity menu.

The board is Columns by Rows cells from the tilemap’s top left. Left and right (arrows, A and D, the d-pad or the stick) slide the piece, held down they keep going; down drops it faster; up or the RotateAction turns it; the DropAction drops it all the way at once. Each kind of piece lands as its own tile (from FirstTile), so a tileset gives each its look; without a tileset image each kind draws as a square of its own color. Tiles painted on the board to begin with are blocks already there. The tiles, score, rows and level are saved with the scene, and the piece falling and those to come are kept with rewind snapshots, so a rewind goes back to just where it was. In a network game the host runs the board and any player can move the piece.

Requires: Tilemap (holds the blocks that have landed)

Works with: Counter (shows the score (Output “Score”), the rows cleared (“Lines”) or the level (“Level Up”, starting at 1))

Takes the player’s input only while it has focus (its Controllable): its Focus action hands it the input and takes it from everything else the same player plays.

Draws itself, along with the rest of its entity (it doesn’t set the entity’s draw order).

In a network game, it also sends values of its own besides its properties.

Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.

  • columns: a whole number = 10. Cells across. (Field: a number.)
  • rows: a whole number = 20. Cells down. (Field: a number.)
  • pieces: text = “IJLOSTZ”. The shapes that come, by letter: I (four in a line), J, L, O (a square), S, T and Z. Each comes once in every round of them, shuffled, so none is kept away for long. “IIO” would deal twice as many I’s as O’s. (The pieces, by letter (I, J, L, O, S, T, Z), each written as many times as it comes, e.g. “IJLOSTZ” for one of each or “IIZ” for twice as many I’s. The Inspector has a count for each.) (Field: its own editor: Letter Counts.)
  • firstTile: a whole number = 0. The tile the I lands as; the J lands as the next, then L, O, S, T and Z. (Tiles of the tilemap’s tilesets by number (the first tileset’s from 0, the next’s from 100, then 200…): a string of numbers and ranges like “10-15, 20”, or for a whole number one tile. The Inspector shows the tiles to click.) (Field: its own editor: Tile Numbers.)
  • seed: a whole number = 0. Picks the order the pieces come in: the same number always gives the same ones. 0 is different each game. (Field: a number.)
  • paused: true or false = false. True while it stands still: the piece doesn’t fall and takes no moves. Its Pause and Resume actions set it. (Field: on or off.)
  • fallTime: a number = 0.8. Seconds a piece takes to fall one row at level 1. (Field: a number.)
  • speedup: a number = 0.8. How much faster each level falls: each level’s fall takes this much of the one before’s time (0.8 is a fifth quicker). (Field: a number.)
  • linesPerLevel: a whole number = 10. Rows to clear for each level: every this many, the level goes up and the pieces fall faster. 0 never speeds up. (Field: a number.)
  • level: a whole number = 1. The level now, from 1. Set it higher to start faster. Saved with the scene, so a rewind takes it back. (Field: a number.)
  • softDropTime: a number = 0.04. Seconds a row while down is held: the soft drop. (Field: a number.)
  • lockTime: a number = 0.5. Seconds a piece rests on what’s under it before it locks. Sliding or turning it starts the wait again (a few times). (Field: a number.)
  • clearTime: a number = 0.3. Seconds full rows flash before they clear and the rows above drop. (Field: a number.)
  • points: a whole number = 100. Points for clearing one row, times the level. Two rows at once score three times as much, three five times, four eight times. (Field: a number.)
  • score: a whole number = 0. The points scored so far. Saved with the scene, so a rewind takes them back. (Field: a number.)
  • lines: a whole number = 0. How many rows have been cleared. Saved with the scene, so a rewind takes them back. (Field: a number.)
  • gameOver: true or false = false. True once the blocks have stacked up to the top and a new piece has no room: nothing more falls. Saved with the scene. (Field: on or off.)
  • controllable: true or false = true. Untick it to have the board ignore the keys and gamepad while its piece falls on: another part of the scene has the player’s input. Its Focus action ticks it and unticks it on everything else the player plays, and the player’s own Focus gives the input back. (Field: on or off.)
  • rotateAction: text = “Fire”. The input action that turns the piece clockwise, as up does: “Fire” is J, the gamepad’s X or the right shoulder. Empty only uses up. (Names an input action.) (Field: a name.)
  • dropAction: text = “Jump”. The input action that drops the piece all the way down at once: “Jump” is Space or the gamepad’s A. Empty for none. (Names an input action.) (Field: a name.)
  • repeatDelay: a number = 0.17. Seconds left or right is held before the piece keeps sliding. (Field: a number.)
  • repeatEvery: a number = 0.05. Seconds between each cell the piece slides while left or right is held. (Field: a number.)
  • background: a color, “#RRGGBB” or “#RRGGBBAA” = “#10141CB0”. A color drawn behind the board’s cells. Transparent draws nothing. (Field: a color.)
  • ghost: a color, “#RRGGBB” or “#RRGGBBAA” = “#FFFFFF40”. The color of the outline showing where the piece will land. Transparent shows none. (Field: a color.)
  • preview: a whole number = 3. How many of the pieces coming next to show, beside the board on the right. 0 shows none. (Field: a number.)
  • moveSound: text = null. A sound played as the piece slides a cell, e.g. “Sounds/select.wav”. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • rotateSound: text = null. A sound played as the piece turns. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • lockSound: text = null. A sound played as a piece locks into place. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • clearSound: text = null. A sound played as full rows clear. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • levelUpSound: text = null. A sound played as the level goes up. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • gameOverSound: text = null. A sound played when the game is over. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • linesMessage: text = “Lines”. A message sent with Game.Send as rows clear, with how many as its data: a Counter listening for it adds them up. (Names a message.) (Field: a name.)
  • scoreMessage: text = “Score”. A message sent as rows clear, with the points they scored as its data: a Counter listening for it (its Message is “Score” to begin with) shows the score. (Names a message.) (Field: a name.)
  • levelMessage: text = “Level Up”. A message sent as the level goes up, with how many levels it went up (1) as its data: a Counter listening for it, starting at 1, shows the level. (Names a message.) (Field: a name.)
  • gameOverMessage: text = “Game Over”. A message sent once the game is over, with this entity as its data: a panel with this as its Open Message shows it. (Names a message.) (Field: a name.)

What anything can make it do with no code: a Trigger’s do when its message arrives, a Contraptions Wire’s input as its signal comes on, a script’s Game.Do(entity, “Name”).

  • Pause. Stops the board where it is: the piece doesn’t fall and takes no moves, until it’s resumed.
  • Resume. Lets a paused board go on.
  • Restart. Starts the board over at the start of the next frame: empty, at the level it started at, with no score or lines.
  • Focus. Gives its entity the player’s input: whatever there and inside it has focus, and everything else the same player plays loses it (a platformer’s player stops on the arrow keys while a board takes them).

What anything can read with no code: a Counter’s, Bar’s or Text’s output, a Contraptions Wire’s output as its signal; Text shows names too, the rest read numbers, true as 1.

  • Level (a whole number). The level now, from 1. Set it higher to start faster. Saved with the scene, so a rewind takes it back.
  • Score (a whole number). The points scored so far. Saved with the scene, so a rewind takes them back.
  • Lines (a whole number). How many rows have been cleared. Saved with the scene, so a rewind takes them back.
  • GameOver (true or false). True once the blocks have stacked up to the top and a new piece has no room: nothing more falls. Saved with the scene.

Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.

  • piece: text. The shape of the piece falling now, e.g. “T”, or null between pieces.
  • pieceAt: [x, y], whole numbers or null. The cell of the falling piece’s box’s top left (it may be off the board), or null between pieces.
  • rotation: a whole number. How many quarter turns clockwise the falling piece has made, 0 to 3.
  • nextPieces: text. The shapes coming next, first first, e.g. “SZO”: as many as Preview shows, or more.
  • isClearing: true or false. True while full rows are clearing: the next piece waits.

Scripts use it as FallingBoard: its methods, events and values that aren’t saved with the scene.