README
¶
Relay Yard: an NSGo first-person shooter template
A first-person shooter arena built with NSGo and github.com/nsgo-dev/game: hold the relay yard against three waves of drones and wardens with a hitscan rifle and a projectile launcher.
It shows:
- A capsule
physics3d.CharacterControllerfor the player and for every enemy, walls and crates as static boxes, and hitscan shots, rounds and enemy sight as layered raycasts through onephysics3d.World. - Enemies driven by an
aibehavior tree (attack the player in sight, else hunt the last place it was seen or heard, else patrol), walking A* paths over apathfind.BoolGridsmoothed withpathfind.SmoothGridPath. - A
render3dlit PBR pipeline drawing the level as three baked meshes (floor, walls and crates) and every moving thing as one unit cube, under arender3d.LightRig, in agpu.View, with a native HUD and an overlaycore.Canvasabove it. - One
input.Actionsfed by the keyboard, mouselook under pointer lock, game controllers and aninput.TouchControlslayer built fromcontrols.touch.yaml(safe-area anchored sticks and fire, jump, reload, swap and weapon-slot buttons). - Headless
nsgotestplaythroughs that win with the keyboard and mouse and with a game controller, and lose by standing still.
Play
| Keyboard and mouse | Game controller | Touch | |
|---|---|---|---|
| Move | W A S D | Left stick | Left stick (drag in the lower left) |
| Look | Mouse (click the arena to lock the pointer), or the arrow keys | Right stick | Right stick (drag in the lower middle) |
| Fire | Left button or F | Right trigger | Fire |
| Jump | Space | South (A) | Jump |
| Reload | R | West (X) | Reload |
| Next weapon | Q, or 1 and 2 | North (Y) | Swap, W1 and W2 |
| Pause, play again | P or Enter | Start | Play again |
When the active controller disconnects and no other controller is connected, the match pauses and releases the pointer. Reconnect the original controller, press a button on another controller, or press a key to clear the alert. A manual pause stays active. Edit the alert's strings in strings/.
Clear all three waves to win; reaching 0 health loses. Health and ammo pickups beside the start return 20 seconds after they are taken.
Run and test
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 and playthroughs
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.
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: name, id, version, window, export presets and the input map that binds every key and controller button to an action.controls.touch.yaml: the on-screen touch layout (input.TouchControls), placed inside the safe area.arena.yaml: the level and its tuning: the layout drawn in characters, the player, the weapons, the enemy kinds, the pickups and the waves.arena.godocuments every field and validates the file.match.go: one match from the countdown to a win or a loss: the physics world, the player's movement and weapons, rounds in flight, pickups and waves. It readscontrols, never a device, so tests drive it directly.enemy.go: an enemy's body, its behavior tree and its path following.controls.go: the actions and how a step's input becomescontrols.render.go: therender3drenderer.game.go: the root component, the 60 Hzgame.Loop, the HUD, the overlay and the end panel.project.go,main.go: the embedded project and arena files and the entry point.*_test.go: the arena file's round trip and validation, the match's rules, the bot that plays the playthroughs, the playthroughs on each device and a rendered frame.
Where to change it
- A new level: edit the
layoutrows inarena.yaml.#is a wall,ca crate you can shoot over,Pthe start,San enemy spawn,1to9the patrol route, and each pickup'ssymbolplaces that pickup. - Balance: weapon damage, fire rate and magazines, enemy health, speed, sight and bolts, and the waves are all in
arena.yaml. - A new weapon: add it to
weaponsashitscanorprojectile;1to9draw them by slot oncegame.yamlbindsweapon3and up andcontrols.goreads them. - A new enemy behavior: add a branch to the selector in
newEnemy(enemy.go), such as a flee when hurt, ahead of the patrol. - Controls: rebind actions in
game.yaml's input map; move or resize the touch controls incontrols.touch.yaml. - Looks: materials and lights are at the top of
render.go; replaceunitCubewith meshes fromgltffor real models.
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