Documentation ¶
Overview ¶
Package entity provides the entity manager, spritesheet and font structure, and some built-in components. We have here two pillars of the Entity Component System architecture.
Index ¶
- Constants
- type AnimationComponent
- type CameraComponent
- type CollisionComponent
- type Component
- type Entitier
- type Entity
- type FontComponent
- type GridComponent
- type MFont
- type MText
- type Manager
- func (m *Manager) Create(etype string) *Entity
- func (m *Manager) Delete(id uint16) bool
- func (m *Manager) Get(id uint16) *Entity
- func (m *Manager) GetAll() []*Entity
- func (m *Manager) IterAvailable(start int) func() (*Entity, int)
- func (m *Manager) IterFilter(components []Component, start int) func() (*Entity, int)
- type PhysicsComponent
- type PositionComponent
- type RectangleComponent
- type RenderComponent
- type Spritesheet
Constants ¶
const ( // RTSprite is the RenderType constant representing sprites RTSprite = iota // RTFont is the RenderType constant representing fonts RTFont // RTGeometry is the RenderType constant representing geometries RTGeometry // RTGrid is the RenderType constant representing grids RTGrid )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnimationComponent ¶
type AnimationComponent struct { InitialPos sdl.Point // frame reference AnimationSpeed uint8 //animations per second PreviousTime uint32 //last animation time Current int Frames int // total sprites RowLength int // number of sprites per row SpriteMap map[string]int }
AnimationComponent is responsible for animate the entity
type CameraComponent ¶
CameraComponent is responsible to render only the content of the viewport
type CollisionComponent ¶
type CollisionComponent struct { // CollisionAreas contains the rectangles that will be checked. // The position is relative to the upper left corner of the renderer CollisionAreas []sdl.Rect }
CollisionComponent makes the entity notify if it hits something else TODO: Add other type of information such as Shape, Density, Friction etc...
type Entitier ¶
type Entitier interface { GetID() uint16 GetComponents() map[string]Component AddComponent(Component) DelComponent(Component) GetComponent(Component) Component }
Entitier has all the behaviours entities should have
type Entity ¶
type Entity struct {
// contains filtered or unexported fields
}
Entity is the struct that contains the components. Right now the id's are not being used
func (*Entity) AddComponent ¶
AddComponent adds a component to the component map of the entity
func (*Entity) DelComponent ¶
DelComponent removes the given component of the entity
func (*Entity) GetComponent ¶
GetComponent returns the given component of the entity
func (*Entity) GetComponents ¶
GetComponents returns a list of all the components of the entity
type FontComponent ¶
FontComponent holds the font and text information
type GridComponent ¶
GridComponent is used for debugging
type MText ¶
MText is the struct that has the rendering information
func (*MText) GenerateRenderComponent ¶
func (t *MText) GenerateRenderComponent() *RenderComponent
GenerateRenderComponent generate the render component used to draw the text
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is the struct responsible to manage the entities in your game
func (*Manager) IterAvailable ¶
IterAvailable creates an iterator for the available entities
type PhysicsComponent ¶
type PhysicsComponent struct { FuturePos *math.FPoint // TODO: move this to PositionComponent // velocity Vel *math.FPoint // acceleration Acc *math.FPoint }
PhysicsComponent is responsible for some of the physics
type PositionComponent ¶
PositionComponent is responsible for the position of the entity
type RectangleComponent ¶
RectangleComponent has the information to draw a rectangle
type RenderComponent ¶
type RenderComponent struct { Texture *sdl.Texture Crop *sdl.Rect // part of the texture which will be displayed Angle float64 Center *sdl.Point Flip sdl.RendererFlip RenderType int }
RenderComponent is responsible for the rendering of the entity
type Spritesheet ¶
Spritesheet has the information about the image
func (*Spritesheet) Init ¶
func (s *Spritesheet) Init()
Init initialize the spritesheet. It generates the texture of that image
func (*Spritesheet) LoadSprite ¶
func (s *Spritesheet) LoadSprite(crop *sdl.Rect) RenderComponent
LoadSprite add the information of the sprite to the render component