system

package
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: 6 Imported by: 5

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

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

func InvertVel

func InvertVel(event Event)

InvertVel invert the vel of the collided object.

Types

type BorderEvent

type BorderEvent struct {
	Ent  *entity.Entity
	Side string
}

BorderEvent has the entity (Ent) that transpassed the border and which border

func (*BorderEvent) Name

func (b *BorderEvent) Name() string

Name returns the border event name

type CollisionEvent

type CollisionEvent struct {
	Ent  *entity.Entity
	With *entity.Entity
}

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

type CollisionSystem struct {
	EntityManager *entity.Manager
	Name          string
	Subject
}

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

type PhysicsSystem struct {
	EntityManager *entity.Manager
	Name          string
	Subject
}

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) ClearEvents

func (s *Subject) ClearEvents()

ClearEvents clear all events

func (*Subject) NotifyEvent

func (s *Subject) NotifyEvent(event Event)

NotifyEvent executes all event handlers for a specific event

func (*Subject) RemHandler

func (s *Subject) RemHandler()

RemHandler removes an event handler

type Systemer

type Systemer interface {
	// Update will be run in the game loop whenever possible
	Update()
	// Init is used to do whatever the system should do before being updated
	Init()
}

Systemer is the interface containing behaviours that every system should have

Jump to

Keyboard shortcuts

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