このページはまだ日本語訳がないため、英語の原文を表示しています。
ガイドThe coop2d template
coop2d holds the authoritative rules of a 2D co-op room for one to four players: room codes and invite links, a fixed tick, leaving and rejoining within a grace period, a teammate reviving a downed player, and a solo respawn when no teammate is standing. Create a project from it with:
go run github.com/nsgo-dev/game/cmd/game@latest new -template coop2d mygame
or with NSGo's own command, nsgo init -template github.com/nsgo-dev/game/template/coop2d -module example.com/mygame mygame. Templates lists the others.
What it holds
- Rooms by code.
Server.CreateRoomopens a room under a code, whichRoomCodederives as six upper-case characters, andServer.Joinadds a player to it, refusing an unknown code, a full room and a player already in it.InviteLinkwrites the code into a link'sroomquery parameter, keeping the link's other parameters, andRoomFromInvitereads it back. - Leaving and rejoining.
Server.Leavedisconnects a player, who keeps their place and state, a downed player staying downed, forrejoinGrace.Server.Rejoinreconnects them within it. When it runs out,Server.Tickremoves the player and returns their ID, and closes a room no one is left in. - Revive and respawn. A player the game's rules mark with
Server.Downis revived afterreviveTicksconsecutive ticks while a teammate is connected and standing, and gets up alone afterrespawnTicksticks while no one is. Who is standing is decided at the start of each tick, so the result does not depend on the order of the players. - Tuning in YAML.
coop.yamlholds the version, the tick rate, the room size, the grace period and the two timers.ParseCoopConfigrefuses an unknown field, a second document and an out-of-range value, andEncodeCoopConfigwrites the file back byte for byte.
Server.Room returns a copy of a room's state with its players sorted by ID, and Server is safe for concurrent use.
Validation
The template's headless tests cover room creation and joining, invite links, leave and rejoin within the grace period, expiry, teammate revival, solo respawn, YAML validation and concurrent snapshots during the authoritative tick. CI runs those tests and builds the generated project for Linux desktop and WebAssembly.
What it does not hold yet
The template has no network transport, lobby screen or play screen: the client is one screen showing the rules from coop.yaml, and the tests drive Server in process. A game connects Server to its clients over netplay or its own transport and runs it on its server; players are identified by the ID the game gives them, not by a resume token.