Documentation
¶
Index ¶
- Constants
- type Entity
- func (entity *Entity) CheckDir(axis rune, distance, point int) bool
- func (entity *Entity) Draw()
- func (entity *Entity) GetEntity() *Entity
- func (entity *Entity) GetEntityGroup() *EntityGroup
- func (entity *Entity) GetGame() *Game
- func (entity *Entity) GetPosition() (int, int)
- func (entity *Entity) GetScene() *Scene
- func (entity *Entity) GetScreenPosition() (int, int)
- func (entity *Entity) GetSprite() rune
- func (entity *Entity) GetX() int
- func (entity *Entity) GetY() int
- func (entity *Entity) Init()
- func (entity *Entity) IsAbove(target IEntity) bool
- func (entity *Entity) IsBelow(target IEntity) bool
- func (entity *Entity) IsLeftOf(target IEntity) bool
- func (entity *Entity) IsRightOf(target IEntity) bool
- func (entity *Entity) Overlaps(target IEntity) bool
- func (entity *Entity) OverlapsPoint(x, y int) bool
- func (entity *Entity) SetColor(fg, bg tcell.Color)
- func (entity *Entity) SetEntityGroup(group *EntityGroup)
- func (entity *Entity) SetPosition(x, y int)
- func (entity *Entity) SetScene(scene *Scene)
- func (entity *Entity) SetSprite(sprite rune)
- func (entity *Entity) Update(delta float64)
- type EntityGroup
- func (eg *EntityGroup) Add(entity IEntity)
- func (eg *EntityGroup) Draw()
- func (eg *EntityGroup) GetDimensions() (int, int)
- func (eg *EntityGroup) GetEntities() []IEntity
- func (eg *EntityGroup) GetEntity() *Entity
- func (eg *EntityGroup) GetEntityAt(idx int) (*Entity, bool)
- func (eg *EntityGroup) Init()
- func (eg *EntityGroup) Remove(entity IEntity)
- func (eg *EntityGroup) SetEntities(entities []IEntity)
- func (eg *EntityGroup) SetHeight(height int)
- func (eg *EntityGroup) SetScene(scene *Scene)
- func (eg *EntityGroup) SetWidth(width int)
- func (eg *EntityGroup) Update(delta float64)
- type Game
- func (game *Game) CurrentScene() *Scene
- func (game *Game) ExitKey() tcell.Key
- func (game *Game) GetFPS() float64
- func (game *Game) GetLogger() *log.Logger
- func (game *Game) Init(scenes []IScene)
- func (game *Game) Input() *tcell.EventKey
- func (game *Game) NextScene()
- func (game *Game) PrevScene()
- func (game *Game) ScreenSize() (int, int)
- func (game *Game) SetExitKey(exitKey tcell.Key)
- func (game *Game) SetFPS(fps float64)
- func (game *Game) SetLogFileName(filename string)
- func (game *Game) SetScene(index int)
- func (game *Game) Start()
- type IEntity
- type IScene
- type IState
- type IStateManager
- type IText
- type Scene
- func (scene *Scene) Add(entity IEntity)
- func (scene *Scene) Draw()
- func (scene *Scene) Entities() []IEntity
- func (scene *Scene) Game() *Game
- func (scene *Scene) GetScene() *Scene
- func (scene *Scene) Init()
- func (scene *Scene) Remove(entity IEntity)
- func (scene *Scene) SetRedraw(redraw bool)
- func (scene *Scene) Setup()
- func (scene *Scene) Update(delta float64)
- type State
- type StateManager
- type Text
Constants ¶
const ( White = tcell.ColorWhite Black = tcell.ColorBlack Gray = tcell.ColorGray Red = tcell.ColorRed Pink = tcell.ColorPink DarkRed = tcell.ColorDarkRed Green = tcell.ColorGreen LightGreen = tcell.ColorLightGreen DarkGreen = tcell.ColorDarkGreen Blue = tcell.ColorBlue LightBlue = tcell.ColorLightBlue DarkBlue = tcell.ColorDarkBlue Orange = tcell.ColorOrange Purple = tcell.ColorPurple Yellow = tcell.ColorYellow )
Colors
const ( KeyEsc = tcell.KeyEscape KeyUp = tcell.KeyUp KeyDown = tcell.KeyDown KeyRight = tcell.KeyRight KeyLeft = tcell.KeyLeft KeyEnter = tcell.KeyEnter )
Event Keys
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entity ¶
type Entity struct {
// contains filtered or unexported fields
}
Entity represents a simple entity to be rendered to the game screen
func NewSpriteEntity ¶
NewSpriteEntity takes an x position, a y position, and a rune to be used as a visual representation, and creates an Entity colors: optional - foreground, background required if used
func (*Entity) CheckDir ¶
CheckDir checks if the entity is the specified distance away from the target point
func (*Entity) Draw ¶
func (entity *Entity) Draw()
Draw fires during scene.Draw and can be overridden. Be careful, overridding this means that you will need to handle rendering on your own.
func (*Entity) GetEntityGroup ¶ added in v1.0.1
func (entity *Entity) GetEntityGroup() *EntityGroup
GetEntityGroup gets the EntityGroup that the Entity belongs to.
Returns nil if not part of an EntityGroup
func (*Entity) GetPosition ¶
GetPosition returns the entity's current x and y values
func (*Entity) GetScreenPosition ¶ added in v1.0.1
GetScreenPosition Gets the screen x and y for the Entity. This will be different than GetPosition when the Entity is part of an EntityGroup
func (*Entity) Init ¶
func (entity *Entity) Init()
Init fires duting game.Init and can be overridden
func (*Entity) IsLeftOf ¶
IsLeftOf checks if the entity is directly to the left of the target entity
func (*Entity) IsRightOf ¶
IsRightOf checks if the entity is directly to the right of the target entity
func (*Entity) OverlapsPoint ¶
OverlapsPoint checks if the entity overlaps the specified screen point
func (*Entity) SetEntityGroup ¶ added in v1.0.1
func (entity *Entity) SetEntityGroup(group *EntityGroup)
SetEntityGroup sets the Entity's EntityGroup
func (*Entity) SetPosition ¶
SetPosition sets the entity's x and y position simultaneously
type EntityGroup ¶
type EntityGroup struct {
*Entity
// contains filtered or unexported fields
}
EntityGroup represents a set of entities that are grouped together within a specified boundary
func NewEntityGroup ¶
func NewEntityGroup(x, y, width, height int, entities []IEntity, colors ...tcell.Color) *EntityGroup
NewEntityGroup creates a new EntityGroup
func (*EntityGroup) Add ¶
func (eg *EntityGroup) Add(entity IEntity)
Add adds an Entity to an EntityGroup and flags the scene for redraw
func (*EntityGroup) Draw ¶
func (eg *EntityGroup) Draw()
Draw fires during scene.Draw and can be overridden
func (*EntityGroup) GetDimensions ¶
func (eg *EntityGroup) GetDimensions() (int, int)
GetDimensions returns the width and height of the EntityGroup
func (*EntityGroup) GetEntities ¶
func (eg *EntityGroup) GetEntities() []IEntity
GetEntities returns all entities contained in the group
func (*EntityGroup) GetEntity ¶
func (eg *EntityGroup) GetEntity() *Entity
GetEntity returns the entity used for positioning the group
func (*EntityGroup) GetEntityAt ¶
func (eg *EntityGroup) GetEntityAt(idx int) (*Entity, bool)
GetEntityAt returns the Entity at the specified index if idx is out of bounds ok returns false
func (*EntityGroup) Init ¶
func (eg *EntityGroup) Init()
Init fires during game.Init and can be overridden
func (*EntityGroup) Remove ¶
func (eg *EntityGroup) Remove(entity IEntity)
Remove removes an Entity from an EntityGroup and flags the scene for redraw. This maintains existing entity order.
func (*EntityGroup) SetEntities ¶
func (eg *EntityGroup) SetEntities(entities []IEntity)
SetEntities sets the EntityGroup's child entities and re-adds the entities to the parent's scene
func (*EntityGroup) SetHeight ¶
func (eg *EntityGroup) SetHeight(height int)
SetHeight sets the height of the EntityGroup
func (*EntityGroup) SetScene ¶
func (eg *EntityGroup) SetScene(scene *Scene)
SetScene adds the Entity to the given scene
func (*EntityGroup) SetWidth ¶
func (eg *EntityGroup) SetWidth(width int)
SetWidth sets the width of the EntityGroup
func (*EntityGroup) Update ¶
func (eg *EntityGroup) Update(delta float64)
Update fires after the scene update on each pass through the game loop, and can be overridden
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
Game is collection of properties used to abstract interaction with a tcell Screen
func (*Game) CurrentScene ¶
CurrentScene returns the game's current Scene
func (*Game) NextScene ¶
func (game *Game) NextScene()
NextScene increments the game sceneIndex if we are not already at the last scene
func (*Game) PrevScene ¶
func (game *Game) PrevScene()
PrevScene decrements the game sceneIndex if we are not already at the first scene
func (*Game) ScreenSize ¶
ScreenSize returns the screen size - (width, height)
func (*Game) SetExitKey ¶
SetExitKey sets the game's exit key
func (*Game) SetLogFileName ¶
SetLogFileName sets a custom log file name for logger output. Default value is 'terminus.log'
type IEntity ¶
type IEntity interface {
Init()
Update(delta float64)
Draw()
SetScene(scene *Scene)
GetEntity() *Entity
GetEntityGroup() *EntityGroup
SetEntityGroup(group *EntityGroup)
}
IEntity is the interface through which custom implementations of Entity can be created
func ToEntities ¶
ToEntities returns a slice of entities representing a given string of text
type IScene ¶
type IScene interface {
Setup()
Init()
Update(delta float64)
Draw()
Entities() []IEntity
GetScene() *Scene
}
IScene is the interface through which custom implementations of scene can be created
type IState ¶
type IState interface {
OnEnter()
OnExit()
Tick(delta float64)
}
IState is the interface through which custom implementations of State can be created
type IStateManager ¶
type IStateManager interface {
ChangeState(s *State)
BackToDefault()
BackToPrevious()
Update(delta float64)
}
IStateManager is the interface through which custom implementations of StateManager can be created
type Scene ¶
type Scene struct {
// contains filtered or unexported fields
}
Scene is an abstraction and expansion of the game's tcell Screen. It controls fg and bg color and offers several methods for custom implementations
func NewSceneCustom ¶
NewSceneCustom creates a new Scene with custom foreground and background colors
func (*Scene) Add ¶
Add adds the given entity to the scene. It should be noted that entities are initialized, updated, and drawn in the order that they have been added to the Scene
func (*Scene) Draw ¶
func (scene *Scene) Draw()
Draw is fired after the scene updates on each pass through the game loop. It can be overridden
func (*Scene) Init ¶
func (scene *Scene) Init()
Init fires during game.Init and when the scene is first entered. It can be overridden
func (*Scene) Remove ¶
Remove removes the given entity from the scene. This preserves previous entity order
func (*Scene) SetRedraw ¶
SetRedraw allows you to tell a specific scene to redraw (true) or not (false) on the next frame
type State ¶
type State struct {
}
State is an abstract struct meant to be extended for use with any scene or entity, and to be managed by a StateManager
func (*State) OnEnter ¶
func (state *State) OnEnter()
OnEnter is fired when the state is entered. This should be overridden
type StateManager ¶
type StateManager struct {
// contains filtered or unexported fields
}
StateManager manages IStates, it can be extended or overridden, but should provide a basic state machine for most general needs.
func NewStateManager ¶
func NewStateManager(defaultState IState) *StateManager
NewStateManager creates a new StateManager
func (*StateManager) BackToDefault ¶
func (sm *StateManager) BackToDefault()
BackToDefault resets the StateManager to the default State, passed at creation
func (*StateManager) BackToPrevious ¶
func (sm *StateManager) BackToPrevious()
BackToPrevious sets the StateManager's current State back to the previous State
func (*StateManager) ChangeState ¶
func (sm *StateManager) ChangeState(s IState)
ChangeState changes the current state of the StateManager
func (*StateManager) Update ¶
func (sm *StateManager) Update(delta float64)
Update should be called inside of the owner entity, or scene's Update method. This powers the StateManager
type Text ¶
type Text struct {
*EntityGroup
// contains filtered or unexported fields
}
Text is a type of EntityGroup which is used to render text to the game screen
func NewText ¶
NewText takes an x position, y position, and text value and creates a new Text Entity on the screen
func (*Text) GetEntityGroup ¶
func (t *Text) GetEntityGroup() *EntityGroup
GetEntityGroup gets the EntityGroup that contain the Text Entities
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
collision
command
|
|
|
entity_groups
command
|
|
|
hello_world
command
|
|
|
logging
command
|
|
|
moveable_entity
command
|
|
|
scenes
command
|
|
|
snake
command
|
|
|
states
command
|
|
|
text
command
|


