game

package
v0.0.0-...-7322cfd Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

components.go

systems.go

Index

Constants

View Source
const (
	ScreenWidth  = 480
	ScreenHeight = 640
)

Variables

This section is empty.

Functions

func DrawCircleOutline

func DrawCircleOutline(screen *ebiten.Image, centerX, centerY, radius float64, clr color.Color)

func GetComponent

func GetComponent[T any](entity *Entity, componentType ComponentType) (*T, bool)

Types

type Component

type Component interface {
	ComponentType() ComponentType
}

Component represents a generic component.

type ComponentType

type ComponentType int

ComponentType represents the type of a component.

const (
	Graphics ComponentType = iota
	Orbit
	Position
)

type Entity

type Entity struct {
	Tag        string
	Enabled    bool
	Components map[ComponentType]interface{}
}

Entity represents an entity in the ECS system.

func NewEntity

func NewEntity(tag string) *Entity

func (*Entity) AddComponent

func (e *Entity) AddComponent(component Component)

AddComponent adds a component to an entity.

type EntityManager

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

EntityManager manages entities in the ECS system.

func (*EntityManager) AddEntity

func (em *EntityManager) AddEntity(entity *Entity)

AddEntity adds a new entity to the ECS system.

func (*EntityManager) AddSystem

func (em *EntityManager) AddSystem(system System)

AddSystem adds a new system to the ECS.

func (*EntityManager) UpdateSystems

func (em *EntityManager) UpdateSystems()

UpdateSystems updates all systems in the ECS.

type Game

type Game struct {
	EntityManager *EntityManager
}

func NewGame

func NewGame() *Game

func (*Game) Draw

func (g *Game) Draw(screen *ebiten.Image)

func (*Game) Layout

func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int)

func (*Game) Update

func (g *Game) Update() error

type GraphicsComponent

type GraphicsComponent struct {
	Color color.Color
}

GraphicsComponent holds data related to rendering.

func (*GraphicsComponent) ComponentType

func (c *GraphicsComponent) ComponentType() ComponentType

type OrbitComponent

type OrbitComponent struct {
	Radius float64
	Speed  float64
	Angle  float64
	Parent *Entity
}

OrbitComponent contains data on the orbit of the planet.

func (*OrbitComponent) ComponentType

func (c *OrbitComponent) ComponentType() ComponentType

type OrbitalSystem

type OrbitalSystem struct{}

OrbitalSystem updates the position of the components based on the orbit data.

func (*OrbitalSystem) Update

func (os *OrbitalSystem) Update(entity *Entity)

Update implements the logic to update the orbital system.

type PositionComponent

type PositionComponent struct {
	X, Y float64
}

PositionComponent holds data on the current position of the planet.

func (*PositionComponent) ComponentType

func (c *PositionComponent) ComponentType() ComponentType

type RenderSystem

type RenderSystem struct{}

RenderSystem renders the screen.

func (*RenderSystem) Draw

func (rs *RenderSystem) Draw(screen *ebiten.Image, entity *Entity)

func (*RenderSystem) Update

func (rs *RenderSystem) Update(entity *Entity)

Update implements the logic to update the render system.

type System

type System interface {
	Update(*Entity)
}

System interface defines the generic update method.

Jump to

Keyboard shortcuts

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