Puzzles and boards
Sokoban crates and goals
Section titled “Sokoban crates and goals”In a scene with a grid player, Entity → Physics → Crate makes a grid crate: a Pushable with a Grid Movement of its own (and no gravity). A grid mover on one of its Layers (Player) that steps into it pushes it a cell the same way, the crate gliding along just ahead of it, as long as the cell beyond is free; a wall or another crate stops the push (the pusher bumps instead), unless the crate Pushes Row, when the crates behind it slide along too. Pushes go straight, never diagonally, and a Speed of 0 won’t budge. The crate never takes the player’s keys, plays its grid movement’s Step Sound as it slides, and raises Pushed with who pushed it and which way. Entity → Genres → Puzzles → Goal makes a goal: a flat square under the crates with a Goal, covered while a crate rests in its cell (once it has finished gliding there). A goal Accepts crates of the Kinds named (Red, Blue; empty takes any), turns the crate on it its Covered Tint, plays its Sound, and sends its Cover Message and Uncover Message; every goal with the same All Covered Message (Solved) sends it once they’re all covered: every crate home, the level solved. A crate that starts on a goal covers it from the start, without a sound or message. A Counter counting the Output Goals Covered of Track * (the first entity in the scene that has it) shows how many goals are covered, with {2} for how many there are (Crates: {0} / {2}). Taking turns, a push is the pusher’s step and uses its one action. In a network game a player’s push goes to the host, which moves the crate.
Undo and restart
Section titled “Undo and restart”A Move History makes each step a grid player takes (with any crates it pushes) a move to take back: its Undo Action (Undo: Z, U or the gamepad’s left shoulder) puts every grid mover back where it was before the last move, standing still and facing the way it was, and held down (Hold To Repeat) keeps going. Its Restart Action (Restart: R or the left trigger) puts them all back where the level started, as one more move Undo takes back; tick Restart Reloads to reload the scene from its file instead (fading over Fade seconds), so pickups, counters and scripts start over too. It puts back players, crates, and chasers and patrols (on the same stretch of their routes), but not what was collected or destroyed, nor counters, switches, inventories or whose turn it is. Limit caps how many moves it remembers (0 for all). Crates put back onto or off goals don’t play their sounds or send messages, and solving the puzzle again sends All Covered again. It plays its Undo Sound and Restart Sound and sends its Undo Message (with the moves taken as its data) and Restart Message. A Counter counting the Output Moves shows how many moves have been taken (Moves: {0}), counting back with each undo. The first goal Entity → Genres → Puzzles → Goal makes in a scene brings a Move History along. Scripts call Undo(), Restart() and Record() (to count a move of their own, like a teleport) and read Moves and CanUndo. In a network game there’s no undo, and anyone’s Restart starts the scene over for everyone. Set its Within to an entity’s name (Puzzle Room) and it covers only part of the scene: the grid movers inside that entity or standing in its area (a Room’s, a tilemap’s, a collider’s). Only their steps are moves, only they go back, and Undo and Restart work while a grid player with the input stands there (over the whole scene, while a grid player has the input, so a board given it doesn’t undo the puzzle); give each puzzle room in a bigger game its own (see Mixing genres).
The Puzzle template
Section titled “The Puzzle template”The Puzzle template is Sokoban made of these pieces, with no scripts: a menu of four levels, each button opening once the level before it is solved, and levels where a worker pushes crates onto the marks on a warehouse floor. Each level is its own scene (Level1 to Level4): a tilemap whose walls are solid and whose floor is a background tile, a grid player, grid crates and goals (each with All Covered Message Solved), and a Move History. Its HUD counts crates on marks and moves, and a Solved panel opens on Solved (its Open Message) saying how many moves it took, with Next, Again and Menu. A Progress counter listening for Solved saves the level as solved (its Save Best As), which is what the next level’s button Needs Saved. To add a level, duplicate a level scene, repaint its tilemap, move the crates and goals, have the last level’s Solved panel go on to it (its Menu button’s Scene), and add a button for it on the menu.
Match-3 boards
Section titled “Match-3 boards”Entity → Genres → Match-3 → Match Board makes a board: an 8 by 8 tilemap with a Match Board, centered in the view and dealt already so you see it. The gems are the tilemap’s tiles, one kind for each tile number in Gems (0-5: six kinds); without a tileset image each kind is a square of its own color, and with one they’re its tiles. Any other tile on the board is a fixed block that gems stop on. Drag a gem onto its neighbor (or click one, then the other) to swap them, or with keys and a gamepad move the cursor with the arrows, pick a gem up with the Pick Action (Jump: Space or A) and press an arrow to swap it that way. Three or more of a kind in a row or column (its Match Length) shrink away over Clear Time, the gems above fall into the gaps (speeding up as they fall, Fall Time a cell), new ones drop in from the top (or grow under a block) with Refill, and whatever lines up as they land clears too: a chain. With Only Matching Swaps, a swap that lines nothing up only nudges the two gems into each other’s cells and back. A board left with no swap to make is shuffled into one that has (Shuffle When Stuck). Each game it’s Dealt afresh with nothing lined up and a move to make, from its Seed (0 for a new board each time); untick Deal to play the gems as painted, a level laid out by hand. It plays its Swap Sound, Match Sound, No Match Sound and Shuffle Sound, and sends its Match Message (Match, with how many gems cleared, so a Counter listening for it adds them up), Chain Message (with how long the chain is from the second clear on), Settled Message (as the board comes to rest after a swap) and Shuffle Message. Swaps counts the swaps made. Scripts call Swap(x1, y1, x2, y2), FindMove() (a hint), Shuffle() and DealInto(map, random), read GemAt(x, y), IsBusy, Chain, Picked and Cursor, and hear Matched (each match’s kind, cells and place in the chain), Swapped and Settled. The tiles and Swaps are saved with the scene, so a rewind goes back to how the board was; Deal unticks itself once the board is dealt, so rewinding doesn’t deal a new one. In a network game the host runs the board, any player can swap with their own mouse or keys, and everyone sees the gems slide and fall.
Match-3 levels
Section titled “Match-3 levels”Each gem cleared scores the board’s Points (10), times how far along the chain it clears (the second clear after a swap scores double, the third triple), adding to its Score and sending its Score Message (Score, with the points), so a plain Counter shows the score. Moves limits the swaps (0 is no limit), Target Score is a score to reach, and Collect names gems to clear as kind:count pairs (0:20, 3:15: 20 of tile 0 and 15 of tile 3), counted in Cleared. Once the goals are met and the board comes to rest the level is won: it plays its Win Sound and sends its Win Message (Level Complete, so a panel with that Open Message shows the win). Use up the moves with the goals still to meet and it plays its Out Of Moves Sound and sends its Out Of Moves Message (Out of Moves), a board with no goals too, the end of a game played for score. Either way no more swaps are taken. Counters show the rest with no code: the Output Moves counts a board’s swaps ({2} its Moves, {3} how many are left: Moves: {3}), Score its score ({2} the Target Score: Score: {0} / {2}) and Cleared:1 the gems of one kind (1 is the tile) (that tile) cleared ({2} how many Collect asks for, {3} how many still to go: {0} / {2}). Scripts read MovesLeft, GoalsMet, IsOver, ClearedOf(kind) and ToCollect(kind), and hear Finished (true for a win). Score, Swaps and Cleared are saved with the scene, so a rewind takes them back, and in a network game players’ counters follow the host’s board.
The Match-3 template
Section titled “The Match-3 template”The Match-3 template is four levels of these boards, with no scripts: a menu whose level buttons each open once the level before is won, and levels (Level1 to Level4: First Sparkle, Ruby Hunt, Stone Garden and Grand Hoard) that each set a board’s Moves, Target Score and Collect, and which gems are in play (five kinds or six); the later ones have stone blocks in the board. Down the left a HUD shows the level, the score (Score), the moves left (Moves) and, for each kind to collect, its gem with a Cleared: counter. A Complete panel opens on the board’s Level Complete (its Open Message) with the score, Next, Again and Menu, and an Out of Moves panel on Out of Moves with Again and Menu. A Progress counter listening for Level Complete saves the level as won (Save Best As), which is what the next level’s button Needs Saved. The gems are a tileset of six cut gems (each its own shape as well as color) and a stone. To add a level, duplicate a level scene, change its board’s goals and moves (and paint stones on its tilemap), have the last level’s Complete panel go on to it, and add a button for it on the menu.
Falling blocks
Section titled “Falling blocks”Entity → Genres → Falling Blocks → Falling Board makes a board: a tilemap with a Falling Board 10 cells across (Columns) and 20 down (Rows), centered in the view. As the game runs, pieces of four blocks come in at the top, one after another, and fall a row every Fall Time (0.8 seconds). Left and right (the arrows, A and D, the d-pad or the stick) slide the piece, held down they keep sliding (after Repeat Delay, a cell every Repeat Every); down falls faster (Soft Drop Time a row); up or the Rotate Action (Fire: J, the gamepad’s X or the right shoulder) turns it clockwise, stepping it aside off a wall or out of the floor if it has to; the Drop Action (Jump: Space or A) drops it all the way at once. A piece that rests on something for Lock Time locks into the board’s tilemap (sliding or turning it starts that wait again, a few times over), and an outline in the Ghost color shows where it would land. A row filled from side to side flashes for Clear Time and clears, the rows above dropping down; rows cleared at once score Points (100) times the Level, three times as much for two rows, five for three and eight for four, adding to Score and Lines. Every Lines Per Level rows the Level goes up, and each level falls in Speedup (0.8) of the time the one before did. Once a new piece has no room to come in, the game is over (Game Over). Each shape lands as its own tile (the I as First Tile, then J, L, O, S, T and Z), so a tileset gives each its look; without one each is a square of its own color. Pieces picks the shapes that come (IJLOSTZ: each comes once in every round of them, shuffled, from the Seed; IIO would deal twice as many I’s as O’s), and Preview shows that many of the next ones in a box to the board’s right. Tiles painted on the board to begin with are blocks already there. It plays its Move Sound, Rotate Sound, Lock Sound, Clear Sound, Level Up Sound and Game Over Sound, and sends its Lines Message (Lines, with how many rows cleared), Score Message (Score, with the points), Level Message (Level Up, with how many levels it went up, so a Counter that starts at 1 shows the level) and Game Over Message (Game Over, so a panel with that Open Message shows it). A Counter counting the Output Score shows its score too. Scripts call Move(direction), Rotate() and Drop(), read Piece, PieceAt, Rotation, PieceCells(), LandingCells(), NextPieces, BlockAt(x, y) and IsClearing, and hear Locked, Cleared, LeveledUp and Ended. The tiles, Score, Lines, Level and Game Over are saved with the scene, and a rewind takes the piece falling and those to come back with them. In a network game the host runs the board, any player can move the piece, and everyone sees it fall.
The Falling Blocks template
Section titled “The Falling Blocks template”The Falling Blocks template is a menu showing the best score with Play and Quit, and a Game scene with a Falling Board of seven bevelled block tiles, the next three pieces beside it, and a HUD of counters: the score (Score), the rows (listening for Lines), the level (listening for Level Up, starting at 1) and the best score (Score with Save Best As best, which the menu’s counter shows). A Game Over panel opens on Game Over with the score, the best, Again and Menu, and the pause menu is there too, with no scripts.