Documentation
¶
Overview ¶
Package system provides the interface used in the game engine, messaging between systems, and some built in systems. List of built-in systems: collision, physics, render
Index ¶
- Constants
- func InvertVel(event Event)
- type BorderEvent
- type CollisionEvent
- type CollisionSystem
- type Event
- type EventHandler
- type PhysicsSystem
- type RenderSystem
- func (r *RenderSystem) GetCameraPosition() (int32, int32)
- func (r *RenderSystem) Init()
- func (r *RenderSystem) OffsetPosition(x, y int32) (int32, int32)
- func (r *RenderSystem) SetCamera(camera entity.Entitier)
- func (r *RenderSystem) Update()
- func (r *RenderSystem) UpdateAccumulator(accumulator uint32)
- func (r *RenderSystem) UpdateTime(time uint32)
- type Subject
- type Systemer
Constants ¶
const (
// UpdateTickLength is the length per update. The game will be updated at a steady 50 times per second,
UpdateTickLength = 1000 / ticksPerSecond
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BorderEvent ¶
BorderEvent has the entity (Ent) that transpassed the border and which border
type CollisionEvent ¶
CollisionEvent has the entity (Ent) that produced the collision and the entity that got collided (With)
func (*CollisionEvent) Name ¶
func (c *CollisionEvent) Name() string
Name returns the collision event name
type CollisionSystem ¶
CollisionSystem is the system responsible to handle collisions
func (*CollisionSystem) Init ¶
func (c *CollisionSystem) Init()
Init initializes this system. So far it does nothing.
func (*CollisionSystem) Update ¶
func (c *CollisionSystem) Update()
Update check for collision and notify observers
type Event ¶
type Event interface {
Name() string
}
Event adds data to the struct that implements event so you can communicate with the system
type EventHandler ¶
type EventHandler func(event Event)
EventHandler is the interface function which will handle the event Think as the Notify() func from the Observer
type PhysicsSystem ¶
PhysicsSystem is responsible to update the physics in the game.
func (*PhysicsSystem) Init ¶
func (p *PhysicsSystem) Init()
Init initializes this system. So far it does nothing.
func (*PhysicsSystem) Update ¶
func (p *PhysicsSystem) Update()
Update change the position and velocity accordingly. We are using Semi-implicit Euler
type RenderSystem ¶
type RenderSystem struct { EntityManager *entity.Manager Window *sdl.Window Renderer *sdl.Renderer BgColor sdl.Color Camera entity.Entitier // entity that have the camera component Name string // contains filtered or unexported fields }
RenderSystem is probably one of the most important system. It is responsible to render (draw) the entities
func (*RenderSystem) GetCameraPosition ¶
func (r *RenderSystem) GetCameraPosition() (int32, int32)
GetCameraPosition gets the camera position
func (*RenderSystem) Init ¶
func (r *RenderSystem) Init()
Init initializes the render system using the current window
func (*RenderSystem) OffsetPosition ¶
func (r *RenderSystem) OffsetPosition(x, y int32) (int32, int32)
OffsetPosition changes the cartesian position according to the camera
func (*RenderSystem) SetCamera ¶
func (r *RenderSystem) SetCamera(camera entity.Entitier)
SetCamera sets the camera which controls what will be rendered
func (*RenderSystem) Update ¶
func (r *RenderSystem) Update()
Update will draw the entities accordingly to their position. it can render animated sprites, fonts or geometry
func (*RenderSystem) UpdateAccumulator ¶
func (r *RenderSystem) UpdateAccumulator(accumulator uint32)
UpdateAccumulator update the accumulator time.
func (*RenderSystem) UpdateTime ¶
func (r *RenderSystem) UpdateTime(time uint32)
UpdateTime update the time
type Subject ¶
type Subject struct {
// contains filtered or unexported fields
}
Subject holds the listerners and their handlers. An event can have multiple handlers.
func (*Subject) AddHandler ¶
func (s *Subject) AddHandler(eventName string, handler EventHandler)
AddHandler adds an event handler
func (*Subject) NotifyEvent ¶
NotifyEvent executes all event handlers for a specific event