9개 챕터
Tutorial: Star Catcher
Build a whole game, Star Catcher, from an empty project to a release you can ship, in nine chapters. Each chapter adds one idea to the game, and each chapter's finished code is in the repository, where CI builds it for every target and runs its tests.
In Star Catcher, stars and rocks fall down five lanes. The player moves a basket from lane to lane to catch the stars and dodge the rocks. A missed star or a caught rock costs one of three lives, and the game speeds up as the score grows.
- An empty projectA module, nsgo.yaml, a Canvas and a first test
- The game loopA fixed-step loop, a virtual resolution and a world that tests can step
- InputTouch, mouse and keyboard moving the basket through named actions
- SpritesA sprite atlas painted in code, sprites, a batch and an animation
- RulesRandom spawns, collisions, score, lives and the end of a game
- ScreensA title screen, a pause menu and a game-over screen in native views
- SoundEffects synthesized in Go, a mixer and a mute switch that is remembered
- SavingThe best score kept across launches in a versioned save slot
- ShippingAn icon, store metadata, a pause when the app loses the focus and release builds
How the game is built
world.goholds the game's state and rules, and only its step method changes them. It knows nothing about windows, so tests step it directly, and the same seed and moves always play the same game.
game.goties the world to the screen. A game.Loop calls step sixty times a second with the player's input, and a Canvas draws the world in between.
screens.gofrom chapter 6, builds the native NSGo views over the canvas: the score, the menus and their buttons.
*_test.gotests both: the rules through world, and the whole app through nsgotest, which runs it without a window and lets a test press buttons, type keys, touch the screen and advance time.
저장소에서 각 챕터 실행
$ cd examples/tutorial $ go tool nsgo dev ./ch05-rules $ go tool nsgo test ./...