README
¶
Action Adventure
A third-person 3D action adventure built with NSGo and github.com/nsgo-dev/game. A knight crosses a walled courtyard, fights the guards, jumps onto a ledge for the key, and the key opens the gate to the shrine. Reaching the shrine wins; losing all health loses.
It shows:
- An orbit camera (
scene3d.OrbitController) that follows the hero, turns with the player and moves in front of walls between it and the hero, found by sweeping aphysics3dsphere along the arm so the lens keeps clear of corners. - A capsule character controller per actor in a
physics3d.Worldof static boxes, with walking, jumping onto a ledge and a door that leaves the world when it opens. - Run, jump, attack, flinch and fall animations on a rig of boxes, played by an
anim3d.StateMachinewhose locomotion state blends idle into run by speed (anim3d.BlendSpace1D), with conditional transitions and ahitclip event that lands each blow. - Enemies that chase the hero inside their sight and leash, wind up a slow swing the hero can interrupt, and walk home when the hero gets away.
- A level that is a scene file: blocks, the spawn, enemies, the key, the door, the goal and the lamps are objects with components, and a connection in the scene, not Go code, makes picking up the key unlock the door.
- render3d's lit PBR pipeline drawing every box from one cube mesh, lit by a moon, an ambient fill and the scene's lamps.
- A pause that is always reachable: Escape or P, a controller's Start or the HUD's Pause button open a menu over the frozen level with Resume and Restart. Losing focus, the app going to the background or the active controller disconnecting pauses the same way, and resuming ignores the controls for half a second so a movement key still held from before the pause does not lurch the hero.
- Keyboard and mouse, game controller and touch, all through one
input.Actionsbound fromgame.yaml, with on-screen sticks and buttons (input.TouchControls) placed inside the safe area fromcontrols.touch.yaml(visible from the first frame on phones and on desktop once touched). - Headless tests that play the whole run to a win with a game controller and to a loss with the keyboard, drive the touch controls and draw the level on a software GPU.
Controls
| Keyboard and mouse | Game controller | Touch | |
|---|---|---|---|
| Move | W A S D or the arrow keys | Left stick or D-pad | Drag on the left half |
| Turn the camera | Q and E, or drag with the mouse | Right stick or the shoulder buttons | Drag on the right half |
| Jump | Space | A (south) | Jump button |
| Attack | J or Enter | X (west) or the right trigger | Attack button |
| Pause and resume | Escape or P | Start | The Pause button in the HUD |
| Play again after the run ends | R | Start | Play again button |
Running and testing
go tool nsgo dev # the desktop, with hot reload
go tool nsgo dev -target web # the browser
go tool nsgo test ./... # the headless tests
go tool nsgo check -target macos,windows,linux,android,web
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.
Layout
game.yaml— the project file: name, id, window, the input map (actions, axes and game controller sticks, including the pause and restart actions), the scene and data files to autoload, and export presets.controls.touch.yaml— the on-screen touch layout (input.TouchControls): floating move and camera sticks, and Attack and Jump buttons anchored inside the safe area.scenes/keep.scene.yaml— the level, a scene file the scene editor opens (go run github.com/nsgo-dev/game/cmd/game editor .). Each object'sx,y(up) andposZplace it in meters, its scale sizes a box, and its components say what it is:block,spawn,enemy,key,door,goalorlamp. Objects sit at the top of their layer, not inside one another, and only the spawn is rotated, byrotY. Theconnectionsat the end wire the key'scollectedevent to the door'sunlockhandler.data/actors.yaml— the hero's and the enemies' tuning (health, speed, jump, reach, damage, swing speed, knockback and colors), the rig of boxes both share, and the animation clips in degrees and seconds.actors.godefines and checks its format.level.go— the level's component types and how a scene becomes boxes, spawns and lamps.game.go— the simulation: the physics world, hero and enemy rules, the key, the door and winning and losing. It knows nothing of devices or the GPU.rig.go— turns the rig and clips intoanim3dclips and a state machine per actor, and poses the boxes.render.go— the camera, the lights and the GPU renderer.view.go— the root component: the fixed-stepgame.Loop, input, the HUD with the Pause button, the pause menu and the touch controls.project.go,main.go— embed the project and its files and start the app.*_test.go— the playthroughs, input, rendering and file-format tests.
Where to change it
- Move walls, add enemies or lamps, or build a new level in
scenes/keep.scene.yaml; the tests check that it still loads, and the bot's route ingame_test.gosays how a run is won. - Tune the fight in
data/actors.yaml: slower enemy swings (attackSpeed), more health or a longerreachchange the difficulty without touching code. - Add an animation by adding a clip to
data/actors.yamland a state tonewAnimatorinrig.go. - Add a component type in
levelComponents(level.go), such as a moving platform, and read it inbuildLevel. - Replace the boxes with glTF models: install the
cc0-adventurerslibrary pack (go run github.com/nsgo-dev/game/cmd/game library install cc0-adventurers) for two CC0 rigged characters (knight.gltf,mage.gltf) sharing twelve clips (Attack,AttackHeavy,Block,Death,Defeat,Dodge,Hit,Idle,Jump,Run,Victory,Walk) and anadventurer.animgraph.yamllocomotion graph; verify withgame checkandgame credits, addpacksto the//go:embeddirective inproject.go, load withgltf.LoadFSandanim3d.LoadGraph, and draw skinned meshes withrender3d.UploadMeshinrenderer.draw.
After editing game.yaml, write the name and id it shares with 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
After moving or adding files, go run github.com/nsgo-dev/game/cmd/game index keeps game.index.yaml, the project's index of stable file IDs, up to date.
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