GitHub시작하기

이 페이지는 아직 한국어로 번역되지 않아 영문 원문을 표시하고 있습니다.

가이드

The roguelike2d template

roguelike2d is a small turn-based roguelike: a delver descends the five floors of the Glimmerdeep, fights the monsters that live there, gathers weapons, armor, draughts, tonics and shards, and lifts the Heart Ember from the last floor, where the Vault Warden stands on it. Every floor is generated from the run's seed, and death is permanent: the run's save is deleted the moment the run ends, and a summary and the records of every run are kept. It is built on procgen, entities, loot, stats, ability, save, random, input and screen, and its art is drawn by code.

go run github.com/nsgo-dev/game/cmd/game@latest new -template roguelike2d mygame
cd mygame
go tool nsgo dev

nsgo init -template github.com/nsgo-dev/game/template/roguelike2d writes the same project, as Templates describes.

What it shows

  • Floors generated by procgen from streams forked off the run's seed: BSP rooms joined by corridors and cellular-automaton caves, with the exit on the floor cell farthest from the start, so the same seed builds the same floor on every platform.
  • Actors as entities: every monster and every item lying on a floor is an entity in the floor's entities world, made of Position, Foe, Guard and Loot components, and the monsters' part of each turn is two systems on an entities.Scheduler, notice and then hunt.
  • Turns: each action of the player is followed by every monster's. Monsters notice the player within their sense, hunt down a breadth-first distance map and strike when next to the player; walking into one attacks it. The player sees along lines of sight, and cells seen before stay drawn, dimmer.
  • Weighted loot from loot: each floor's item cells and each monster's drops are rolled from data/loot.yaml, with a soft pity ramp on draughts and a hard one on the best weapon, whose counters carry from floor to floor.
  • Stats from stats: health, attack and defense with an equipment slot each for a weapon and armor, which Sheet.Refresh swaps, timed tonic modifiers that Sheet.Step counts down once a turn, and levels that raise the bases.
  • Abilities from ability: a quaff that spends a draught and a cleave that strikes every neighbour, gated by conditions and cooldowns. The caster runs at one step a second, so every duration in data/abilities.yaml counts turns.
  • Permadeath with save: the run is saved as the player arrives on each floor and after every turn, with the floor's world of actors as an entities snapshot and the state of its random streams, so closing the app and opening it again resumes the run exactly where it stood. Quitting before a blow lands undoes nothing, and the slot is deleted when the run is won or lost. A records slot counts every run, and the end-of-run panel shows the summary and the records.
  • One input map in game.yaml for the keyboard, game controllers, touch and the mouse, with on-screen controls on phones and tablets, and anywhere once the game has been touched or clicked.
  • Tests that play the game through to a win with the keyboard, a controller and touch, and to a death, check that the run slot is gone and the records count it, resume a run from storage mid-floor and play it out the same as the run that was never closed, refuse run slots with numbers out of range, generate every floor of forty seeds, check the balance with two bots over those seeds, check the rules one by one and check that every data file is canonical.

Controls

Keyboard Controller Touch
Move, or attack what is in the way Arrows, WASD Left stick, d-pad The arrows at the bottom left
Wait a turn Space, . South button The dot between the arrows
Quaff a draught Q West button ! at the bottom right
Cleave everything next to you E North button C at the bottom right
Play again after the run ends R, Enter Start The Play again button

Holding a direction keeps walking, one step and then one every few frames. Holding the left mouse button over an on-screen control plays like touching it.

How it is organised

File What it holds
game.yaml The project file: the window, the 320 by 180 virtual screen, the input map and the export presets.
data/dungeon.yaml The player's progression, the floors, the monsters and the items, in the format below.
data/stats.yaml The player's stats and the effects weapons, armor and tonics apply, in the format of stats.
data/loot.yaml The drop tables floors and monsters roll, in the format of loot.
data/abilities.yaml The quaff and the cleave, in the format of ability.
dungeon.go, data.go The dungeon format, and loading the four files with a check of every name one uses from another.
floor.go Generating a floor: its cells, start, exit, monsters and items, the distance map and line of sight.
actors.go The components of the floor's monsters and items, and the notice and hunt systems that play the monsters' turn.
run.go One run's rules, one turn at a time, without knowing about devices or drawing.
records.go The run and records save slots, the checks a resumed run slot must pass, and the run summary.
game.go, draw.go The root component, the fixed-step loop, input, the HUD, the end-of-run panel and drawing.
*_test.go The playthroughs, the bots, the rules, floor generation and the data files.

The dungeon file lists the floors in the order a run descends them; every floor but the last has stairs down, and the last holds the relic:

version: 1
name: The Glimmerdeep
player:
  weapon: rusty-pick
  draughts: 2
  draughtHeal: 15
  levelXP: 10
  levelHealth: 5
  levelAttack: 1
  regenTurns: 5
floors:
  - name: The Mossy Galleries
    generator: bsp
    width: 40
    height: 30
    monsters: 6
    items: 5
    loot: floor-shallow
monsters:
  - id: moss-rat
    name: Moss Rat
    glyph: r
    color: '#84cc16'
    health: 5
    attack: 3
    defense: 0
    xp: 2
    sense: 5
    drops: rat
    from: 1
    to: 2
    weight: 3
items:
  - id: rusty-pick
    name: rusty pick
    kind: weapon
    effect: rusty-pick
    rank: 1
    color: '#a8a29e'
Field Meaning
player The starting weapon and draughts, the health a draught restores, the experience each level costs (level n needs n times levelXP), what a level adds to the maxHealth and attack bases, and how many turns recover 1 health (0 for none).
floors Each floor's generator (bsp or cave), size in cells (16 to 96 a side), how many monsters it spawns, how many times it rolls its loot table, and an optional guardian, a monster that stands on the exit and never leaves it.
monsters Each monster's display name, the letter and #rrggbb colour it is drawn in, its combat numbers, the experience it gives, the walking distance at which it starts to hunt, an optional drops table, and the floors it spawns on with its weight among them; a monster without from and to spawns only as a guardian.
items Each item's kind: a weapon or armor is equipped when its rank beats the one held and applies its stats effect, a draught adds to the draughts, a tonic applies its timed effect, and shards are the run's score. Loot drop counts are how many draughts or shards one drop gives.

Unknown fields, unknown kinds and generators, names that are not defined, and a version other than 1 are refused. The file is kept canonical: TestDataFilesAreCanonical fails when it is not in the form encodeDungeon writes, and loading a file and encoding it again changes nothing, so a review shows only real edits. TestDataFilesAgree checks the names the four files use from each other, including every condition and resource in data/abilities.yaml, which must be ones run.condition and draughtPool answer.

Where to change it

  • Floors: edit floors in data/dungeon.yaml. TestFloorsAreSound generates every floor of forty seeds and reports a floor that is not connected, whose exit is too close or whose spawns overlap; procgen.BSPConfig and procgen.CaveConfig in generateFloor shape the rooms and caves further.
  • Balance: monsters' numbers, the player's progression and the loot weights. TestBotsWinAndLose plays forty seeds with a bot that clears each floor and one that dives for the exits, and fails when the first stops winning or the second stops dying; it logs both counts.
  • A new monster or item: an entry in data/dungeon.yaml, its stats effect in data/stats.yaml for gear and tonics, and a line in a loot table for items. A new item kind needs a case in run.take.
  • A new ability: an entry in data/abilities.yaml with an action, a binding for that action in game.yaml, and a case in run.abilityEvent for its effect. roguelikeGame.update activates every ability by the action its entry names, and run.act uses whichever ability the action carries. A new condition or resource also needs a case in run.condition or draughtPool and its name in the data check.
  • Smarter monsters: the hunt system in actors.go walks down one distance map. A new behaviour is a new component and one more system on the scheduler run.newMonsterTurn builds, ordered with entities.Before and entities.After; ai has behaviour trees and pathfinding for monsters that flee, keep their distance or patrol.
  • Controls: the input section of game.yaml; touch regions are in virtual screen points. repeatDelay and repeatEvery in game.go set how fast a held direction walks.
  • Art: draw.go draws letters and shapes; load an atlas with sprite.LoadAtlas and draw a tilemap.Tilemap painted with procgen.Grid.Paint instead.
  • Saving: runSave in records.go is the run slot, and the codecs newActors registers name the components in it. When either changes shape, raise saveVersion and give newSaveStore a save.WithMigration.
이 페이지 편집