# ladrilho
The game's own parts for **Ladrilho: Block Puzzle**, a phone-first block-placement
puzzle in English and Brazilian Portuguese: drag pieces onto an 8x8 board of painted
tiles, fill rows and columns to clear them.
## The game shell
- **Title:** the Ladrilho wordmark (each letter on a painted tile), "N playing now",
your level and XP, Play, Progress and Settings.
- **Modes:** Endless (best score kept), Daily Board (the same pieces for everyone each
UTC day, a world leaderboard per day), Adventure (60 levels in five chapters on a
path map, three stars each, the next level opens when one is cleared) and Duel
(3 minutes, a friend by room code or the computer).
- **Results:** score, best / new best, today's rank, stars, XP gained, level up and
tile looks unlocked, then Play again / Next / Map / Modes / Home.
- **Progress:** saved per player account by saveKit and back after a reload: XP and
level (40 levels), twelve tile looks unlocked by level, best scores, stars.
- **Settings:** music and effects volume (menusKit), graphics quality (Graphics
Presets), language (Automatic / English / Português (Brasil), switched live, even
mid-round) and the tile look.
- Portrait first; landscape and desktop mouse layouts too.
## Modules
`ladrilho.app` (routing, the mode API), `ladrilho.App` (the component), `ladrilho.screens`,
`ladrilho.art`, `ladrilho.modes`, `ladrilho.profile`, `ladrilho.daily`, `ladrilho.duel`,
`ladrilho.board` (the seam to blockPuzzleKit), `ladrilho.lang`.
## A mode, and how it plugs in a blockPuzzleKit session
```lua
local Modes = require("ladrilho.modes")
Modes.register({
id = "endless", order = 1, icon = "infinity", route = "play",
title = "ladrilho.modes.endless", blurb = "ladrilho.modes.endless_desc",
session = function(ctx) return { board = "classic8", pieces = "classic", dealer = "merciful", look = ctx.look, seed = ctx.seed } end,
finish = function(ctx, result) ... return { title = ..., score = ..., buttons = { "again", "modes", "home" } } end,
})
-- the App: App.startMode("endless") -> mode.session(ctx) -> Board.mount(cfg, region, App.boardEvent)
-- the board: App.boardEvent{ type = "score", score, lines } / { type = "gameOver" } / { type = "goalDone", stars }
-- the end: App.finishRound(result) -> mode.finish(ctx, result) -> results screen
```
## Installed kits it runs on
- **blockPuzzleKit**: the board, pieces, dealers, scoring, level goals, drag-and-place tray and computer player.
- **menusKit**: pause and settings screens (it brings **controlsKit** with it for input).
- **saveKit**: the saved profile.
- **scoreKit**: best scores and the Daily world boards, one per day (it brings **MatchFlow** with it).
- **Graphics Presets**: the graphics quality setting.
- **Table Codes (roomsKit)**: Duel rooms, the code keypad and the computer seat.
- **announcerKit**: the clear and combo callouts.
- **soundstageCore**: music and sound effects.
- **playingNow**: the "N playing now" chip.
- **levelPathMap**: the Adventure's chapter map, given Ladrilho's palette, fonts, widgets, goal glyphs and words in `Screens.adventureSpec`.
## Words
`locales/en/ladrilho.json` and `locales/pt-BR/ladrilho.json`, with plural forms and
the language's number grouping. The Brazilian Portuguese has been reviewed
(`locales/pt-BR/ladrilho.review.json`, every line `ai_reviewed`, the review state the
catalog check takes for a translation checked by someone other than its writer).
# ladrilho.App
The component that runs Ladrilho on each machine: in play it starts the shell
(`ladrilho.app`: saved profile, language, graphics, daily board, duel rooms) and
passes every tap, key and frame to it. Place one on an entity in the startup scene.
`preview = true` draws the title screen in edit mode.
# ladrilho.app
The App's logic as a module: routing (title, modes, daily, adventure, duel, play,
results, profile; settings and pause on menusKit), the mode API
(`App.startMode(id, opts)`, `App.boardEvent(ev)`, `App.finishRound(result)`,
`App.go(route)`, `App.state()`), and the setup of every kit it runs on. Driven by
`ladrilho.App`; tests and tools call it directly.
# ladrilho.art
Ladrilho's own look: the painted-tile palette (`Art.C`), the four-petal tile motif
(`Art.tileSvg`), the tiled background (`Art.background`), the wordmark set letter by
letter on painted tiles (`Art.wordmark`), and the widget helpers every screen uses
(`button`, `iconButton`, `panel`, `label`, `ICONS`). Called by `ladrilho.screens`.
# ladrilho.board
Where a blockPuzzleKit session meets the App: `Board.mount(cfg, region, onEvent)` starts
the kit's session with a mode's config and mounts its board and tray in the play
region the play screen leaves for it; the kit's events come back through `onEvent`
(`score`, `gameOver`, `goalDone`). Until blockPuzzleKit is installed `Board.available()`
is false and the play screen shows the marked placeholder instead.
# ladrilho.daily
The Daily Board: today's UTC date, its seed, and the world leaderboard for that day.
The board is scoreKit's weekly board with one board id per day (`daily-YYYY-MM-DD`):
a UTC day always lies inside one ISO week, so the week's rows of that board are exactly
the day's rows. Each player writes only their own row (scoreKit.weekly). A play session
an agent drives posts nothing (scoreKit's real-session rule), so tests never reach the
public board.
# ladrilho.duel
Ladrilho's 3-minute Duel, on Table Codes (roomsKit) rooms and blockPuzzleKit's replayable move logs.
- **Lobby.** Play a friend: roomsKit's own home screen (digit codes tapped on its keypad, a Back
button to Ladrilho). The host starts the round from the room; an empty seat is filled by a
computer player (roomsKit bot fill). Play the computer: Easy, Normal or Hard starts a private
two-seat room with the computer in seat 2 at once.
- **Same pieces.** The host deals one seed; both boards run `Duel.rules(seed)` (classic 8x8,
classic pieces, the `daily` dealer, which never reads the board, so the pieces depend on the seed
alone).
- **Clock.** `startAt` / `endAt` are `multiplayer.sessionTime()` seconds in the room state, so every
screen counts the same 3-2-1 and the same 3:00. Before `startAt` an overlay takes the taps.
- **Moves.** Each machine plays its own board locally and sends its moves `{ slot, q, r, at }` to the
host (re-sent until the host confirms them). The host checks each move by replaying it, drops one
made after 0:00, and publishes every seat's move log in the room state.
- **Opponent.** Each machine applies the opponent's log to a second, non-interactive kit board (the
mini-board: above your board in portrait, in a left column in landscape) with `game:apply(move)`;
its score is the opponent's score.
- **Computer players.** The host plays every `bot` seat (from the start, or one that took over for
someone who left) with the kit's AI (`BP.Ai.new(level)` and a time-sliced `ai:think` job) at a
person's pace (Easy 2.6-4.6 s a move, Normal 1.8-3.4 s, Hard 1.3-2.6 s). A new host after host
migration carries on from the published logs.
- **The end.** At 0:00 plus a 1.2 s grace (or as soon as both boards are out of room) the host replays
both logs and publishes `result = { scores, lines, winner }`: more points wins, tied points go to
more lines cleared, else a draw. Every screen shows that one result. A member whose host vanished
at the last second decides from the logs itself after 6 s (same replay, same answer).
- **Rematch.** In a friend room, the room's waiting screen comes back (the host starts again); against
the computer, a new match at the same level.
API: see the header of `init.luau`. Every word is in `locales/<lang>/ladrilho.json` under `duel.*`.
# ladrilhoAdventure
Checks Ladrilho's 60 Adventure levels: every chapter file loads, each level is a well-formed blockPuzzleKit level (8x8 ascii map, known goals, a move limit, a start the kit accepts), every goal line reads as words in English and Brazilian Portuguese, and blockPuzzleKit's `hard` computer player beats every level inside its move limit — on the level's own seed and on at least 4 of 6 seeds. The sweep prints the moves each win took (`[adventure] a07 limit 26: hard AI won 6/6, moves [...]`), the numbers the move limits are tuned from. It does not drive the map or the play screen; those are checked by playing.
# ladrilho.lang
The language choice: Automatic, English or Português (Brasil). It provides menusKit's
Language row, and a choice goes to `i18n.choose`, which every catalog (Ladrilho's and
every kit's) follows at once, mid-round, with no restart.
# ladrilho.modes
The four ways to play (Endless, Daily Board, Adventure, Duel), each a small
definition the App runs: its card on the mode screen, the blockPuzzleKit session
config for one round (`session(ctx)`), an optional time limit, and what a finished
round saves, posts and shows (`finish(ctx, result)`). `Modes.register(def)` adds or
replaces a mode, so the duel's sync or the adventure's level data change their mode
without touching the App. The full shape is at the top of `init.luau`.
# ladrilho.profile
Each player's saved Ladrilho progress on saveKit (profile mode, namespace `ladrilho`):
XP and level (40 levels, 100, 140, 180 ... XP each), the twelve tile looks unlocked by
level, best Endless score, today's Daily Board best, adventure stars per level, games
played and the tile look in use. `recordGame(mode, result)` gives the XP for a round and
answers what changed (new best, level up, looks unlocked). Called by `ladrilho.App`
and the mode definitions.
# ladrilho.screens
Every Ladrilho screen as a pure function of what it shows and the canvas size:
title (wordmark, "N playing now", level and XP, Play), modes (four cards), daily
(today's best and the day's world leaderboard), adventure (a chapter path of 12
level tiles with stars and locks, five chapters), duel (friend or computer), play
(HUD and the board region the kit's view mounts in; a marked placeholder until the
kit is installed), results and profile (stats and tile looks). Portrait stacks,
landscape sets things side by side. Called by `ladrilho.app`.
# ladrilho.soundBake
The recipes behind every clip in `ladrilho.package/sounds/` (plucked strings, bells,
filtered noise; all arithmetic on samples, so every sound is original). Authoring only:
`require("ladrilho.soundBake").bakeAll()` writes the clips again.
# ladrilho.sounds
Ladrilho's sound on soundstageCore: menu taps, a piece set down, clears whose bells
climb with the combo, game over, new best, level up, and a gentle 16-second bossa
loop as music. Every clip is synthesised (`ladrilho.soundBake`) and small; they play on
the ui / sfx / music mixer channels, so menusKit's volume settings apply.
# clear1
A line clear in Ladrilho, combo level 1: a quick rising bell arpeggio (four notes up a major scale from C5) with a soft shimmer, under a second. Played by `ladrilho.sounds` (Sounds.clear) for a single clear.
Made by `ladrilho.soundBake` (recipe `clear1`); rebake it there to change it.
# clear2
A line clear in Ladrilho, combo level 2: the rising bell arpeggio one step higher and with five notes, for a second clear in a row or a double. Played by `ladrilho.sounds` (Sounds.clear).
Made by `ladrilho.soundBake` (recipe `clear2`); rebake it there to change it.
# clear3
A line clear in Ladrilho, combo level 3: a six-note rising bell arpeggio, a step above level 2. Played by `ladrilho.sounds` (Sounds.clear) for a three-line or third-in-a-row clear.
Made by `ladrilho.soundBake` (recipe `clear3`); rebake it there to change it.
# clear4
A line clear in Ladrilho, combo level 4: a seven-note rising bell arpeggio, brighter and higher. Played by `ladrilho.sounds` (Sounds.clear) for big combos.
Made by `ladrilho.soundBake` (recipe `clear4`); rebake it there to change it.
# clear5
A line clear in Ladrilho, combo level 5 and above: the highest, seven-note rising bell arpeggio. Played by `ladrilho.sounds` (Sounds.clear) for the biggest combos.
Made by `ladrilho.soundBake` (recipe `clear5`); rebake it there to change it.
# gameover
A gentle end-of-round phrase in Ladrilho: four plucked nylon-string notes falling G-E-C-G, about 1.4 s, soft rather than sad. Played by `ladrilho.sounds` (Sounds.gameOver) when no piece fits.
Made by `ladrilho.soundBake` (recipe `gameover`); rebake it there to change it.
# levelup
A bright five-note rising bell run for reaching a new level in Ladrilho, about 1.2 s. Played by `ladrilho.sounds` (Sounds.levelUp) after the results screen shows the level up.
Made by `ladrilho.soundBake` (recipe `levelup`); rebake it there to change it.
# music_loop
Ladrilho's music: a gentle 16-second bossa nova loop at 120 bpm, synthesised: plucked nylon-ish chords (Cmaj9, Am7, Dm9, G13, Em7) on the bossa comping rhythm, a soft thumb bass, a shaker and a rim click, with a short bell melody in the second half. Loops seamlessly on the music channel through soundstageCore (`ladrilho.sounds`).
Made by `ladrilho.soundBake` (recipe `music_loop`); rebake it there to change it.
# newbest
A small celebration for a new best score in Ladrilho: a rising bell arpeggio C-E-G-C ending on a plucked C major chord and a shimmer, about 1.6 s. Played by `ladrilho.sounds` (Sounds.newBest) on the results screen.
Made by `ladrilho.soundBake` (recipe `newbest`); rebake it there to change it.
# place
The sound of a painted ceramic tile set down: a short woody clack of filtered noise, a faint high ring and a low thump, about 0.16 s. Played by `ladrilho.sounds` (Sounds.place) when a piece lands on the board.
Made by `ladrilho.soundBake` (recipe `place`); rebake it there to change it.
# ui_back
A soft two-note falling bell (880 Hz then 660 Hz) for going back a screen in Ladrilho, about 0.12 s. Played by `ladrilho.sounds` (Sounds.back) on the ui channel.
Made by `ladrilho.soundBake` (recipe `ui_back`); rebake it there to change it.
# ui_tap
A short bright bell tick for a menu tap in Ladrilho: a sine bell at 1320 Hz with a tiny noise click, under 0.1 s. Played by `ladrilho.sounds` (Sounds.tap) on the ui channel for every button press.
Made by `ladrilho.soundBake` (recipe `ui_tap`); rebake it there to change it.