Documentation ¶
Index ¶
- Constants
- type Attr
- type BaseLevel
- type Canvas
- type Cell
- type Drawable
- type DynamicPhysical
- type Entity
- type Event
- type EventType
- type FpsText
- type Game
- func (g *Game) AddEntity(d Drawable)
- func (g *Game) CreateLevel(bg Attr)
- func (g *Game) DebugOn() bool
- func (g *Game) Level() Level
- func (g *Game) Log(log string, items ...interface{})
- func (g *Game) SetDebugOn(debugOn bool)
- func (g *Game) SetLevel(l Level)
- func (g *Game) SetScreen(s *Screen)
- func (g *Game) Start()
- type Key
- type Level
- type Modifier
- type Physical
- type Rectangle
- func (r *Rectangle) Color() Attr
- func (r *Rectangle) Draw(s *Screen)
- func (r *Rectangle) Position() (int, int)
- func (r *Rectangle) SetColor(color Attr)
- func (r *Rectangle) SetPosition(x, y int)
- func (r *Rectangle) SetSize(w, h int)
- func (r *Rectangle) Size() (int, int)
- func (r *Rectangle) Tick(ev Event)
- type Screen
- type Text
- func (t *Text) Color() (Attr, Attr)
- func (t *Text) Draw(s *Screen)
- func (t *Text) Position() (int, int)
- func (t *Text) SetColor(fg, bg Attr)
- func (t *Text) SetPosition(x, y int)
- func (t *Text) SetText(text string)
- func (t *Text) Size() (int, int)
- func (t *Text) Text() string
- func (t *Text) Tick(ev Event)
Constants ¶
const ModAltModifier = 0x01
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attr ¶
type Attr uint16
type BaseLevel ¶
type BaseLevel struct {
// contains filtered or unexported fields
}
BaseLevel type represents a Level with a background defined as a Cell, and a slice of Drawables, entities, that are drawn after the background.
func NewBaseLevel ¶
NewBaseLevel creates a new BaseLevel with background bg. Returns a pointer to the new BaseLevel.
func (*BaseLevel) DrawBackground ¶
DrawBackground draws the background Cell bg to each Cell of the Screen s.
func (*BaseLevel) RemoveEntity ¶
RemoveEntity removes Drawable d from the level's entities.
type Cell ¶
type Cell struct { Fg Attr // Foreground colour Bg Attr // Background color Ch rune // The character to draw }
Represents a character to be drawn on the screen.
type Drawable ¶
type Drawable interface { Tick(Event) // Method for processing events, e.g. input Draw(*Screen) // Method for drawing to the screen }
Drawable represents something that can be drawn, and placed in a Level.
type DynamicPhysical ¶
type DynamicPhysical interface { Position() (int, int) // Return position, x and y Size() (int, int) // Return width and height Collide(Physical) // Handle collisions with another Physical }
DynamicPhysical represents something that can process its own collisions. Implementing this is an optional addition to Drawable.
type Entity ¶
type Entity struct {
// contains filtered or unexported fields
}
Provides a general Drawable to be rendered.
func NewEntity ¶
NewEntity creates a new Entity, with position (x, y) and size (width, height). Returns a pointer to the new Entity.
func (*Entity) Draw ¶
Draw draws the entity to its current position on the screen. This is usually called every frame.
func (*Entity) SetCell ¶
SetCell updates the attribute of the Cell at x, y to match those of c. The coordinates are relative to the entity itself, not the Screen.
func (*Entity) SetPosition ¶
SetPosition sets the x and y coordinates of the Entity.
type Event ¶
type Event struct { Type EventType // The type of event Key Key // The key pressed, if any Ch rune // The character of the key, if any Mod Modifier // A keyboard modifier, if any Err error // Error, if any }
Provides an event, for input, errors or resizing. Resizing and errors are largely handled by Termloop itself - this would largely be used for input.
type FpsText ¶
type FpsText struct {
// contains filtered or unexported fields
}
FpsText provides a Text which updates with the current 'framerate' at specified intervals, to be used for testing performance. Please note that the framerate displayed is a measure of Termloop's processing speed - visible framerate is largely dependent on your terminal!
func NewFpsText ¶
NewFpsText creates a new FpsText at position (x, y) and with background and foreground colors fg and bg respectively. It will refresh every 'update' seconds. Returns a pointer to the new FpsText.
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
Represents a top-level Termloop application.
func NewGame ¶
func NewGame() *Game
NewGame creates a new Game, along with a Screen and input handler. Returns a pointer to the new Game.
func (*Game) CreateLevel ¶
CreateLevel creates a new BaseLevel with background color bg, and sets it as the Game's level.
func (*Game) Log ¶
Log takes a log string and additional parameters, which can be substituted into the string using standard fmt.Printf rules. The formatted string is added to Game g's logs. If debug mode is on, the log will be printed to the terminal when Termloop exits.
func (*Game) SetDebugOn ¶
SetDebugOn sets debug mode's on status to be debugOn.
type Key ¶
type Key uint16
const ( KeyF1 Key = 0xFFFF - iota KeyF2 KeyF3 KeyF4 KeyF5 KeyF6 KeyF7 KeyF8 KeyF9 KeyF10 KeyF11 KeyF12 KeyInsert KeyDelete KeyHome KeyEnd KeyPgup KeyPgdn KeyArrowUp KeyArrowDown KeyArrowLeft KeyArrowRight MouseLeft MouseMiddle MouseRight )
Key constants. See Event.Key.
const ( KeyCtrlTilde Key = 0x00 KeyCtrl2 Key = 0x00 KeyCtrlSpace Key = 0x00 KeyCtrlA Key = 0x01 KeyCtrlB Key = 0x02 KeyCtrlC Key = 0x03 KeyCtrlD Key = 0x04 KeyCtrlE Key = 0x05 KeyCtrlF Key = 0x06 KeyCtrlG Key = 0x07 KeyBackspace Key = 0x08 KeyCtrlH Key = 0x08 KeyTab Key = 0x09 KeyCtrlI Key = 0x09 KeyCtrlJ Key = 0x0A KeyCtrlK Key = 0x0B KeyCtrlL Key = 0x0C KeyEnter Key = 0x0D KeyCtrlM Key = 0x0D KeyCtrlN Key = 0x0E KeyCtrlO Key = 0x0F KeyCtrlP Key = 0x10 KeyCtrlQ Key = 0x11 KeyCtrlR Key = 0x12 KeyCtrlS Key = 0x13 KeyCtrlT Key = 0x14 KeyCtrlU Key = 0x15 KeyCtrlV Key = 0x16 KeyCtrlW Key = 0x17 KeyCtrlX Key = 0x18 KeyCtrlY Key = 0x19 KeyCtrlZ Key = 0x1A KeyEsc Key = 0x1B KeyCtrlLsqBracket Key = 0x1B KeyCtrl3 Key = 0x1B KeyCtrl4 Key = 0x1C KeyCtrlBackslash Key = 0x1C KeyCtrl5 Key = 0x1D KeyCtrlRsqBracket Key = 0x1D KeyCtrl6 Key = 0x1E KeyCtrl7 Key = 0x1F KeyCtrlSlash Key = 0x1F KeyCtrlUnderscore Key = 0x1F KeySpace Key = 0x20 KeyBackspace2 Key = 0x7F KeyCtrl8 Key = 0x7F )
type Physical ¶
type Physical interface { Position() (int, int) // Return position, x and y Size() (int, int) // Return width and height }
Physical represents something that can collide with another Physical, but cannot process its own collisions. Optional addition to Drawable.
type Rectangle ¶
type Rectangle struct {
// contains filtered or unexported fields
}
A type representing a 2D rectangle, with position, size and color.
func NewRectangle ¶
NewRectangle creates a new Rectangle at position (x, y), with size (width, height) and color color. Returns a pointer to the new Rectangle.
func (*Rectangle) SetPosition ¶
SetPosition sets the coordinates of the Rectangle to be x and y.
type Screen ¶
type Screen struct {
// contains filtered or unexported fields
}
A Screen represents the current state of the display. To draw on the screen, create Drawables and set their positions. Then, add them to the Screen's Level, or to the Screen directly (e.g. a HUD).
func NewScreen ¶
func NewScreen() *Screen
NewScreen creates a new Screen, with no entities or level. Returns a pointer to the new Screen.
func (*Screen) Draw ¶
func (s *Screen) Draw()
Draw is called every frame by the Game to render the current state of the screen.
func (*Screen) RenderCell ¶
RenderCell updates the Cell at a given position on the Screen with the attributes in Cell c.
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text represents a string that can be drawn to the screen.
func NewText ¶
NewText creates a new Text, at position (x, y). It sets the Text's background and foreground colors to fg and bg respectively, and sets the Text's text to be text. Returns a pointer to the new Text.
func (*Text) SetColor ¶
SetColor sets the (foreground, background) colors of the Text to fg, bg respectively.
func (*Text) SetPosition ¶
SetPosition sets the coordinates of the Text to be (x, y).