game

package
v0.0.0-...-fec722e Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2013 License: BSD-2-Clause Imports: 15 Imported by: 0

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

View Source
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
)
View Source
const (
	DEFAULT_HP = 10
)
View Source
const (
	// weight? #items?
	DEFAULT_INVENTORY_CAP = 10
)

Variables

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

func SamePos

func SamePos(ob1, ob2 Object) bool

Types

type Action

type Action int

func (Action) String

func (a Action) String() string

type DefaultSubject

type DefaultSubject struct {
	sync.Mutex
	Observers *list.List
}

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

func (gob *GameObject) Draw(buf *tulib.Buffer, pos image.Point)

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

func (gob *GameObject) SetTag(tag string, val bool) (old bool)

func (GameObject) String

func (gob GameObject) String() string

func (*GameObject) Update

func (gob *GameObject) Update(delta time.Duration)

type GameObjectMap

type GameObjectMap struct {
	Objs map[int]Object
	// contains filtered or unexported fields
}

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

type Inventory struct {
	Items    map[int]*Item
	Capacity int
}

func NewInventory

func NewInventory() *Inventory

func (Inventory) AddItem

func (inv Inventory) AddItem(i *Item)

func (Inventory) ContainsItem

func (inv Inventory) ContainsItem(i *Item) bool

func (Inventory) ContainsItemNamed

func (inv Inventory) ContainsItemNamed(name string) bool

Returns an item with .Name == name if it exists, otherwise false

func (Inventory) DestroyItem

func (inv Inventory) DestroyItem(i *Item)

func (Inventory) DropItem

func (inv Inventory) DropItem(i *Item) *Item

Removes an item from an Invetory yet returns the dropped item to the caller for further processing

func (Inventory) GetItemNamed

func (inv Inventory) GetItemNamed(name string) *Item

Assumes Item exists in Inventory (or panics)

func (Inventory) String

func (i Inventory) String() string

Iterates over Inventory items and prints their attrs Should intelligently handle printing items in qty > 1 assuming the items also have the same properties (modifiers, etc)

type Item

type Item struct {
	Object // The game object?

	Desc     string
	Weight   int
	Modifier int
}

func NewItem

func NewItem(name string) *Item

func (Item) String

func (i Item) String() string

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 MapChunkFromFile(mapfile string) *MapChunk

func NewMapChunk

func NewMapChunk() *MapChunk

func (*MapChunk) CheckCollision

func (mc *MapChunk) CheckCollision(gob *GameObject, pos image.Point) bool

func (*MapChunk) GetTerrain

func (mc *MapChunk) GetTerrain(pt image.Point) (t *Terrain, ok bool)

get terrain at v. returns nil, false if it is not present

func (*MapChunk) HasCell

func (mc *MapChunk) HasCell(pt image.Point) bool

return true if the map chunk has a cell with coordinates v.X, v.Y

func (*MapChunk) RandCell

func (mc *MapChunk) RandCell() image.Point

Generates an array of (x,y) tuples of open spots on the map, called open, and selects random(1, len(open))

func (*MapChunk) String

func (mc *MapChunk) String() string

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

func NewGameObject(name string) Object

type Observer

type Observer interface {
	Update()
}

type Player

type Player struct {
	*Unit
}

func NewPlayer

func NewPlayer(name string) *Player

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 Session

type Session interface {
	SendPacket(pk *gnet.Packet)
	GetPlayer() *Player
	ID() uuid.UUID
	Username() string
}

type Subject

type Subject interface {
	Attach(obs Observer)
	Detach(obs Observer)
	Notify()
}

type Terrain

type Terrain struct {
	//*GameObject
	Glyph termbox.Cell
	Type  TerrainType
}

func GlyphToTerrain

func GlyphToTerrain(g rune) (t *Terrain, ok bool)

func (*Terrain) Draw

func (t *Terrain) Draw(b *tulib.Buffer, pt image.Point)

func (*Terrain) IsEmpty

func (t *Terrain) IsEmpty() bool

func (*Terrain) IsGround

func (t *Terrain) IsGround() bool

func (*Terrain) IsWall

func (t *Terrain) IsWall() bool

func (Terrain) String

func (t Terrain) String() string

type TerrainType

type TerrainType uint32

func (*TerrainType) String

func (tt *TerrainType) String() string

type Unit

type Unit struct {
	Object
	*Inventory

	Level     int
	Hp, HpMax int
}

func NewUnit

func NewUnit(name string) *Unit

func (Unit) HasItem

func (u Unit) HasItem(i *Item) bool

Checks if a Unit HasItem *Item

func (Unit) String

func (u Unit) String() string

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.

Jump to

Keyboard shortcuts

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