igloo

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2020 License: MIT Imports: 3 Imported by: 3

README

Igloo

PkgGoDev codecov tests

Extension framework to ebiten

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Vec2Zero is a Vec2 of (0, 0)
	Vec2Zero = Vec2{0, 0}
	// Vec2One is a Vec2 of (1, 1)
	Vec2One = Vec2{1, 1}
)

Functions

This section is empty.

Types

type Camera

type Camera interface {
	Dirtier

	// WorldToScreen will convert a world matrix into a screen matrix for rendering
	WorldToScreen(ebiten.GeoM) ebiten.GeoM

	// ScreenToWorld will convert an X,Y coordinate from the screen to its world position
	ScreenToWorld(x, y float64) (float64, float64)

	// IsInView returns whether or not a rectangle is within the cameras view
	IsInView(x, y, width, height float64) bool
}

Camera allows you to move through a large scene without having to modify each individual element. To allow for any type of camera ( or none at all ) instead of defining specifics on how the camera works or behaves in relation to elements we instead define how the elements behave with the camera.

That is, if your element should interact with a possible moving camera have its world position modified to use the screen position from WorldToScreen. If your element should not be affected by a camera, such as a UI element, do not use the world to screen function.

To avoid drawing anything off screen check if it is in view first.

type Canvaser

type Canvaser interface {
	DrawImage(src *ebiten.Image, op *ebiten.DrawImageOptions)
}

Canvaser represents a surface that images can be drawn to. Typically, this would be an *ebiten.Image.

type Dirtier

type Dirtier interface {
	// IsDirty returns whether or not our object is dirty
	IsDirty() bool
	// Clean the object back to a fresh state
	Clean()
}

Dirtier allows structs to track when they are changed and only apply complex changes when there is something new to update.

type Game

type Game interface {
	ebiten.Game

	// LoadScene will unload the current scene and load in a new one.
	// It should dipose of the previous scene before setting up the next.
	// This is to allow a clean transition from one scene to another by allowing the
	// previous scene to be disposed before the new scene is setup.
	// Game Logic > Dispose current scene > Setup new scene.
	LoadScene(Scene)
}

Game adds a LoadScene method to ebitens Game interface allowing us to go from one scene to another.

type Scene

type Scene interface {
	// Setup is used to handle all the loading of content and elements.
	// You should load all content and data here instead of a constructor function.
	// This way the LoadScene on the Game can transition between scenes.
	Setup(Game)

	// Update all game elements.
	Update(deltaTime float64)

	// Draw all game elements.
	Draw(screen *ebiten.Image)

	// Dispose of game content or data.
	Dispose()
}

Scene is a core component of logic and rendering. The core methods are update and draw to handle game logic and rendering.

type Sprite

type Sprite struct {
	Image     *ebiten.Image
	Transform *Transform
	// contains filtered or unexported fields
}

Sprite represents a renderable element in the world.

func NewSprite

func NewSprite(image *ebiten.Image, transform *Transform) *Sprite

NewSprite will create a basic sprite from image and transform. Anchor defaults to (0,0) and size will default to the image size.

func NewSpriteAnchor

func NewSpriteAnchor(image *ebiten.Image, transform *Transform, anchor Vec2) *Sprite

NewSpriteAnchor will create a sprite with a custom anchor. Size will default to the image size.

func NewSpriteAnchorSize

func NewSpriteAnchorSize(
	image *ebiten.Image, transform *Transform, anchor Vec2, width, height float64,
) *Sprite

NewSpriteAnchorSize will create a sprite with a custom anchor and size

func NewSpriteSize

func NewSpriteSize(image *ebiten.Image, transform *Transform, width, height float64) *Sprite

NewSpriteSize will create a sprite with a custom size. Anchor defaults to (0,0)

func (*Sprite) Anchor

func (s *Sprite) Anchor() Vec2

Anchor determines our rotation point.

func (*Sprite) Clean

func (s *Sprite) Clean()

Clean resets our dirty state, automatically called when drawing

func (*Sprite) Draw

func (s *Sprite) Draw(canvas Canvaser, camera Camera)

Draw will render the sprite onto the canvas. If our transform, sprite or camera are dirty then we will update internal values accordingly.

func (*Sprite) Height

func (s *Sprite) Height() float64

Height returns our drawing height

func (*Sprite) IsDirty

func (s *Sprite) IsDirty() bool

IsDirty returns whether or not our internal state has changed since last drawing. When dirty our next drawing attempt will refresh drawing values.

func (*Sprite) SetAnchor

func (s *Sprite) SetAnchor(anchor Vec2)

SetAnchor will change our rotation point. Will also mark the sprite as dirty. (0, 0) will rotate around the top left (0.5, 0.5) will rotate around the center (1, 1) will rotate around the bottom right

func (*Sprite) SetHeight

func (s *Sprite) SetHeight(height float64)

SetHeight will change our drawing height. Will also mark the sprite as dirty.

func (*Sprite) SetWidth

func (s *Sprite) SetWidth(width float64)

SetWidth will change our drawing width. Will also mark the sprite as dirty.

func (*Sprite) Width

func (s *Sprite) Width() float64

Width returns our drawing width

type Transform

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

Transform holds all data associated to a location

func NewTransform

func NewTransform(x, y, rotation float64) *Transform

NewTransform will create a new transform from x,y and rotation. Note that transforms start dirty.

func (*Transform) Clean

func (t *Transform) Clean()

Clean will clean up the dirty status back to false

func (*Transform) GetPosition

func (t *Transform) GetPosition() (float64, float64)

GetPosition will return both x and y

func (*Transform) IsDirty

func (t *Transform) IsDirty() bool

IsDirty returns whether or not we have changed since the last update

func (*Transform) Rotation

func (t *Transform) Rotation() float64

Rotation will return the rotation value

func (*Transform) SetPosition

func (t *Transform) SetPosition(x, y float64)

SetPosition will change both x and y values as well as marking us as dirty.

func (*Transform) SetRotation

func (t *Transform) SetRotation(rotation float64)

SetRotation will change the rotation value and mark us as dirty.

func (*Transform) SetX

func (t *Transform) SetX(x float64)

SetX will change the x value and mark us as dirty.

func (*Transform) SetY

func (t *Transform) SetY(y float64)

SetY will change the y value and mark us as dirty.

func (*Transform) Translate

func (t *Transform) Translate(dx, dy float64)

Translate will move x and y by dx and dy as well as marking as dirty.

func (*Transform) X

func (t *Transform) X() float64

X will return the x value

func (*Transform) Y

func (t *Transform) Y() float64

Y will return the y value

type Vec2

type Vec2 struct {
	X, Y float64
}

Vec2 describes a 2D vector or point

func Vec2FromAngle

func Vec2FromAngle(angle float64) Vec2

Vec2FromAngle returns a Vec2 from an angle in radians

func (Vec2) Add

func (v Vec2) Add(other Vec2) Vec2

Add other to us

func (Vec2) Angle

func (v Vec2) Angle() float64

Angle returns the angle in radians of our vector

func (Vec2) Cross

func (v Vec2) Cross(other Vec2) float64

Cross returns the cross product of vectors v and other

func (Vec2) Dist

func (v Vec2) Dist(other Vec2) float64

Dist returns the distance between two vectors

func (Vec2) Dot

func (v Vec2) Dot(other Vec2) float64

Dot returns the dot product of vectors v and other

func (Vec2) Mag

func (v Vec2) Mag() float64

Mag returns the magnitude of our vector

func (Vec2) Map

func (v Vec2) Map(fun func(float64) float64) Vec2

Map applies a function to both X and Y components and returns a new Vec2 of the result

func (Vec2) MulScalar

func (v Vec2) MulScalar(scalar float64) Vec2

MulScalar multiplies both elements by a scalar

func (Vec2) Normal

func (v Vec2) Normal() Vec2

Normal returns a vectors normal, same as rotating 90 degress

func (Vec2) SqrDist

func (v Vec2) SqrDist(other Vec2) float64

SqrDist returns the square distance between us and another vector

func (Vec2) SqrMag

func (v Vec2) SqrMag() float64

SqrMag returns the Square Magnitude of our vector

func (*Vec2) String

func (v *Vec2) String() string

String returns vec2 as a string

func (Vec2) Sub

func (v Vec2) Sub(other Vec2) Vec2

Sub other from us

func (Vec2) SubScalar

func (v Vec2) SubScalar(scalar float64) Vec2

SubScalar subtracts both elements by a scalar

func (Vec2) Unit

func (v Vec2) Unit() Vec2

Unit is a 1 unit vector in the same direction as v. Unless v is (0,0) in which case it returns (0,0).

func (Vec2) XY

func (v Vec2) XY() (float64, float64)

XY returns the X and Y components separately

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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