tomohawk

package module
Version: v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 8 Imported by: 0

README

ATTENTION!

Tomohawk has been rebranded, and overhauled, and is now pearl!
https://github.com/eboatwright/pearl

Tomohawk

A Lightweight Cross-platform 2D ECSS Framework for Go and Ebiten!

Installation

go get github.com/eboatwright/tomohawk@v{REPLACE THIS WITH LATEST STABLE VERSION!}

Look through the releases tab, and find the latest one that says stable. 😄
Also, check through https://ebiten.org/documents/install.html and find the dependencies that you need for your Operating System. 😄

Updates

I have a public Trello board now!
https://trello.com/b/fIKnTlR7/tomohawk

Documentation / Wiki

API: https://pkg.go.dev/github.com/eboatwright/tomohawk
Not Tutorials yet, but you can learn the basics from the supplied example.txt file. 😄

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)

Sets currentScene to be specified 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 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, title string, backgroundColor color.Color, init fn)

Call this to start tomohawk!

func ToggleFPS

func ToggleFPS()

Toggles the ShowFPS variable

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 will be

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

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. Returns nil if entity doesn't have component

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

func (*Entity) RemoveChildAt

func (e *Entity) RemoveChildAt(index int)

Removes Entity at index from child list

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)
	Update(entity *Entity, scene *Scene)
	// Your draw loop (called 60 times per second)
	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 will be

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

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

Returns a slice of Components found

func (*Scene) FindEntitiesOfType

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

Returns a slice of Entities found with Component

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

func (s *Scene) RemoveEntity(index int)

Destroys Entity at index

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 tomohawk.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 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 tomohawk.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)

Jump to

Keyboard shortcuts

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