Documentation
¶
Overview ¶
Package gorogue is a simple roguelike engine build in golang.
Goals For This Project:
1. Keep it simple, stupid
I'm building an engine, not a game. The idea is to create a simple tool that any designer can extend to create their game. I'm not going to bloat the repository with unnecessary things like lots of items, or damage equations or things like that. Users will have to add those features per their needs.
2. Focus on versatility
I want this project to be flexible. That's why I'll be supporting a wide variety of "play styles" including: Turn Based, "Real time", Multi-player, and Squad/Party based.
3. An engine is only as good as its documentation.
4. Implement as little as possible in the base package.
Use the base package as a skeleton for any game to work from. Implement things in subpackages so they can just as easily be extended as removed.
Index ¶
- Constants
- Variables
- func BindCommand(cmd Command, Action Action)
- func BindKey(key Key, Action Action)
- func CatchSignals()
- func NewClient(c Client, host, port string) error
- func NewServer(s Server, port string)
- func SetCell(x, y int, c termbox.Cell)
- type Action
- type ActionQuit
- type ActionResponse
- type Actor
- type BaseAction
- type Border
- type BorderSet
- type Bounds
- type Client
- type Command
- type Conn
- type Direction
- type Key
- type Map
- type Object
- type Point
- type Pos
- type Server
- type Tile
- type TileSet
- type UI
- func (u *UI) AddView(name string, v View)
- func (u *UI) Bounds() Bounds
- func (u *UI) Draw() error
- func (u UI) DrawAt(cells [][]termbox.Cell, Ox, Oy int) error
- func (u *UI) Name() string
- func (u UI) OutOfScreenBoundryError(b Bounds) error
- func (u *UI) Run()
- func (u *UI) SetBorder(b BorderSet)
- func (u UI) String(Ox, Oy int, fg, bg termbox.Attribute, s string) error
- func (u *UI) Type() UIElementType
- type UIElement
- type UIElementType
- type UITemplate
- type View
Constants ¶
const ( LightBorder BorderSet = "─│┌┬┐├┼┤└┴┘" HeavyBorder = "━┃┏┳┓┣╋┫┗┻┛" DoubleBorder = "═║╔╦╗╠╬╣╚╩╝" )
const KeyNotBoundError string = "Key not bound"
Variables ¶
var ( Esc Key = Key{0, termbox.KeyEsc, 0} Tab = Key{0, termbox.KeyTab, 0} Space = Key{0, termbox.KeySpace, 0} Backspace = Key{0, termbox.KeyBackspace, 0} Enter = Key{0, termbox.KeyEnter, 0} )
Special keys are listed here:
TODO add more keys.
var Commands map[Command]Action
Commands stores all currently bound commands
var Keybinds map[Key]Action
Keybinds stores all currently bound keys.
Functions ¶
func BindCommand ¶
BindCommand maps a Command to an action, overwriting any action the Command was previously mapped to
func BindKey ¶
BindKey maps a key to an action, overwriting any action the Key was previously mapped to
func CatchSignals ¶
func CatchSignals()
Types ¶
type Action ¶
type Action interface { Name() string // The name of the Action to be performed. Caller() string // The originator of the Action. Args() []interface{} // Any relevant parameters the action needs. }
Actions are the heart of the game's operation.
func KeyPressed ¶
type ActionQuit ¶
type ActionQuit struct {
Caller string
}
func (*ActionQuit) Action ¶
func (a *ActionQuit) Action() Action
type ActionResponse ¶
type ActionResponse struct { Msg *string // Message to display to the user / logs. Reply bool // Whether the action completed sucessfully }
ActionResponse is a stuct returned from the server to a client or NPC, informing them of whether their action was performed, and if not, why not.
type Actor ¶
type Actor interface { Object // The Object interface. Move(pos Pos) bool // Moves the Actor to the given position. }
Actor is an object that can act freely. There are two main kinds of actors: player characters and non-player characters (NPCs). The important distinction being that NPCs are controlled by the server, and Player characters are controlled by clients.
Each NPC gets their own goroutine, meaning each acts on their own thread, separate from other actors. The server receives requests to act from each NPC, and determines whether that action is valid. If if isn't, the action is rejected and the Actor must choose a different action to perform. If the action is valid, it gets stored in memory and is called during the next Map tick. (See Map.Tick)
type BaseAction ¶
type BaseAction struct {
// contains filtered or unexported fields
}
func NewAction ¶
func NewAction(name, caller string, args ...interface{}) *BaseAction
func (*BaseAction) Args ¶
func (b *BaseAction) Args() []interface{}
func (*BaseAction) Caller ¶
func (b *BaseAction) Caller() string
func (*BaseAction) Name ¶
func (b *BaseAction) Name() string
type Border ¶
type Border struct { BorderSet // The runes to use for the border. UIElement // The element this is bordering. }
Border is a border around a UI element.
type BorderSet ¶
type BorderSet TileSet
BorderSet is a set of characters that can be used to border a UI element. BorderSets must be laid out in the following order:
Top Left, Top Right, Bottom Left, Bottom Right, Horizontal, Vertical VerticalRight, VerticalLeft, LeftUp, Center,DownHorizontal
TODO: Add remaining borders.
type Bounds ¶
type Bounds [2]Point
Bounds hold the top left-most and bottom right-most points of a UIElement
type Command ¶
type Command string
Command is a string mapped to an Action. Commands are intended to be called in a Vi style command bar.
TODO: (7) Implement Vi command bar.
type Conn ¶
type Conn struct { Conn *net.Conn // Connection data. Squad []Actor // Actors this connection has control over. }
Conn is the server-side representation of a connection to a client.
type Direction ¶
type Direction uint8
Direction represents the cardinal and ordinal directions. North points towards the top of the screen, east points to the right, etc.
Converting between coordinates and Directions is often done with Bitwise operations, hence why they are not laid out in perfect sequence.r
type Key ¶
type Key struct { Mod termbox.Modifier // One of termbox.Mod* constants or 0. Key termbox.Key // One of termbox.Key* constants, invalid if 'Ch' is not 0. Ch rune // a unicode character. }
Key is a keyboard key mapped to an Action. See package github.com/nsf/termbox-go for more information.
type UI ¶
type UI struct { Border *Border // The UI's border (if any). Views map[string]*View // Views contained in this UI. // contains filtered or unexported fields }
UI holds everything a player sees in game.
TODO: Improve UI description.
func (*UI) AddView ¶
AddView adds a view to this UI. The view is automatically adjusted to fit if u has a Border.
func (*UI) Draw ¶
Draw displays the UI in termbox. UIElements are drawn in the following order:
Views, Border.
func (UI) DrawAt ¶
DrawAt draws the given cells in termbox at the given location (0x, 0y). Currently, this will write over any existing cells.
DrawAt returns OutOfScreenBoundryError if the drawing exceeds termbox's size.
func (UI) OutOfScreenBoundryError ¶
Returned after an element is drawn. Returns nil if b does not exceed the terminal's size.
func (UI) String ¶
String prints an unterminated string, starting at the given coordinates (Ox, Oy).
String returns OutOfScreenBoundryError if the drawing exceeds termbox's size.
func (*UI) Type ¶
func (u *UI) Type() UIElementType
type UIElement ¶
type UIElement interface { Name() string Type() UIElementType Bounds() Bounds }
UIElement is anything that can show up in termbox, including UIs, Views and Borders
type UIElementType ¶
type UIElementType uint8
UIElementType is an enum of valid UIElements.
const ( UITypeBorder UIElementType = iota UITypeUI UITypeView )
type UITemplate ¶
type UITemplate struct {
*UI
}
UITemplate provides some example UIs to help with starting your game.
func Fullscreen ¶
func Fullscreen(m *string) *UITemplate
Fullscreen returns a minimum terminal sized UI (80x24), with one view into a map.
type View ¶
type View struct { Bounds Origin Point // Where this view is located in the UI. Map *string // The Map data is drawn from. }
View is a window into a Map. Views can be any size.