Documentation
¶
Overview ¶
Core game object interfaces
Inventory is a collection of items ¶
Item is any construct which can be stored in a Unit's inventory can be equipment.
Game map functions ¶
Player is a Unit that is controllable by a client (this should really have no distinction)
Time wrapper for easy delta timers ¶
Unit is a non-static game object
Index ¶
- Constants
- Variables
- func SamePos(ob1, ob2 Object) bool
- type Action
- type DefaultSubject
- type DeltaTimer
- type GameObject
- func (gob *GameObject) AddSubObject(obj Object)
- func (gob *GameObject) Draw(buf *tulib.Buffer, pos image.Point)
- func (gob *GameObject) GetGlyph() termbox.Cell
- func (gob *GameObject) GetID() int
- func (gob *GameObject) GetName() string
- func (gob *GameObject) GetPos() (x, y int)
- func (gob *GameObject) GetSubObjects() *GameObjectMap
- func (gob *GameObject) GetTag(tag string) bool
- func (gob *GameObject) RemoveSubObject(obj Object) Object
- func (gob *GameObject) SetGlyph(glyph termbox.Cell)
- func (gob *GameObject) SetID(id int)
- func (gob *GameObject) SetName(name string)
- func (gob *GameObject) SetPos(x, y int) bool
- func (gob *GameObject) SetTag(tag string, val bool) (old bool)
- func (gob GameObject) String() string
- func (gob *GameObject) Update(delta time.Duration)
- type GameObjectMap
- type Inventory
- func (inv Inventory) AddItem(i *Item)
- func (inv Inventory) ContainsItem(i *Item) bool
- func (inv Inventory) ContainsItemNamed(name string) bool
- func (inv Inventory) DestroyItem(i *Item)
- func (inv Inventory) DropItem(i *Item) *Item
- func (inv Inventory) GetItemNamed(name string) *Item
- func (i Inventory) String() string
- type Item
- type MapChunk
- type Object
- type Observer
- type Player
- type Renderable
- type Session
- type Subject
- type Terrain
- type TerrainType
- type Unit
Constants ¶
const ( MAP_WIDTH = 256 MAP_HEIGHT = 256 T_EMPTY TerrainType = iota T_WALL // can't pass/see through wall T_GROUND // passable/visible T_UNIT DIR_UP Action = iota // player movement instructions DIR_DOWN DIR_LEFT DIR_RIGHT ACTION_ITEM_PICKUP ACTION_ITEM_DROP ACTION_ITEM_LIST_INVENTORY )
const (
DEFAULT_HP = 10
)
const (
// weight? #items?
DEFAULT_INVENTORY_CAP = 10
)
Variables ¶
var ( DirTable = map[Action]image.Point{ DIR_UP: image.Point{0, -1}, DIR_DOWN: image.Point{0, 1}, DIR_LEFT: image.Point{-1, 0}, DIR_RIGHT: image.Point{1, 0}, } GLYPH_EMPTY = termbox.Cell{Ch: ' '} GLYPH_WALL = termbox.Cell{Ch: '#', Fg: termbox.ColorDefault, Bg: termbox.ColorBlack | termbox.AttrUnderline | termbox.AttrBold} GLYPH_GROUND = termbox.Cell{Ch: '.', Fg: termbox.ColorGreen} GLYPH_FLAG = termbox.Cell{Ch: '%', Fg: termbox.ColorCyan} GLYPH_ITEM = termbox.Cell{Ch: '?', Fg: termbox.ColorCyan} GLYPH_HUMAN = termbox.Cell{Ch: '@'} )
Functions ¶
Types ¶
type DefaultSubject ¶
func NewDefaultSubject ¶
func NewDefaultSubject() *DefaultSubject
func (*DefaultSubject) Attach ¶
func (sub *DefaultSubject) Attach(obs Observer)
func (*DefaultSubject) Detach ¶
func (sub *DefaultSubject) Detach(obs Observer)
func (*DefaultSubject) Notify ¶
func (sub *DefaultSubject) Notify()
type DeltaTimer ¶
type DeltaTimer struct {
// contains filtered or unexported fields
}
func NewDeltaTimer ¶
func NewDeltaTimer() *DeltaTimer
func (*DeltaTimer) DeltaTime ¶
func (dt *DeltaTimer) DeltaTime() time.Duration
DeltaTime returns the time between now and the last time DeltaTime was called. If DeltaTime is called the first time, the last time is the time DeltaTimer was created. DeltaTime also resets the timer.
func (*DeltaTimer) GetDeltaTime ¶
func (dt *DeltaTimer) GetDeltaTime() time.Duration
GetDeltaTime returns the time between now and the last time DeltaTime was called. If DeltaTime is called the first time, the last time is the time DeltaTimer was created. GetDeltaTime does not reset the timer.
func (*DeltaTimer) Reset ¶
func (dt *DeltaTimer) Reset()
Reset resets sets the time of the timer to now.
type GameObject ¶
type GameObject struct {
ID int // game object id
ItemID int // id if from game/data/itemdb.lua, else -1
Name string // object name
Pos image.Point // object world coordinates
Glyph termbox.Cell // character for this object
Tags map[string]bool // object tags
SubObjects *GameObjectMap // objects associated with this one
// contains filtered or unexported fields
}
func (*GameObject) AddSubObject ¶
func (gob *GameObject) AddSubObject(obj Object)
func (*GameObject) GetGlyph ¶
func (gob *GameObject) GetGlyph() termbox.Cell
func (*GameObject) GetID ¶
func (gob *GameObject) GetID() int
func (*GameObject) GetName ¶
func (gob *GameObject) GetName() string
func (*GameObject) GetPos ¶
func (gob *GameObject) GetPos() (x, y int)
func (*GameObject) GetSubObjects ¶
func (gob *GameObject) GetSubObjects() *GameObjectMap
func (*GameObject) GetTag ¶
func (gob *GameObject) GetTag(tag string) bool
func (*GameObject) RemoveSubObject ¶
func (gob *GameObject) RemoveSubObject(obj Object) Object
func (*GameObject) SetGlyph ¶
func (gob *GameObject) SetGlyph(glyph termbox.Cell)
func (*GameObject) SetID ¶
func (gob *GameObject) SetID(id int)
func (*GameObject) SetName ¶
func (gob *GameObject) SetName(name string)
func (*GameObject) SetPos ¶
func (gob *GameObject) SetPos(x, y int) bool
func (GameObject) String ¶
func (gob GameObject) String() string
func (*GameObject) Update ¶
func (gob *GameObject) Update(delta time.Duration)
type GameObjectMap ¶
handy interface for a collection of game objects
func NewGameObjectMap ¶
func NewGameObjectMap() *GameObjectMap
func (*GameObjectMap) Add ¶
func (gom *GameObjectMap) Add(obj Object)
func (*GameObjectMap) Chan ¶
func (gom *GameObjectMap) Chan() <-chan Object
func (*GameObjectMap) FindObjectByID ¶
func (gom *GameObjectMap) FindObjectByID(id int) Object
func (*GameObjectMap) GetSlice ¶
func (gom *GameObjectMap) GetSlice() []Object
return a slice containing the objects XXX: crappy hack so lua can iterate the contents
func (*GameObjectMap) RemoveObject ¶
func (gom *GameObjectMap) RemoveObject(obj Object)
type Inventory ¶
func NewInventory ¶
func NewInventory() *Inventory
func (Inventory) ContainsItem ¶
func (Inventory) ContainsItemNamed ¶
Returns an item with .Name == name if it exists, otherwise false
func (Inventory) DestroyItem ¶
func (Inventory) DropItem ¶
Removes an item from an Invetory yet returns the dropped item to the caller for further processing
func (Inventory) GetItemNamed ¶
Assumes Item exists in Inventory (or panics)
type MapChunk ¶
type MapChunk struct {
Size image.Point
Rect image.Rectangle
Locations [][]*Terrain // land features
GameObjects []*GameObject // active game objects
Players []*Player // active players
}
func MapChunkFromFile ¶
func NewMapChunk ¶
func NewMapChunk() *MapChunk
func (*MapChunk) CheckCollision ¶
func (mc *MapChunk) CheckCollision(gob *GameObject, pos image.Point) bool
func (*MapChunk) GetTerrain ¶
get terrain at v. returns nil, false if it is not present
type Object ¶
type Object interface {
// Setter/getter for ID
SetID(id int)
GetID() int
SetName(name string)
GetName() string
// Setter/getter for position
SetPos(x, y int) bool
GetPos() (x, y int)
// Setter/getter for the glyph
SetGlyph(termbox.Cell)
GetGlyph() termbox.Cell
// Setter/getter for tags
SetTag(tag string, val bool) bool // returns old value
GetTag(tag string) bool
GetSubObjects() *GameObjectMap
AddSubObject(obj Object)
RemoveSubObject(obj Object) Object
// update this object with delta
Update(delta time.Duration)
Renderable
}
func NewGameObject ¶
type Renderable ¶
type Renderable interface {
// Draw this object on the buffer at pos
Draw(buf *tulib.Buffer, pos image.Point)
}
TODO: remove need for this when drawing terrain with camera.Draw
type Terrain ¶
type Terrain struct {
//*GameObject
Glyph termbox.Cell
Type TerrainType
}
func GlyphToTerrain ¶
type TerrainType ¶
type TerrainType uint32
func (*TerrainType) String ¶
func (tt *TerrainType) String() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Packet: message type for flow procs and chanio connections
|
Packet: message type for flow procs and chanio connections |
|
This file describes general interfaces that game objects should try to take advantage of.
|
This file describes general interfaces that game objects should try to take advantage of. |