Documentation ¶
Index ¶
- Constants
- func DestroyTree(object GameObject) error
- func DrawTree(object GameObject, screen *ebiten.Image)
- func InitTree(object GameObject) error
- func UpdateTree(object GameObject) error
- type BaseObject
- func (o *BaseObject) AddChild(id string, child GameObject) error
- func (o *BaseObject) Destroy() error
- func (o *BaseObject) Draw(screen *ebiten.Image)
- func (o *BaseObject) GetChild(id string) GameObject
- func (o *BaseObject) GetChildren() []GameObject
- func (o *BaseObject) GetID() string
- func (o *BaseObject) GetZIndex() int
- func (o *BaseObject) Init() error
- func (o *BaseObject) RemoveChild(id string) error
- func (o *BaseObject) RemoveFromParent() error
- func (o *BaseObject) SetParent(parent GameObject)
- func (o *BaseObject) Update() error
- type GameObject
- type IndexedObjectList
- type LevelObject
- type Lifecycle
- type NPC
- type NewBaseObjectOpts
- type NewLevelObjectOptions
- type NewTextEffectOptions
- type Player
- func (o *Player) Draw(screen *ebiten.Image)
- func (o *Player) ExtrapolateState(from *gametypes.PlayerState, to *gametypes.PlayerState, factor float64)
- func (o *Player) InterpolateState(from *gametypes.PlayerState, to *gametypes.PlayerState, factor float64)
- func (o *Player) ReconcileState(state *gametypes.PlayerState) error
- func (o *Player) Update() error
- type PreviousState
- type SortedZIndexObject
- type TextEffect
- type TextOverlayObject
Constants ¶
const (
// MaxPreviousStates is the maximum number of past states to keep
MaxPreviousStates = 60
)
Variables ¶
This section is empty.
Functions ¶
func DestroyTree ¶
func DestroyTree(object GameObject) error
func DrawTree ¶
func DrawTree(object GameObject, screen *ebiten.Image)
func InitTree ¶
func InitTree(object GameObject) error
func UpdateTree ¶
func UpdateTree(object GameObject) error
Types ¶
type BaseObject ¶
type BaseObject struct {
// contains filtered or unexported fields
}
BaseObject is a base implementation of GameObject. All game objects should embed this struct to inherit its methods.
func NewBaseObject ¶
func NewBaseObject(id string, opts *NewBaseObjectOpts) *BaseObject
func (*BaseObject) AddChild ¶
func (o *BaseObject) AddChild(id string, child GameObject) error
func (*BaseObject) Destroy ¶
func (o *BaseObject) Destroy() error
func (*BaseObject) Draw ¶
func (o *BaseObject) Draw(screen *ebiten.Image)
func (*BaseObject) GetChild ¶
func (o *BaseObject) GetChild(id string) GameObject
func (*BaseObject) GetChildren ¶
func (o *BaseObject) GetChildren() []GameObject
func (*BaseObject) GetID ¶
func (o *BaseObject) GetID() string
func (*BaseObject) GetZIndex ¶
func (o *BaseObject) GetZIndex() int
func (*BaseObject) Init ¶
func (o *BaseObject) Init() error
func (*BaseObject) RemoveChild ¶
func (o *BaseObject) RemoveChild(id string) error
func (*BaseObject) RemoveFromParent ¶
func (o *BaseObject) RemoveFromParent() error
func (*BaseObject) SetParent ¶
func (o *BaseObject) SetParent(parent GameObject)
func (*BaseObject) Update ¶
func (o *BaseObject) Update() error
type GameObject ¶
type GameObject interface { Lifecycle GetID() string GetChildren() []GameObject GetChild(id string) GameObject AddChild(id string, child GameObject) error RemoveChild(id string) error SetParent(parent GameObject) RemoveFromParent() error GetZIndex() int }
GameObject is the highest level interface for game related types. It provides methods for initializing, destroying, updating, and drawing game objects. It also provides methods for managing child game objects. All game objects should implement this interface. The BaseObject struct provides a base implementation of this interface.
func NewTextOverlayObject ¶
func NewTextOverlayObject(id string, text string) GameObject
type IndexedObjectList ¶
type IndexedObjectList struct {
// contains filtered or unexported fields
}
TODO: unit tests for IndexedObjectList
func NewIndexedObjectList ¶
func NewIndexedObjectList() *IndexedObjectList
func (*IndexedObjectList) Add ¶
func (l *IndexedObjectList) Add(id string, object GameObject)
func (*IndexedObjectList) Get ¶
func (l *IndexedObjectList) Get(id string) GameObject
func (*IndexedObjectList) GetAll ¶
func (l *IndexedObjectList) GetAll() []GameObject
func (*IndexedObjectList) Remove ¶
func (l *IndexedObjectList) Remove(id string)
type LevelObject ¶
type LevelObject struct { *BaseObject // contains filtered or unexported fields }
func NewLevelObject ¶
func NewLevelObject(id string, opts NewLevelObjectOptions) *LevelObject
func (*LevelObject) Draw ¶
func (o *LevelObject) Draw(screen *ebiten.Image)
type NPC ¶
type NPC struct { *BaseObject ID string // TODO: make this private with a getter and setter State *gametypes.NPCState // contains filtered or unexported fields }
func (*NPC) ExtrapolateState ¶
func (*NPC) InterpolateState ¶
type NewBaseObjectOpts ¶
type NewBaseObjectOpts struct {
ZIndex int
}
type NewLevelObjectOptions ¶
type NewLevelObjectOptions struct { // X is the x-coordinate of the level object. X float32 // Y is the y-coordinate of the level object. Y float32 // W is the width of the level object. W float32 // H is the height of the level object. H float32 // Color is the color of the level object. Color color.Color // ZIndex is the z-index of the level object. ZIndex int }
type NewTextEffectOptions ¶
type NewTextEffectOptions struct { // Text is the text to display. Text string // X is the x-coordinate of the text. X float64 // Y is the y-coordinate of the text. Y float64 // Color is the color of the text. Color color.Color // Scroll is a boolean value indicating whether the text should scroll. Scroll bool // TTL is the time to live in milliseconds. TTL int // ZIndex is the z-index of the text effect. ZIndex int }
type Player ¶
type Player struct { *BaseObject ID string // TODO: make this private with a getter and setter State *gametypes.PlayerState // contains filtered or unexported fields }
func NewPlayer ¶
func NewPlayer(id string, networkManager *network.NetworkManager, state *gametypes.PlayerState) (*Player, error)
func (*Player) ExtrapolateState ¶
func (o *Player) ExtrapolateState(from *gametypes.PlayerState, to *gametypes.PlayerState, factor float64)
func (*Player) InterpolateState ¶
func (o *Player) InterpolateState(from *gametypes.PlayerState, to *gametypes.PlayerState, factor float64)
func (*Player) ReconcileState ¶
func (o *Player) ReconcileState(state *gametypes.PlayerState) error
ReconcileState reconciles the player state with the server state by going back through the past client states and checking if it the client state for that timestamp matches the server state. If it doesn't match, the server state is applied and all of the past updates that are after the last processed timestamp are replayed.
type PreviousState ¶
type PreviousState struct { Timestamp int64 State *gametypes.PlayerState }
func (PreviousState) NeedsReconciliation ¶
func (ps PreviousState) NeedsReconciliation(other *gametypes.PlayerState) bool
NeedsReconciliation returns true if the previous state needs to be reconciled with an authoritative state
type SortedZIndexObject ¶
type SortedZIndexObject struct { *BaseObject // contains filtered or unexported fields }
SortedZIndexObject is a GameObject that maintains a sorted list of child objects by z-index.
func NewSortedZIndexObject ¶
func NewSortedZIndexObject(id string) *SortedZIndexObject
func (*SortedZIndexObject) AddChild ¶
func (o *SortedZIndexObject) AddChild(id string, child GameObject) error
func (*SortedZIndexObject) GetChildren ¶
func (o *SortedZIndexObject) GetChildren() []GameObject
func (*SortedZIndexObject) RemoveChild ¶
func (o *SortedZIndexObject) RemoveChild(id string) error
type TextEffect ¶
type TextEffect struct { *BaseObject ID string // contains filtered or unexported fields }
func NewTextEffect ¶
func NewTextEffect(id string, opts NewTextEffectOptions) *TextEffect
func (*TextEffect) Draw ¶
func (o *TextEffect) Draw(screen *ebiten.Image)
func (*TextEffect) Update ¶
func (o *TextEffect) Update() error
type TextOverlayObject ¶
type TextOverlayObject struct { *BaseObject // contains filtered or unexported fields }
func (*TextOverlayObject) Draw ¶
func (o *TextOverlayObject) Draw(screen *ebiten.Image)