arcade

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package arcade is the Concord Arcade standard for game plugins: a character-cell canvas with half-block pixels, the shaded pixel-font logo, seven-segment digits, colour roles taken from each viewer's Concord theme, the pass-and-draft reward system (Pit Passes, Gold Stars: each game names its own) and a generated chiptune sound kit.

Screens are drawn on a Canvas the size of the viewer's pane and returned from a pane model's View as Canvas.String(). Everything is plain text with SGR colours, so it works in any terminal Concord runs in.

Index

Constants

View Source
const (
	SoundBlip    = "sounds/blip.wav"    // the menu cursor moves
	SoundSelect  = "sounds/select.wav"  // a choice is made
	SoundBack    = "sounds/back.wav"    // back one screen
	SoundCoin    = "sounds/coin.wav"    // PRESS ENTER
	SoundAmber   = "sounds/amber.wav"   // a countdown light
	SoundGo      = "sounds/go.wav"      // green: go
	SoundRed     = "sounds/red.wav"     // a foul or a false start
	SoundMistake = "sounds/mistake.wav" // a mistake
	SoundFinish  = "sounds/finish.wav"  // the finish fanfare
	SoundRecord  = "sounds/record.wav"  // a new record, an unlock
)

The sound kit: short chiptune effects made from square, triangle and sawtooth waves, like an 8-bit sound chip. They're generated here, so every game has the same sounds and nothing is borrowed. Write them into a plugin's client/ folder with WriteSoundKit and play them with plugin.Conn.PlaySound(channel, viewer, arcade.SoundCoin, 0).

View Source
const OfferSize = 3

OfferSize is how many locked items a pass offers.

Variables

View Source
var LogoShade = []string{"hi", "hi", "purple", "purple", "purple", "pink", "pink"}

LogoShade is the standard logo shading, one role per pixel row: light at the top, the brand purple, then pink at the foot.

View Source
var PaintNames = map[string]string{
	"cyan": "ICE BLUE", "pink": "BUBBLEGUM", "green": "LIME LEAF", "orange": "ORANGE CRUSH",
	"yellow": "LEMON DROP", "red": "CHERRY", "fg": "SILVER",
}

PaintNames are the paints' display names.

View Source
var Paints = []string{"cyan", "pink", "green", "orange", "yellow", "red", "fg"}

Paints are the colours a player can choose for their piece or car. They are theme roles, so they follow each viewer's theme. Purple is never a paint: it is the brand colour, kept for the grapes.

Functions

func DigitWidth

func DigitWidth(scale int) int

DigitWidth is a seven-segment digit's width in cells at scale, gap included.

func Flip

func Flip(rows []string) []string

Flip mirrors pixel art left to right.

func LogoHeight

func LogoHeight(scale int) int

LogoHeight is how many rows Logo takes at scale, drop shadow included.

func LogoWidth

func LogoWidth(text string, scale int) int

LogoWidth is how many cells Logo takes for text at scale.

func SoundKit

func SoundKit() map[string][]byte

SoundKit returns every sound in the kit as WAV files (16-bit mono PCM), keyed by their path in client/.

func SpriteWidth

func SpriteWidth(rows []string, scale int) int

SpriteWidth is the width in cells of rows at scale.

func TextWidth

func TextWidth(s string) int

TextWidth is how many cells s takes.

func WriteSoundKit

func WriteSoundKit(clientDir string) error

WriteSoundKit writes the kit into a plugin's client folder (e.g. "client"), creating client/sounds/. Run it from a go:generate tool, and commit the files so releases include them.

Types

type Canvas

type Canvas struct {
	W, H int
	// contains filtered or unexported fields
}

Canvas is a grid of character cells the size of a pane. Coordinates are cells; pixel coordinates (py) count half-rows, two to a cell. Fine pixels (FinePx) also halve the columns: four to a cell.

func New

func New(w, h int, pal Palette) *Canvas

New makes a blank canvas.

func (*Canvas) Box

func (c *Canvas) Box(x, y, w, h int, role, title, titleRole string)

Box draws a Concord pane: rounded corners, the title set into the top border.

func (*Canvas) Center

func (c *Canvas) Center(y int, s, fg, bg string, bold bool) int

Center writes s centred on row y.

func (*Canvas) CenterIn

func (c *Canvas) CenterIn(x, w, y int, s, fg, bg string, bold bool) int

CenterIn writes s centred in the columns [x, x+w).

func (*Canvas) Digit

func (c *Canvas) Digit(d, x, py int, on string, scale int)

Digit draws one seven-segment digit (d < 0: all segments unlit) in role on, from column x and half-row py.

func (*Canvas) Fill

func (c *Canvas) Fill(x, y, n int, ch, fg, bg string)

Fill repeats ch n times from (x, y).

func (*Canvas) FinePx added in v0.15.0

func (c *Canvas) FinePx(fx, fy int, role string)

FinePx sets one fine pixel: half-column fx, half-row fy. Fine pixels are drawn with quadrant characters (▘▝▖▗▚▞▙▛▜▟), twice the detail of Px across but half as wide, so art for them is drawn twice as wide. A cell shows at most two colours, so keep fine art to one colour on a background; a third colour in one cell is drawn in the second's place.

func (*Canvas) FineSprite added in v0.15.0

func (c *Canvas) FineSprite(fx, fy int, rows []string, pal map[rune]string)

FineSprite draws pixel art in fine pixels from half-column fx and half-row fy: one string per row, one rune per fine pixel, looked up in pal (runes not in pal are see-through).

func (*Canvas) Keys

func (c *Canvas) Keys(x, y int, keys ...Key) int

Keys draws footer key chips the Concord way, the key in bold cyan on the current-line colour, from column x on row y.

func (c *Canvas) Logo(text string, x, py, scale int, shade []string)

Logo draws text in the arcade pixel font from cell column x and half-row py, with a drop shadow one pixel down and right. shade gives each pixel row's role (one role for a single colour); nil uses LogoShade. Unknown characters draw as spaces.

func (*Canvas) Number

func (c *Canvas) Number(n, digits, x, py int, on string, scale int)

Number draws n as seven-segment digits, zero-padded to digits.

func (*Canvas) Px

func (c *Canvas) Px(x, py int, role string)

Px sets one pixel: column x, half-row py.

func (*Canvas) Shade added in v0.12.0

func (c *Canvas) Shade(x, y, w, h int, bg string)

Shade sets the background of the cells in a w x h box at (x, y), keeping what's drawn in them: a chalkboard, a highlighted square.

func (*Canvas) Sprite

func (c *Canvas) Sprite(x, py int, rows []string, pal map[rune]string, scale int)

Sprite draws pixel art: one string per pixel row, one rune per pixel, looked up in pal (runes not in pal are see-through). Each pixel becomes a scale x scale block.

func (*Canvas) String

func (c *Canvas) String() string

String renders the canvas as lines of text with SGR colours, writing a style only when it changes. Every line is the full width: Concord centres each line of a frame on its own, so lines of different lengths would shift against each other.

func (*Canvas) Text

func (c *Canvas) Text(x, y int, s, fg, bg string, bold bool) int

Text writes s at (x, y) and returns the column after it. Characters past the edge are dropped. bg "" leaves the background alone.

type Color

type Color struct {
	// contains filtered or unexported fields
}

Color is one terminal colour: true colour, an ANSI palette index, or the terminal's own default.

func Mix

func Mix(a, b Color, t float64, fallback Color) Color

Mix blends a toward b by t (0 = a, 1 = b). Only true colours can be mixed; otherwise it returns fallback.

func ParseColor

func ParseColor(s string) Color

ParseColor reads "#rrggbb", an ANSI index "0"-"15", or "" (default).

func (Color) RGB

func (c Color) RGB() (r, g, b uint8, ok bool)

RGB reports whether the colour is true colour, and its components.

type Key

type Key struct{ Key, Does string }

Key is one footer hint: the key and what it does.

type Palette

type Palette struct {
	// contains filtered or unexported fields
}

Palette maps colour roles to the viewer's colours.

Base roles come straight from the Concord theme: bg, fg, comment, line, purple, pink, green, yellow, orange, red, cyan. Derived roles:

hi      purple lightened: the top of the logo, grape shine
shadow  purple darkened: the logo's drop shadow
ghost   comment darkened: unlit segments, bulbs and locked silhouettes
dim     quiet text
tire    near black
hub     wheel hubs
<paint>D a darker shade of each paint, e.g. "cyanD"
<colour>B a background tint of purple and each paint, e.g. "greenB" (a
         chalkboard), falling back to "line" where colours can't mix

func NewPalette

func NewPalette(t *wire.PaneTheme) Palette

NewPalette builds the roles from a viewer's theme (nil: Dracula).

func (Palette) Get

func (p Palette) Get(role string) Color

Get returns a role's colour (the default colour for an unknown role).

type Rewards

type Rewards struct {
	Passes int      `json:"passes"`
	Owned  []string `json:"owned,omitempty"`
	Offer  []string `json:"offer,omitempty"`
}

Rewards is one player's passes and what they've unlocked. Each game names its passes to suit it -- Pit Passes in Grape Race, Gold Stars in tic-tac-toe -- and only the name on screen differs. Keep it in the player's saved record: the offer is saved with it, so leaving and coming back shows the same choices (no re-rolling).

func (*Rewards) Count

func (r *Rewards) Count(items []Unlockable) int

Count is how many items are unlocked, starters included.

func (*Rewards) Deal

func (r *Rewards) Deal(items []Unlockable, rnd *rand.Rand) []string

Deal returns the current offer, dealing a new one when there's a pass to spend and no offer yet: up to OfferSize locked items, weighted by tier (common 6, rare 3, legendary 1), no repeats.

func (*Rewards) Grant

func (r *Rewards) Grant(n int, items []Unlockable) int

Grant adds n passes, never more than there is left to unlock. It reports how many were actually granted.

func (*Rewards) Locked

func (r *Rewards) Locked(items []Unlockable) []Unlockable

Locked is everything still to unlock, in catalogue order.

func (*Rewards) Owns

func (r *Rewards) Owns(id string, items []Unlockable) bool

Owns reports whether id is unlocked (starters always are).

func (*Rewards) Pick

func (r *Rewards) Pick(id string) bool

Pick spends a pass on id, which must be in the offer. The offer is then cleared, and the next Deal makes a new one.

type Tier

type Tier int

Tier is how rare an unlockable is.

const (
	Starter Tier = iota // owned from the start
	Common
	Rare
	Legendary
)

func (Tier) Name

func (t Tier) Name() string

Name is the tier as players see it.

func (Tier) Role

func (t Tier) Role() string

Role is the colour role the tier is shown in.

func (Tier) Stars

func (t Tier) Stars() string

Stars is the tier's star rating: none, ★, ★★ or ★★★.

type Unlockable

type Unlockable struct {
	ID   string
	Name string
	Tier Tier
	// Kind groups items a player picks one of ("pieces", "board"); a game
	// with a single kind (Grape Race's cars) can leave it empty.
	Kind string
	// Blurb is a line about it, shown when it's offered.
	Blurb string
}

Unlockable is something a player can earn: a car, a piece set, a board.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL