sk

package module
v0.0.0-...-ece690c Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

README

SKALD ENGINE

This is a 2D ECS game engine based on Ebitenengine for Golang. I created Skald for personal usage, but I will keep it open hoping that would be useful for other people.

Features:

  • Performatic ECS: although my goal is not performance, the ECS implementation is quite lightweight and can handle dozens of thousands individual entities at same time.
  • Command-Based Input System: use commands to abstract the actions of the game, using multiple devices at same time for complex combinations. Change the shortcuts in realtime as needed.
  • Asset Loading: load assets asynchrounously.

In development:

  • Camera
  • Integrated physics
  • Integrated simple collisions
  • Plugin systems
  • Tilemaps
  • Texture Atlas
  • Asset pipeline
  • UI
  • Particle System
  • Event System

Roadmap:

  1. Example: pong Game

    The idea is to create a single game to feel the development flow of the engine and work on real necessities, moreover, working as documentation and showcase.

    Dependencies:

    • input system
    • simple collisions
    • text
    • mobile build
    • web build
    • PC build

Documentation

Index

Constants

View Source
const PIXELS_PER_UNIT float64 = 100
View Source
const SCREEN_HEIGHT float64 = 768 / PIXELS_PER_UNIT
View Source
const SCREEN_WIDTH float64 = 1024 / PIXELS_PER_UNIT
View Source
const WINDOW_HEIGHT int = 768
View Source
const WINDOW_WIDTH int = 1024

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetServer

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

func NewAssetServer

func NewAssetServer() *AssetServer

func (*AssetServer) Load

func (as *AssetServer) Load(path string) *Handler

func (*AssetServer) LoadAsync

func (as *AssetServer) LoadAsync(path string) *Handler

func (*AssetServer) Unload

func (as *AssetServer) Unload(path string)

type ComponentDefinition

type ComponentDefinition[T any] struct {
	OnCreated  func(*T)
	OnAttached func(*T, *EntityInstance)
	OnDetached func(*T, *EntityInstance)
	// contains filtered or unexported fields
}

func NewComponent

func NewComponent[T any]() *ComponentDefinition[T]

func NewComponentWithOptions

func NewComponentWithOptions[T any](options ComponentOptions[T]) *ComponentDefinition[T]

func (*ComponentDefinition[T]) Get

func (c *ComponentDefinition[T]) Get(entity *EntityInstance) *T

func (*ComponentDefinition[T]) Id

func (c *ComponentDefinition[T]) Id() ID

func (*ComponentDefinition[T]) In

func (c *ComponentDefinition[T]) In(entity *EntityInstance) bool

func (*ComponentDefinition[T]) Name

func (c *ComponentDefinition[T]) Name() string

func (*ComponentDefinition[T]) New

func (c *ComponentDefinition[T]) New() any

func (*ComponentDefinition[T]) Type

func (c *ComponentDefinition[T]) Type() reflect.Type

type ComponentOptions

type ComponentOptions[T any] struct {
	Dependencies []IComponent
	OnCreated    func(*T)
	OnAttached   func(*T, *EntityInstance)
	OnDetached   func(*T, *EntityInstance)
}

type Components

type Components []IComponent

type Debug

type Debug struct {
	Enabled bool
	// contains filtered or unexported fields
}

func NewDebug

func NewDebug() *Debug

func (*Debug) AfterDraw

func (d *Debug) AfterDraw(fn func(*ebiten.Image))

func (*Debug) BeforeDraw

func (d *Debug) BeforeDraw(fn func(*ebiten.Image))

type EntityDefinition

type EntityDefinition struct {
	OnSpawned   func(*EntityInstance)
	OnDespawned func(*EntityInstance)
	// contains filtered or unexported fields
}

func NewEntity

func NewEntity(components ...IComponent) *EntityDefinition

func NewEntityWithOptions

func NewEntityWithOptions(options EntityOptions) *EntityDefinition

func (*EntityDefinition) AddComponent

func (e *EntityDefinition) AddComponent(c IComponent) bool

func (*EntityDefinition) Components

func (e *EntityDefinition) Components() []IComponent

func (*EntityDefinition) HasComponent

func (e *EntityDefinition) HasComponent(c IComponent) bool

func (*EntityDefinition) Id

func (e *EntityDefinition) Id() ID

func (*EntityDefinition) New

func (e *EntityDefinition) New() *EntityInstance

func (*EntityDefinition) RemoveComponent

func (e *EntityDefinition) RemoveComponent(c IComponent)

type EntityInstance

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

----------------------------------------------------------------------------- ENTITY INSTANCE -----------------------------------------------------------------------------

func (*EntityInstance) AddComponent

func (e *EntityInstance) AddComponent(c IComponent) bool

func (*EntityInstance) Definition

func (e *EntityInstance) Definition() *EntityDefinition

func (*EntityInstance) GetComponent

func (e *EntityInstance) GetComponent(id ID) any

func (*EntityInstance) HasComponent

func (e *EntityInstance) HasComponent(id ID) bool

func (*EntityInstance) Id

func (e *EntityInstance) Id() ID

func (*EntityInstance) RemoveComponent

func (e *EntityInstance) RemoveComponent(c IComponent)

type EntityOptions

type EntityOptions struct {
	Components  []IComponent
	OnSpawned   func(*EntityInstance)
	OnDespawned func(*EntityInstance)
}

type Game

type Game struct {
	World    *World
	Assets   *AssetServer
	Renderer *Renderer
	Inputs   *inputs.System
	Window   *Window
	Screen   *Screen
	Timer    *Timer
	Debug    *Debug
	// contains filtered or unexported fields
}

func NewGame

func NewGame() *Game

func (*Game) AddService

func (g *Game) AddService(service IService)

func (*Game) AddSystem

func (g *Game) AddSystem(system *SystemDefinition, options ...*SystemOptions)

func (*Game) Play

func (g *Game) Play()

func (*Game) RemoveService

func (g *Game) RemoveService(service IService)

func (*Game) RemoveSystem

func (g *Game) RemoveSystem(system *SystemDefinition)

type Handler

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

func NewHandler

func NewHandler(id string) *Handler

func (*Handler) AsRaw

func (h *Handler) AsRaw() []byte

func (*Handler) AsString

func (h *Handler) AsString() string

func (*Handler) AsTexture

func (h *Handler) AsTexture() *Texture

func (*Handler) Error

func (h *Handler) Error() error

func (*Handler) Id

func (h *Handler) Id() string

func (*Handler) IsReady

func (h *Handler) IsReady() bool

func (*Handler) SetData

func (h *Handler) SetData(data []byte)

func (*Handler) SetError

func (h *Handler) SetError(err error)

type IComponent

type IComponent interface {
	Id() ID
	Name() string
	Type() reflect.Type
	New() any
	// contains filtered or unexported methods
}

type ID

type ID uint64

type IPlugin

type IPlugin interface {
	Register(g *Game)
	Unregister(g *Game)
}

type IQuery

type IQuery interface {
	Id() ID
	Name() string
	// contains filtered or unexported methods
}

type IService

type IService interface {
	Id() ID
	Name() string
	Type() reflect.Type
	New() any
}

type Plugin

type Plugin struct {
}

type QueryDefinition

type QueryDefinition[T any] struct {
	// contains filtered or unexported fields
}

----------------------------------------------------------------------------- QUERY DEFINITION -----------------------------------------------------------------------------

func NewQuery

func NewQuery[T any]() *QueryDefinition[T]

func (*QueryDefinition[T]) Id

func (c *QueryDefinition[T]) Id() ID

func (*QueryDefinition[T]) Name

func (c *QueryDefinition[T]) Name() string

func (*QueryDefinition[T]) Query

func (c *QueryDefinition[T]) Query() []*T

type Rect

type Rect struct {
	Position Vec2
	Size     Vec2
}

func (Rect) Bottom

func (r Rect) Bottom() float64

func (Rect) Center

func (r Rect) Center() Vec2

func (Rect) Contains

func (r Rect) Contains(v Vec2) bool

func (Rect) Expand

func (r Rect) Expand(v Vec2) Rect

func (Rect) ExpandS

func (r Rect) ExpandS(s float64) Rect

func (Rect) Intersect

func (r Rect) Intersect(r2 Rect) Rect

func (Rect) Intersects

func (r Rect) Intersects(r2 Rect) bool

func (Rect) Left

func (r Rect) Left() float64

func (Rect) Max

func (r Rect) Max() Vec2

func (Rect) Min

func (r Rect) Min() Vec2

func (Rect) Right

func (r Rect) Right() float64

func (Rect) Shrink

func (r Rect) Shrink(v Vec2) Rect

func (Rect) ShrinkS

func (r Rect) ShrinkS(s float64) Rect

func (Rect) Top

func (r Rect) Top() float64

func (Rect) Union

func (r Rect) Union(r2 Rect) Rect

type RenderLayer

type RenderLayer []*renderItem

func (RenderLayer) Len

func (q RenderLayer) Len() int

func (RenderLayer) Less

func (q RenderLayer) Less(i, j int) bool

func (*RenderLayer) Pop

func (q *RenderLayer) Pop() any

func (*RenderLayer) Push

func (q *RenderLayer) Push(x any)

func (RenderLayer) Swap

func (q RenderLayer) Swap(i, j int)

type Renderer

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

func NewRenderer

func NewRenderer() *Renderer

func (*Renderer) AddLayer

func (r *Renderer) AddLayer() uint

func (*Renderer) Clear

func (r *Renderer) Clear()

func (*Renderer) Draw

func (r *Renderer) Draw(screen *ebiten.Image, cameraOps *ebiten.DrawImageOptions)

func (*Renderer) Queue

func (r *Renderer) Queue(layer uint, zindex int, image *ebiten.Image, op *ebiten.DrawImageOptions)

type Screen

type Screen struct {
	Surface       *ebiten.Image
	PixelsPerUnit float64
	// contains filtered or unexported fields
}

func NewScreen

func NewScreen() *Screen

func (*Screen) Clear

func (s *Screen) Clear()

func (*Screen) GetColor

func (s *Screen) GetColor() color.Color

func (*Screen) GetPosition

func (s *Screen) GetPosition() Vec2

func (*Screen) GetRotation

func (s *Screen) GetRotation() float64

func (*Screen) GetSize

func (s *Screen) GetSize() Vec2

func (*Screen) GetZoom

func (s *Screen) GetZoom() float64

func (*Screen) GetZoomLimits

func (s *Screen) GetZoomLimits() (float64, float64)

func (*Screen) Move

func (s *Screen) Move(x, y float64)

func (*Screen) Rotate

func (s *Screen) Rotate(rotation float64)

func (*Screen) ScreenPositionToWorld

func (s *Screen) ScreenPositionToWorld(x, y int) (float64, float64)

func (*Screen) SetColor

func (s *Screen) SetColor(color color.Color)

func (*Screen) SetPosition

func (s *Screen) SetPosition(x, y float64)

func (*Screen) SetRotation

func (s *Screen) SetRotation(rotation float64)

func (*Screen) SetSize

func (s *Screen) SetSize(w, h float64)

func (*Screen) SetZoom

func (s *Screen) SetZoom(zoom float64)

func (*Screen) SetZoomLimits

func (s *Screen) SetZoomLimits(min, max float64)

func (*Screen) WorldPositionToScreen

func (s *Screen) WorldPositionToScreen(x, y float64) (int, int)

func (*Screen) Zoom

func (s *Screen) Zoom(zoom float64)

type ServiceDefinition

type ServiceDefinition[T any] struct {
	OnCreated func(*T)
	// contains filtered or unexported fields
}

func NewService

func NewService[T any](default_ ...T) *ServiceDefinition[T]

func (*ServiceDefinition[T]) Get

func (s *ServiceDefinition[T]) Get(g *Game) *T

func (*ServiceDefinition[T]) Id

func (s *ServiceDefinition[T]) Id() ID

func (*ServiceDefinition[T]) In

func (s *ServiceDefinition[T]) In(g *Game) bool

func (*ServiceDefinition[T]) Name

func (s *ServiceDefinition[T]) Name() string

func (*ServiceDefinition[T]) New

func (s *ServiceDefinition[T]) New() any

func (*ServiceDefinition[T]) Type

func (s *ServiceDefinition[T]) Type() reflect.Type

type SystemDefinition

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

func NewSystem

func NewSystem(fn SystemFn, queries ...IQuery) *SystemDefinition

func (*SystemDefinition) Id

func (s *SystemDefinition) Id() ID

type SystemFn

type SystemFn func(*Game) error

type SystemOptions

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

----------------------------------------------------------------------------- SYSTEM OPTIONS -----------------------------------------------------------------------------

func NewSystemOptions

func NewSystemOptions() *SystemOptions

func (*SystemOptions) Once

func (sb *SystemOptions) Once() *SystemOptions

func (*SystemOptions) Priority

func (sb *SystemOptions) Priority(priority int) *SystemOptions

type Texture

type Texture struct {
	Image *ebiten.Image
}

func NewEmptyTexture

func NewEmptyTexture(width, height int) *Texture

func NewTextureFromBytes

func NewTextureFromBytes(data []byte) (*Texture, error)

func NewTextureFromImage

func NewTextureFromImage(image *ebiten.Image) *Texture

type Timer

type Timer struct {
	DeltaTime float64
	// contains filtered or unexported fields
}

func NewTimer

func NewTimer() *Timer

func (*Timer) Attach

func (t *Timer) Attach(other *Timer)

func (*Timer) Detach

func (t *Timer) Detach(other *Timer)

func (*Timer) GetScale

func (t *Timer) GetScale() float64

func (*Timer) IsPaused

func (t *Timer) IsPaused() bool

func (*Timer) Pause

func (t *Timer) Pause()

func (*Timer) Resume

func (t *Timer) Resume()

func (*Timer) SetScale

func (t *Timer) SetScale(scale float64)

func (*Timer) Update

func (t *Timer) Update(dt float64)

Delta time in seconds

type Vec2

type Vec2 struct {
	X, Y float64
}

func (Vec2) Abs

func (v Vec2) Abs() Vec2

func (Vec2) Add

func (v Vec2) Add(v2 Vec2) Vec2

func (Vec2) AddS

func (v Vec2) AddS(s float64) Vec2

func (Vec2) Angle

func (v Vec2) Angle() float64

func (Vec2) Ceil

func (v Vec2) Ceil() Vec2

func (Vec2) Clamp

func (v Vec2) Clamp(min, max Vec2) Vec2

func (Vec2) ClampS

func (v Vec2) ClampS(min, max float64) Vec2

func (Vec2) Cross

func (v Vec2) Cross(v2 Vec2) float64

func (Vec2) Distance

func (v Vec2) Distance(v2 Vec2) float64

func (Vec2) Div

func (v Vec2) Div(v2 Vec2) Vec2

func (Vec2) DivS

func (v Vec2) DivS(s float64) Vec2

func (Vec2) Dot

func (v Vec2) Dot(v2 Vec2) float64

func (Vec2) Equal

func (v Vec2) Equal(v2 Vec2) bool

func (Vec2) Floor

func (v Vec2) Floor() Vec2

func (Vec2) Length

func (v Vec2) Length() float64

func (Vec2) LengthSqr

func (v Vec2) LengthSqr() float64

func (Vec2) Lerp

func (v Vec2) Lerp(v2 Vec2, t float64) Vec2

func (Vec2) Max

func (v Vec2) Max(v2 Vec2) Vec2

func (Vec2) Min

func (v Vec2) Min(v2 Vec2) Vec2

func (Vec2) Mul

func (v Vec2) Mul(v2 Vec2) Vec2

func (Vec2) MulS

func (v Vec2) MulS(s float64) Vec2

func (Vec2) Normalized

func (v Vec2) Normalized() Vec2

func (Vec2) Rotate

func (v Vec2) Rotate(angle float64) Vec2

func (Vec2) Round

func (v Vec2) Round() Vec2

func (Vec2) Sub

func (v Vec2) Sub(v2 Vec2) Vec2

func (Vec2) SubS

func (v Vec2) SubS(s float64) Vec2

type Window

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

func NewWindow

func NewWindow() *Window

func (*Window) Close

func (win *Window) Close()

func (*Window) GetCursorShape

func (win *Window) GetCursorShape() ebiten.CursorShapeType

func (*Window) GetFPS

func (win *Window) GetFPS() float64

func (*Window) GetMonitorSize

func (win *Window) GetMonitorSize() (int, int)

func (*Window) GetPosition

func (win *Window) GetPosition() (int, int)

func (*Window) GetSize

func (win *Window) GetSize() (int, int)

func (*Window) GetSizeLimits

func (win *Window) GetSizeLimits() (minW, minH, maxW, maxH int)

func (*Window) GetTPS

func (win *Window) GetTPS() float64

func (*Window) GetTitle

func (win *Window) GetTitle() string

func (*Window) IsCursorCaptured

func (win *Window) IsCursorCaptured() bool

func (*Window) IsCursorVisible

func (win *Window) IsCursorVisible() bool

func (*Window) IsDecorated

func (win *Window) IsDecorated() bool

func (*Window) IsFloating

func (win *Window) IsFloating() bool

func (*Window) IsFocused

func (win *Window) IsFocused() bool

func (*Window) IsFullscreen

func (win *Window) IsFullscreen() bool

func (*Window) IsMaximized

func (win *Window) IsMaximized() bool

func (*Window) IsMinimized

func (win *Window) IsMinimized() bool

func (*Window) IsMousePassthrough

func (win *Window) IsMousePassthrough() bool

func (*Window) IsResizable

func (win *Window) IsResizable() bool

func (*Window) IsRunnableOnUnfocused

func (win *Window) IsRunnableOnUnfocused() bool

func (*Window) IsVsync

func (win *Window) IsVsync() bool

func (*Window) Maximize

func (win *Window) Maximize()

func (*Window) Minimize

func (win *Window) Minimize()

func (*Window) Restore

func (win *Window) Restore()

func (*Window) SetCursorCaptured

func (win *Window) SetCursorCaptured(captured bool)

func (*Window) SetCursorShape

func (win *Window) SetCursorShape(shape ebiten.CursorShapeType)

func (*Window) SetCursorVisible

func (win *Window) SetCursorVisible(visible bool)

func (*Window) SetDecorated

func (win *Window) SetDecorated(decorated bool)

func (*Window) SetFloating

func (win *Window) SetFloating(floating bool)

func (*Window) SetFullscreen

func (win *Window) SetFullscreen(fullscreen bool)

func (*Window) SetMousePassthrough

func (win *Window) SetMousePassthrough(passthrough bool)

func (*Window) SetPosition

func (win *Window) SetPosition(x, y int)

func (*Window) SetResizable

func (win *Window) SetResizable(resizable bool)

func (*Window) SetRunnableOnUnfocused

func (win *Window) SetRunnableOnUnfocused(runnable bool)

func (*Window) SetSize

func (win *Window) SetSize(w, h int)

func (*Window) SetSizeLimits

func (win *Window) SetSizeLimits(minW, minH, maxW, maxH int)

func (*Window) SetTPS

func (win *Window) SetTPS(tps int)

func (*Window) SetTitle

func (win *Window) SetTitle(title string)

func (*Window) SetVsync

func (win *Window) SetVsync(vsync bool)

type World

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

----------------------------------------------------------------------------- WORLD -----------------------------------------------------------------------------

func NewWorld

func NewWorld() *World

func (*World) AddQuery

func (w *World) AddQuery(query IQuery)

func (*World) Despawn

func (w *World) Despawn(entity *EntityInstance)

func (*World) Entities

func (w *World) Entities() []*EntityInstance

func (*World) RemoveQuery

func (w *World) RemoveQuery(query IQuery)

func (*World) Spawn

func (w *World) Spawn(def *EntityDefinition, fn ...func(*EntityInstance))

func (*World) SpawnMulti

func (w *World) SpawnMulti(n int, def *EntityDefinition, fn ...func(*EntityInstance))

Directories

Path Synopsis
feats

Jump to

Keyboard shortcuts

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