ecs

package
v0.0.0-...-32108e7 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component interface {
	ComponentType() ComponentType
}

Component represents a component in the world, which will be attached to an entity. Component must return a particular ComponentType, which will be used to query the world for components of a particular type (instead of doing something like using reflection).

type ComponentType

type ComponentType int

ComponentType should be created for each component, so it can be used for querying for components in place of reflection.

type Entity

type Entity struct {
	ID         int
	EntityName string
	// contains filtered or unexported fields
}

Entity is a game entity.

func NewEntity

func NewEntity(entityName string) *Entity

NewEntity creates a new entity of a particular name. Names are purely informational and no uniqueness is enforced.

func (*Entity) AddComponent

func (e *Entity) AddComponent(c Component) *Entity

AddComponent adds a component to an entity.

func (*Entity) GetComponent

func (e *Entity) GetComponent(componentType ComponentType) Component

GetComponent returns the first component of a requested ComponentType belonging to the entity, or nil if no such components were found.

func (*Entity) GetComponents

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

GetComponents returns all components belonging to the entity.

type EntityAddedEvent

type EntityAddedEvent struct {
	Entity Entity
}

func (EntityAddedEvent) EventType

func (EntityAddedEvent) EventType() EventType

type EntityRemovedEvent

type EntityRemovedEvent struct {
	Entity Entity
}

func (EntityRemovedEvent) EventType

func (EntityRemovedEvent) EventType() EventType

type Event

type Event interface {
	EventType() EventType
}

Event is something emitted by or queried for by a system. Events have types and may extend with additional data that can be used by consuming systems.

type EventHandler

type EventHandler interface {
	DesiredEventType() EventType
	HandleEvent(Event, *World)
}

EventHandlers will be called to handle any fired events of the particular type they're interested in.

type EventType

type EventType int

EventType is the type of event -- we need this to avoid generics and reflection, though to be honest reflection might be good enough depending how fast it is.

const (
	EntityRemovedEventType EventType = iota + 100000
	EntityAddedEventType
)

type FindEntitiesWithComponentResult

type FindEntitiesWithComponentResult struct {
	Entity             Entity
	RequestedComponent Component
}

type FindEntitiesWithComponentsResult

type FindEntitiesWithComponentsResult struct {
	Entity              Entity
	RequestedComponents map[ComponentType]Component
}

type LogicSystem

type LogicSystem interface {
	Update(*World) error
}

LogicSystem is a system which applies logic. These are run before render systems.

type Point

type Point struct {
	X int
	Y int
}

type Rect

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

func NewRect

func NewRect(topLeft Point, bottomRight Point) (Rect, error)

func (Rect) Intersects

func (r Rect) Intersects(target Rect) bool

check if a rect overlaps another rect

type RenderSystem

type RenderSystem interface {
	Update(*World, *ebiten.Image) error
}

RenderSystem is a system which performs some kind of screen rendering. These are run last.

type World

type World struct {
	ScreenWidth  int
	ScreenHeight int
	// contains filtered or unexported fields
}

func NewWorld

func NewWorld(screenWidth int, screenHeight int) World

func (*World) AddEntity

func (w *World) AddEntity(e Entity) *World

AddEntity adds an entity to the world.

func (*World) AddEventHandler

func (w *World) AddEventHandler(e EventHandler)

func (*World) AddLogicSystem

func (w *World) AddLogicSystem(s LogicSystem)

func (*World) AddRenderSystem

func (w *World) AddRenderSystem(s RenderSystem)

func (World) FindEntitiesWithComponent

func (w World) FindEntitiesWithComponent(requestedComponent ComponentType) []FindEntitiesWithComponentResult

FindEntitiesWithComponent finds ALL entities that have the requested component attached.

func (World) FindEntitiesWithComponents

func (w World) FindEntitiesWithComponents(requestedComponents ...ComponentType) []FindEntitiesWithComponentsResult

FindEntitiesWithComponents finds ALL entities that have ALL the requested components attached.

func (*World) FireEvent

func (w *World) FireEvent(e Event)

func (*World) GetEntities

func (w *World) GetEntities() []Entity

GetEntities returns all entities in the world.

func (*World) RemoveEntity

func (w *World) RemoveEntity(idToRemove int)

RemoveEntity removes an entity from the world.

func (*World) Tick

func (w *World) Tick(screen *ebiten.Image) error

Tick runs the game world, logic then renderer. Please pass an image that's a buffer here, so it can be swapped to screen during render to ensure things keep running correctly.

Jump to

Keyboard shortcuts

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