Back to godoc.org
github.com/lethal-bacon0/sh2d

Package sh2d

v0.0.0-...-11f1231
Latest Go to latest

The highest tagged major version is .

Published: Sep 5, 2020 | License: MIT | Module: github.com/lethal-bacon0/sh2d

Index

func GetWindowHeight

func GetWindowHeight() int

func GetWindowName

func GetWindowName() string

func GetWindowWidth

func GetWindowWidth() int

func RotateAtCenter

func RotateAtCenter(renderPos *ebiten.GeoM, rotation float64, width, height float64)

RotateAtCenter totates a matrix on its center

Parameters:

- `renderPos`: matrix to rotate
- `rotation`: rotation in radians
- `width`: width of the sprite
- `height`: height of the sprite
- `position`: position of the sprite

func SetActiveScene

func SetActiveScene(newScene *Scene)

type Component

type Component interface {
	Update() error
	Draw(screen *ebiten.Image) error
}

Component asd

type GameObject

type GameObject struct {
	Position   Vector2D
	Rotation   float64
	Active     bool
	Components []Component
}

GameObject is a generic type all elements in the game should inherit

func (*GameObject) AddComponent

func (g *GameObject) AddComponent(newComponent Component)

AddComponent adds a new component to the game object

func (*GameObject) Draw

func (g *GameObject) Draw(screen *ebiten.Image) error

Draw draws all components to screen

func (*GameObject) GetComponent

func (g *GameObject) GetComponent(withType Component) Component

GetComponent gets a component of the speciied type

func (*GameObject) Update

func (g *GameObject) Update() error

Update updates all conmponents

type Gameloop

type Gameloop struct {
}

Gameloop implements ebiten.Gameloop interface.

func NewGame

func NewGame(screenWidth, screenHeight int, name string) *Gameloop

NewGame creates a new game

func (*Gameloop) Draw

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

Draw draws the game screen. Draw is called every frame (typically 1/60[s] for 60Hz display).

func (*Gameloop) Layout

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

Layout takes the outside size (e.g., the window size) and returns the (logical) screen size. If you don't have to adjust the screen size with the outside size, just return a fixed size.

func (*Gameloop) Update

func (g *Gameloop) Update(screen *ebiten.Image) error

Update proceeds the game state. Update is called every tick (1/60 [s] by default).

type RenderPositions

type RenderPositions string

RenderPositions defines anchor positions

const (
	//CenterCenter center of sprite
	CenterCenter RenderPositions = "CENTER"
	//TopLeft topleft of sprite
	TopLeft RenderPositions = "LEFT"
)

type Scene

type Scene struct {
	SceneElements []GameObject
}

Scene contains all elements on screen

func GetActiveScene

func GetActiveScene() *Scene

func (*Scene) AddChild

func (s *Scene) AddChild(child *GameObject)

AddChild adds new child to scene

type SpriteMover

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

SpriteMover moves a sprite

func NewSpriteMover

func NewSpriteMover(container *GameObject, direction Vector2D, velocity float64) *SpriteMover

NewSpriteMover creates a new sprite mover

func (*SpriteMover) Draw

func (b *SpriteMover) Draw(screen *ebiten.Image) error

func (*SpriteMover) Update

func (b *SpriteMover) Update() error

type SpriteRenderer

type SpriteRenderer struct {
	Texture *ebiten.Image

	Anchor *RenderPositions
	Scale  *float64
	// contains filtered or unexported fields
}

SpriteRenderer is a component to render a sprite

func NewSpriteRenderer

func NewSpriteRenderer(texture []byte, container *GameObject, anchor RenderPositions) *SpriteRenderer

NewSpriteRenderer creates a new sprite renderer

func (*SpriteRenderer) Draw

func (sp *SpriteRenderer) Draw(screen *ebiten.Image) error

Draw draws the component.

func (*SpriteRenderer) GetAbsCenter

func (sp *SpriteRenderer) GetAbsCenter() Vector2D

GetAbsCenter gets centered absolute coordinates

func (*SpriteRenderer) GetAbsTopCenter

func (sp *SpriteRenderer) GetAbsTopCenter() Vector2D

GetAbsTopCenter gets absolute coordinates of top center

func (*SpriteRenderer) GetRelCenter

func (sp *SpriteRenderer) GetRelCenter() Vector2D

GetRelCenter gets centered relative coordinates

func (*SpriteRenderer) Update

func (sp *SpriteRenderer) Update() error

Update updates the component.

type Vector2D

type Vector2D struct {
	X, Y float64
}

Vector2D represents a simple 2D vector

func (Vector2D) Add

func (v1 Vector2D) Add(v2 Vector2D) Vector2D

Add adds two vectors and return the result as a new vector

func (Vector2D) GetDirVector

func (v1 Vector2D) GetDirVector(v2 Vector2D) Vector2D

GetDirVector gets the directional vector of two vectors

func (Vector2D) GetUnitVector

func (v1 Vector2D) GetUnitVector() Vector2D

GetUnitVector calculates the unit vector

func (Vector2D) GetVectorLength

func (v1 Vector2D) GetVectorLength() float64

GetVectorLength calculates the length of a given vector

func (Vector2D) Sub

func (v1 Vector2D) Sub(v2 Vector2D) Vector2D

Sub subtracts two vectors and return a new Vector2D

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier