pearl

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2021 License: MIT Imports: 11 Imported by: 0

README

Pearl

A Lightweight Cross-Platform ECSS Framework for Ebiten and Go! Trello: https://trello.com/b/bprGiIi1/pearl

Installation

go get github.com/eboatwright/pearl@vX.X.X

Look through releases tab, and replace X.X.X with the latest one that's flagged Stable 😄
Also, check through https://ebiten.org/documents/install.html and find the dependencies that you need for your Operating System. 😄

Documentation

API Reference: pkg.go.dev/github.com/eboatwright/pearl
Examples: Check examples folder in repositody 😄
Tutorials and Wiki page soon! 😄

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Shorthand for 0, 0
	VZERO = Vector2{0, 0}
	// Shorthand for 1, 1
	VONE = Vector2{1, 1}
	// Shorthand for 0, -1
	VUP = Vector2{0, -1}
	// Shorthand for 0, 1
	VDOWN = Vector2{0, 1}
	// Shorthand for -1, 0
	VLEFT = Vector2{-1, 0}
	// Shorthand for 1, 0
	VRIGHT = Vector2{1, 0}
)

Functions

func EntityMatchesSystem

func EntityMatchesSystem(entity *Entity, system ISystem) bool

Returns a bool on whether or not an entity meets the requirements of the system

func GetInputAxis

func GetInputAxis(negative, positive []ebiten.Key) int

Returns an integer and is -1 if one of the negative keys specified is pressed, and returns 1 if any of the positive keys specified is pressed. Returns 0 if both or none are pressed.

func KeyJustPressed

func KeyJustPressed(key ebiten.Key) bool

Returns true or false if key was just pressed this frame

func KeyJustReleased

func KeyJustReleased(key ebiten.Key) bool

Returns true or false if key was just released this frame

func KeyPressed

func KeyPressed(key ebiten.Key) bool

Returns true or false when key is being held

func LoadImage

func LoadImage(path string) *ebiten.Image

A helper function for getting an Ebiten image

func LoadScene

func LoadScene(scene *Scene)

Makes scene specified the current scene

func MouseButtonJustPressed

func MouseButtonJustPressed(button ebiten.MouseButton) bool

Returns true or false if mouse button was just pressed this frame

func MouseButtonJustReleased

func MouseButtonJustReleased(button ebiten.MouseButton) bool

Returns true or false if mouse button was just released this frame

func MouseButtonPressed

func MouseButtonPressed(button ebiten.MouseButton) bool

Returns true or false when mouse button is being held

func PlaySoundFromFile added in v1.0.8

func PlaySoundFromFile(path string)

func RGBA

func RGBA(r, g, b, a uint8) color.RGBA

Returns a color.RGBA with the R, G, B, A provided

func SetDrawPosition

func SetDrawPosition(options *ebiten.DrawImageOptions, position Vector2)

Helper function for setting a ebiten.DrawImageOptions.GeoM position (resets GeoM before doing so because Ebiten ¯\_(ツ)_/¯)

func Start

func Start(windowWidth, windowHeight, screenScale int, windowTitle string, backgroundColor color.Color, onStart function)

Call this to start Pearl! :D

func TimeSinceStart added in v1.0.8

func TimeSinceStart() float64

Returns the time since the program started

func ToggleFPS

func ToggleFPS()

Call this to toggle the FPS overlay

Types

type Entity

type Entity struct {
	// The name / ID of the entity
	ID string
	// Whether or not the Entity is destroyed
	Destroyed bool
	// contains filtered or unexported fields
}

The struct that all entities are

func (*Entity) AddChild

func (e *Entity) AddChild(entity *Entity)

Adds Entity to child list

func (*Entity) AddChildren

func (e *Entity) AddChildren(entities []*Entity)

Adds Entities to child list

func (*Entity) AddComponent

func (e *Entity) AddComponent(component IComponent)

Adds component specified to entity's component list

func (*Entity) AddComponents

func (e *Entity) AddComponents(components []IComponent)

Adds each of the components specified to entity's component list

func (*Entity) AddTag

func (e *Entity) AddTag(tag string)

Adds tag to the entity's tag list

func (*Entity) AddTags

func (e *Entity) AddTags(tags []string)

Adds each of the tags specified to entity's tag list

func (*Entity) Destroy

func (e *Entity) Destroy()

Flags entity as destroyed and will destroy it in the next update loop

func (*Entity) GetChildren

func (e *Entity) GetChildren() []*Entity

Returns Entity's children

func (*Entity) GetComponent

func (e *Entity) GetComponent(id string) IComponent

Returns the component with the id specified, but returns nil if entity doesn't a component with that id

func (*Entity) GetComponentInChildren

func (e *Entity) GetComponentInChildren(id string) IComponent

Checks each child for component with id and returns the first one found. Returns nil if not found

func (*Entity) GetComponentInParent

func (e *Entity) GetComponentInParent(id string) IComponent

Returns the component in the parent with id specified. Returns nil if parent doesn't have component

func (*Entity) GetComponents

func (e *Entity) GetComponents(id string) []IComponent

Returns a slice of components found on entity, returns an empty slice if none found

func (*Entity) GetComponentsInChildren

func (e *Entity) GetComponentsInChildren(id string) []IComponent

Returns slice of all components with id found in each children, returns empty slice if none found

func (*Entity) GetComponentsInParent

func (e *Entity) GetComponentsInParent(id string) []IComponent

Returns a slice of components with id specified found in the parent. Returns empty list if none found

func (*Entity) GetParent

func (e *Entity) GetParent() *Entity

Returns Entity's parent

func (*Entity) HasComponent

func (e *Entity) HasComponent(id string) bool

Returns bool on wether or not the entity has the component

func (*Entity) HasTag

func (e *Entity) HasTag(tag string) bool

Returns whether or not the Entity has the tag specified

func (*Entity) RemoveChild

func (e *Entity) RemoveChild(entity *Entity)

Removes Entity from child list, but does nothing if entity specified isn't a child of entity

func (*Entity) RemoveChildAt

func (e *Entity) RemoveChildAt(index int)

Removes Entity at index from child list, but does nothing if entity specified isn't a child of entity

func (*Entity) SetParent

func (e *Entity) SetParent(entity *Entity)

Sets Entity's parent variable

type IComponent

type IComponent interface {
	// Returns name / ID of component
	ID() string
}

The interface all components will implement

type ISystem

type ISystem interface {
	// Your update loop (called 60 times per second) before draw
	Update(entity *Entity, scene *Scene)
	// Your draw loop (called 60 times per second) after update
	Draw(entity *Entity, scene *Scene, screen *ebiten.Image, options *ebiten.DrawImageOptions)
	// Should return a slice of strings that have the IDs of all components required
	GetRequirements() []string
}

The interface all systems will implement

type Scene

type Scene struct {
	// The Scene's name / ID
	ID string
	// A list of the Scene's Entities
	Entities []*Entity
	// A list of the Scene's Systems
	Systems []ISystem
}

The struct that all Scenes are

func (*Scene) AddEntities

func (s *Scene) AddEntities(entities []*Entity)

Adds Entities specified to Scene's entity list

func (*Scene) AddEntity

func (s *Scene) AddEntity(entity *Entity)

Adds Entity specified to Scene's entity list

func (*Scene) AddSystem

func (s *Scene) AddSystem(system ISystem)

Adds System specified to Scene's System list

func (*Scene) AddSystems

func (s *Scene) AddSystems(systems []ISystem)

Adds Systems specified to Scene's System list

func (*Scene) Draw

func (s *Scene) Draw(screen *ebiten.Image)

This is automatically called, and it draws all Entities and Systems

func (*Scene) FindComponent

func (s *Scene) FindComponent(id string) IComponent

Returns the first component found on the first entity found, returns nil if not found

func (*Scene) FindComponents

func (s *Scene) FindComponents(id string) []IComponent

Returns a slice of Components found, returns empty slice if none found

func (*Scene) FindEntitiesOfType

func (s *Scene) FindEntitiesOfType(id string) []*Entity

Returns a slice of Entities found with Component

func (*Scene) FindEntityOfType

func (s *Scene) FindEntityOfType(id string) *Entity

Returns the first Entity found with specified component, but if none found returns nil

func (*Scene) GetEntitiesWithTag

func (s *Scene) GetEntitiesWithTag(tag string) []*Entity

Returns a slice of Entities found with the specified tag

func (*Scene) GetEntityWithID

func (s *Scene) GetEntityWithID(id string) *Entity

Returns Entity from Scene's entity list with ID specified, and returns nil if Scene doesn't have an Entity with that ID

func (*Scene) GetEntityWithTag

func (s *Scene) GetEntityWithTag(tag string) *Entity

Returns first Entity found with tag, but returns nil if not found

func (*Scene) RemoveEntity

func (s *Scene) RemoveEntity(index int)

Removes Entity at index (might cause problems if you use this. It's best to just call Destroy() and let Pearl handle it, but you do you XD)

func (*Scene) Update

func (s *Scene) Update()

This is automatically called, and it updates all Entities and Systems

type Vector2

type Vector2 struct {
	X float64
	Y float64
}

The Vector2 struct

func GetMousePosition

func GetMousePosition() Vector2

Get mouse position as Vector2

func GetScreenSize

func GetScreenSize() Vector2

Returns screen size as Vector2

func Normalized

func Normalized(v Vector2) Vector2

Returns a copy of the Vector2 normalized (doesn't change Vector2)

func Vector2Add

func Vector2Add(vector Vector2, other interface{}) Vector2

Adds b to vector. returns result

func Vector2Divide

func Vector2Divide(vector Vector2, other interface{}) Vector2

Divides a and b (doesn't change variables)

func Vector2Floor

func Vector2Floor(vector Vector2) Vector2

Returns Vector2 floored (doesn't change Vector2)

func Vector2Multiply

func Vector2Multiply(vector Vector2, other interface{}) Vector2

Multiplies a and b (doesn't change variables)

func Vector2Subtract

func Vector2Subtract(vector Vector2, other interface{}) Vector2

Subtracts a and b (doesn't change variables)

func (*Vector2) Add

func (v *Vector2) Add(other interface{})

Adds Vector2 and other (changes Vector2)

func (*Vector2) Divide

func (v *Vector2) Divide(other interface{})

Divides Vector2 and other (changes Vector2)

func (*Vector2) Magnitude

func (v *Vector2) Magnitude() float64

Returns the magnitude of a Vector2 type

func (*Vector2) Multiply

func (v *Vector2) Multiply(other interface{})

Multiplies Vector2 and other (changes Vector2)

func (*Vector2) Normalize

func (v *Vector2) Normalize()

Normalizes Vector2

func (*Vector2) Subtract

func (v *Vector2) Subtract(other interface{})

Subtracts Vector2 and other (changes Vector2)

func (*Vector2) Vector2Floor

func (v *Vector2) Vector2Floor()

Floors Vector2 (changes Vector2)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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