entity

package
Version: v0.0.0-...-b13d3a1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2018 License: Zlib Imports: 7 Imported by: 5

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

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

type CameraComponent struct {
	ViewportSize sdl.Point
	WorldSize    sdl.Point
	IsActive     bool
}

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 Component

type Component interface{}

Component is the abstract type for each component

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

func (e *Entity) AddComponent(c Component)

AddComponent adds a component to the component map of the entity

func (*Entity) DelComponent

func (e *Entity) DelComponent(c Component)

DelComponent removes the given component of the entity

func (*Entity) GetComponent

func (e *Entity) GetComponent(component Component) Component

GetComponent returns the given component of the entity

func (*Entity) GetComponents

func (e *Entity) GetComponents() map[string]Component

GetComponents returns a list of all the components of the entity

func (*Entity) GetID

func (e *Entity) GetID() uint16

GetID returns the id of the entity

func (*Entity) GetType

func (e *Entity) GetType() string

GetType returns the type of the entity

type FontComponent

type FontComponent struct {
	Font     *ttf.Font
	Text     string
	Modified bool
	Color    *sdl.Color
}

FontComponent holds the font and text information

type GridComponent

type GridComponent struct {
	Size  *sdl.Point
	Color *sdl.Color
}

GridComponent is used for debugging

type MFont

type MFont struct {
	File string
	Size uint8
	// contains filtered or unexported fields
}

MFont is the font struct that has the file, size and font pointer

func (*MFont) Close

func (f *MFont) Close()

Close closes the font

func (*MFont) Open

func (f *MFont) Open() *ttf.Font

Open opens the font

type MText

type MText struct {
	Text  string
	Color *sdl.Color
	// contains filtered or unexported fields
}

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

func (*MText) Init

func (t *MText) Init(renderer *sdl.Renderer, font *ttf.Font)

Init initialize the MText struct

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is the struct responsible to manage the entities in your game

func (*Manager) Create

func (m *Manager) Create(etype string) *Entity

Create creates a new entity and returns it

func (*Manager) Delete

func (m *Manager) Delete(id uint16) bool

Delete removes an entity associated to the given id

func (*Manager) Get

func (m *Manager) Get(id uint16) *Entity

Get gets an entity from the array of entities given an id

func (*Manager) GetAll

func (m *Manager) GetAll() []*Entity

GetAll gets all entities

func (*Manager) IterAvailable

func (m *Manager) IterAvailable(start int) func() (*Entity, int)

IterAvailable creates an iterator for the available entities

func (*Manager) IterFilter

func (m *Manager) IterFilter(components []Component, start int) func() (*Entity, int)

IterFilter creates an iterator with the available entities and its index that contain the given components

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

type PositionComponent struct {
	Pos *sdl.Point
	Z   float32
}

PositionComponent is responsible for the position of the entity

type RectangleComponent

type RectangleComponent struct {
	Size   *sdl.Point
	Color  *sdl.Color
	Filled bool
}

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

type Spritesheet struct {
	// renderer
	Renderer *sdl.Renderer
	Texture  *sdl.Texture
	Filepath string
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL