README
¶
Gem Garden
A match-3 puzzle game built with NSGo and github.com/nsgo-dev/game, made from the match3 template.
Swap two neighboring gems to line up three or more of a color. Four in a line make a line gem, which clears its row or column; an L or a T makes a bomb gem, which clears the cells around it; five in a line make a color gem, which clears every gem of the color it is swapped with, and two special gems swapped together combine. Each level has a move budget and one or more goals: reach a score, collect gems of a color, clear every jelly, or break crates and ice. Meet every goal before the moves run out to win; moves left over add to the score, and the score earns one to three stars.
Twenty levels sit on a level map in two packs, Meadow and Grotto; winning a level unlocks the next, and winning every Meadow level opens the Grotto. Starting a level takes one of five lives, winning gives it back, and a spent life comes back every 20 minutes, also while the game is closed. Stars earned for the first time pay coins, which buy a booster before a level (a line gem, a bomb gem or three more moves) or five more moves when a level runs out. There are no real-money purchases.
It demonstrates:
- Levels in the versioned
match3level format, one file per level inlevels/*.level.yaml, and the packs, star thresholds and unlock rules in aprogressionmanifest,levels/packs.yaml; both are read strictly and kept in the canonical form their encoders write. - The rules from
pkg/match3: matches of every shape, special gems and their combinations, jelly, crates and ice, cascades, hints and reshuffles of a board with no moves, all deterministic for a seed. - Lives on an
idle.Meterthat refills on the wall clock while the app is closed, and best results and unlocks fromprogression.Progress, saved withsave.Store. - The coins, boosters and the out-of-moves offer in
economy.yaml. - A fixed-step
game.Loopthat readsinput.Actions, bound from the input map ingame.yaml, and animates swaps, clears and falls withtween. - Native NSGo controls for the map, the counters and the dialogs, over a board drawn on a
core.Canvaswith no image files. - Headless tests that play level 1 to a win and to a loss through
nsgotestby touch, the mouse, the keyboard and a game controller, and a bot that wins every level within its moves.
Controls
| Keyboard | Game controller | Touch and mouse | |
|---|---|---|---|
| Move the cursor | Arrow keys or WASD | D-pad or left stick | |
| Select a gem | Enter or Space | South | Tap or click it |
| Swap the selected gem | Arrow keys or WASD | D-pad or left stick | Tap or click a neighbor, or swipe from the gem |
| Show a hint | H | North | Hint |
| Pause | Escape | East | Pause |
| Turn the map's pack | Q and E | Shoulders | ◀ and ▶ |
| Choose in a dialog | Arrows, then Enter | D-pad, then South | The button |
The keyboard and game controller bindings are the input map in game.yaml; edit them there. The swipes are bound in newGemGame.
The game's settings live in game.yaml, its project file. Edit the name and identifier there before shipping it, then write them into nsgo.yaml and check the project:
go run github.com/nsgo-dev/game/cmd/game project sync
go run github.com/nsgo-dev/game/cmd/game project check
Running and testing
Run with hot reload on your desktop (macOS, Windows or Linux):
go tool nsgo dev
Run on other targets:
go tool nsgo dev -target web
go tool nsgo dev -target ios_simulator
go tool nsgo dev -target android
Debug the game's Go code with Delve (dlv on PATH):
go tool nsgo dev -target native -debug
Attach from VS Code with the Attach to game configuration in .vscode/launch.json, replacing 40000 with the port in Delve's API server listening at line, or from GoLand with a Go Remote configuration at the same host and port.
Run the tests, which play level 1 and have a bot win every level:
go tool nsgo test ./...
Vet and check across platforms:
go tool nsgo check -target macos,windows,linux,android,web
go tool nsgo check -target ios,ios_simulator # on macOS with Xcode
Build release artifacts into dist/ (go tool game release sets GOFLAGS=-tags=release automatically to strip debug code):
GOFLAGS=-tags=release go tool nsgo build -target macos_arm64,windows_x64,linux_x64,web
GOFLAGS=-tags=release go tool nsgo build -target ios,android_arm64
Adding a level
Write the level in levels/<id>.level.yaml in the match-3 level format: its size, colors, seed, moves, an optional mask of holes, its jelly, crates and ice, and its goals. The game draws up to six colors and plays move-budget levels with score, collect, clear-jelly and clear-blocker goals.
Then list it in levels/packs.yaml, the progression manifest, under its pack: its id, which the save keys its stars by, so keep it when renaming or moving the level; its name in each language; its file; stars, the final scores (score plus 250 for each move left) that earn two and three stars, as any win earns one; and unlock, usually after the level before it.
TestBotWinsEveryLevel fails when a level cannot be won within its moves in any of its seeds; TestLevelFilesAreCanonical prints a file's canonical form when it is not in it.
Lives, coins and boosters
economy.yaml sets how many lives a player holds and how long one takes to come back, the coins a player starts with and earns per new star, the out-of-moves offer and the boosters sold before a level, with their prices. Lives are an idle.Meter: the save keeps its value and refill anchor, so lives refill for the time the game was closed, and setting the device clock back grants nothing.
Layout
game.yaml: the project file, with the game's name, id and version, its window, the input map and the export presets.levels/packs.yaml,levels/*.level.yaml: the packs and levels.data.goloads them andeconomy.yaml.play.go: one attempt at a level: its board, the boosters applied to it, the continue offer and the stars it earns.save.go: the saved progress, lives and coins.game.go: the game: the loop, the input, the map, starting and ending levels, and the economy.anim.go: the animation of a swap and its cascades.draw.go: how the board is laid out and drawn on the Canvas.ui.go: the native views: the map, the counters and buttons, and the dialogs.project.go,main.go: the parsedgame.yamland the entry point.*_test.go: the tests.game_test.goplays the game throughnsgotest;bot_test.gowins every level with a bot;data_test.gochecks the data files;play_test.gotests the rules of an attempt.nsgo.yaml: NSGo app metadata and dev settings; its name, id, version and build output and targets followgame.yaml.
Git setup
Each clone enables the object-by-object scene merge driver once (.gitattributes names it, while Git keeps driver config local to .git/config):
go tool game merge -setup