README
¶
NSGo Game Platformer Template
A small 2D side-scrolling platformer built with NSGo and github.com/nsgo-dev/game. A lantern bearer runs and jumps through three rooms of Lantern Hills, collects sparks, lights a lamp that becomes the respawn point and reaches the beacon to win. Spikes and pits cost a life; losing the last one loses the run.
It shows:
- A
platformer.Controllerover aphysics.CharacterBody: run, variable-height jumps, coyote time, jump buffering, one-way ledges, wall slides and wall jumps, tuned bydata/player.yaml. - A level drawn as text in
data/level.yaml, built into aphysics.Gridto collide with, atilemap.Tilemapto draw andphysics.Triggersensors for spikes, sparks, the lamp and the beacon. - Rooms with their own camera bounds from
data/rooms.yaml: arooms.Directorslides atilemap.Camerabetween them and the player waits while it does. - One input map in
game.yamlfor the keyboard, game controllers, touch and the mouse, bound into aninput.ActionswithProject.BindInput; on-screen controls are drawn where the touch regions are. - A 320 by 180 virtual screen scaled by whole multiples, a native HUD and end-of-run panel over the canvas, and art drawn by code.
- Tests that play the level through with the keyboard, a controller and touch to a win, run into the spikes to a loss, and check the data files, the rules and the controller's timing.
Controls
| Keyboard | Controller | Touch | |
|---|---|---|---|
| Run | Left and right arrows, A and D | Left stick, d-pad | The left and right arrows at the bottom left |
| Jump (hold to jump higher) | Space, up arrow, W | South button (A on Xbox, Cross on PlayStation) | The arrow at the bottom right |
| Play again after the run ends | R, Enter | Start | The Play again button |
The mouse plays like touch: hold the left button over an on-screen control. The controls are drawn on phones and tablets, and anywhere once the game view has been touched or clicked.
Running and testing
go tool nsgo dev # the desktop, with hot reload
go tool nsgo dev -target web # the browser
go tool nsgo dev -target ios_simulator
go tool nsgo dev -target android
go tool nsgo test ./... # headless tests
go tool game playtest # automated bot playtest and report
go tool nsgo check -target macos,windows,linux,android,web
GOFLAGS=-tags=release go tool nsgo build -target macos_arm64,windows_x64,linux_x64,web
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
Layout
game.yaml: the project file, with the window, the virtual screen, the input map and the export presets.data/level.yaml: the level, one character per tile (the legend is onLevelinlevel.go), its tile size and the lives a run starts with.data/rooms.yaml: the rooms, in world points, and the camera transition into them.data/player.yaml: the controller's tuning.data.go: embeds and parses the data files.level.go: the level format: parsing, validation and canonical encoding.world.go: a run of the level: collision grid, player, sensors, lives, checkpoint, goal and rooms, stepped once per fixed step and independent of devices and drawing.game.go: the root component, the fixed-step loop, input sampling, the HUD and the end-of-run panel.draw.goandart.go: drawing the run, and the tileset and player frames drawn by code.main.goandproject.go: the entry point and the embeddedgame.yaml.playtest.yamlandplaytest_test.go: theplatformer-runnerplaytest configuration andTestPlaytestadapter driven bygo tool game playtest.*_test.go: playthroughs, rules, controller timing and the data files.
Where to change it
- Make a level: edit the tiles in
data/level.yaml, keeping every row the same width with onePand oneG, and ground (#) or a ledge (=) under everyPandC, and keepdata/rooms.yamlcovering every column.TestDataFilesAreCanonicalandTestRoomsCoverTheLevelsay what is wrong. If you change the route, change the playthrough'sobstacleAheadingame_test.gotoo, or give it a list of jumps. - Change how the player feels:
data/player.yaml. Raisecoyote_timeandjump_bufferfor a more forgiving jump, setwall_jump_speed_y: 0to turn wall jumps off. - Add a tile kind: a glyph in
level.go, a case innewWorldfor what it does and one innewTilemapfor how it looks. - Add enemies or moving platforms: give each a
physics.Body, move it inworld.step, pass moving platforms toController.Stepand add a sensor that setsw.hurt. - Rebind a control: the
inputsection ofgame.yaml; the touch regions are in virtual screen points. - Replace the art: load an atlas with
sprite.LoadAtlasinnewPlayerAtlasand a tileset image innewTilemap, or load the whole level from a Tiled map withtilemap.LoadTiled. - Add sound with
sound.Mixer, configured from anaudiosection ingame.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