gorogue

package module
v0.0.0-...-7867579 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2018 License: LGPL-3.0 Imports: 12 Imported by: 0

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

View Source
const (
	LightBorder  BorderSet = "─│┌┬┐├┼┤└┴┘"
	HeavyBorder            = "━┃┏┳┓┣╋┫┗┻┛"
	DoubleBorder           = "═║╔╦╗╠╬╣╚╩╝"
)
View Source
const KeyNotBoundError string = "Key not bound"

Variables

View Source
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.

View Source
var Commands map[Command]Action

Commands stores all currently bound commands

View Source
var Keybinds map[Key]Action

Keybinds stores all currently bound keys.

Functions

func BindCommand

func BindCommand(cmd Command, Action Action)

BindCommand maps a Command to an action, overwriting any action the Command was previously mapped to

func BindKey

func BindKey(key Key, Action Action)

BindKey maps a key to an action, overwriting any action the Key was previously mapped to

func CatchSignals

func CatchSignals()

func NewClient

func NewClient(c Client, host, port string) error

Connect initializes a connection to a server. It must be called before all other functions.

func NewServer

func NewServer(s Server, port string)

func SetCell

func SetCell(x, y int, c termbox.Cell)

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 Input

func Input() (Action, error)

Input polls the user for a Key, and returns the Action it's mapped to (if any).

func KeyPressed

func KeyPressed(key Key) (Action, error)

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.

func (*Border) Bounds

func (b *Border) Bounds() Bounds

Bounds returns the bounds of b's UIElement.

func (*Border) Draw

func (b *Border) Draw()

Draw prints the border into termbox. Borders get drawn after the elements inside them.

func (*Border) Type

func (b *Border) Type() UIElementType

Type return's b's UIElementType.

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 Client

type Client interface {
	Addr() string
	Init() *UI
	Ping()
	HandleAction(a Action)
	Maps() map[string]Map
	Squad() []Actor
	SetAddr(addr string)
	SetRPC(conn *rpc.Client)
}

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

const (
	North     Direction = 1 + iota // 0001
	East                           // 0010
	NorthEast                      // 0011
	West                           // 0100
	NorthWest                      // 0101
	South     Direction = 8        // 1000
	SouthEast Direction = 10       // 1010
	SouthWest Direction = 12       // 1100
)

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 Map

type Map interface {
	TileSlice(x1, x2, w, h int) [][]Tile
}

type Object

type Object interface {
	Name() string
	ID() string
	Index() int
	MarshalJSON() ([]byte, error)
	Pos() *Pos
	SetIndex(i int)
	SetPos(p Pos)
	Sprite() termbox.Cell
	UnmarshalJSON(data []byte) error
}

type Point

type Point struct {
	X int
	Y int
}

Point represents a coordinate pair.

func (*Point) Ints

func (p *Point) Ints() (x, y int)

Ints returns the point as a pair of ints.

type Pos

type Pos struct {
	Point
	Map string
}

Pos represents the position of an object.

func NewPos

func NewPos(x, y int, Map string) *Pos

func (*Pos) Ints

func (p *Pos) Ints() (x, y int, Map string)

Ints

type Server

type Server interface {
	Conns() map[string]*Conn
	HandleRequests()
	// Maps() map[string]*Map
	// Ping(addr *string, reply *Pong)
	Port() string
	SetPort(port string)
}

type Tile

type Tile struct {
	Sprite termbox.Cell
}

type TileSet

type TileSet string

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 NewUI

func NewUI(name string, w, h int) *UI

New creates a new UI with a given name and size.

func (*UI) AddView

func (u *UI) AddView(name string, v View)

AddView adds a view to this UI. The view is automatically adjusted to fit if u has a Border.

func (*UI) Bounds

func (u *UI) Bounds() Bounds

Bounds return's u's bounds, including the border (if any).

func (*UI) Draw

func (u *UI) Draw() error

Draw displays the UI in termbox. UIElements are drawn in the following order:

Views, Border.

func (UI) DrawAt

func (u UI) DrawAt(cells [][]termbox.Cell, Ox, Oy int) error

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) Name

func (u *UI) Name() string

func (UI) OutOfScreenBoundryError

func (u UI) OutOfScreenBoundryError(b Bounds) error

Returned after an element is drawn. Returns nil if b does not exceed the terminal's size.

func (*UI) Run

func (u *UI) Run()

Run runs the active UI.

func (*UI) SetBorder

func (u *UI) SetBorder(b BorderSet)

func (UI) String

func (u UI) String(Ox, Oy int, fg, bg termbox.Attribute, s string) error

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.

func NewView

func NewView(bounds Bounds, m *string, origin Point) *View

NewView returns a newly created view.

bounds is the portion of the map that you want displayed.

origin is the location in the UI where you want this view to be placed.

func (*View) Draw

func (v *View) Draw() error

Draw displays the view in termbox.

Directories

Path Synopsis
Package client handles drawing the UI, interfacing with the player, and talking to the server.
Package client handles drawing the UI, interfacing with the player, and talking to the server.

Jump to

Keyboard shortcuts

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