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 anai.BoolGridsmoothed withai.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.VirtualPadof touch sticks and 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 |
| Pause, play again | P or Enter | Start | Play again |
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
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/gameproject sync
go run github.com/nsgo-dev/game/cmd/gameproject 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.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, the touch pad 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; the touch layout islayoutTouchPadincontrols.go. - Looks: materials and lights are at the top of
render.go; replaceunitCubewith meshes fromgltffor real models.
Click to show internal directories.
Click to hide internal directories.