common

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package common contains basic structures for use in engine backends.

Index

Constants

View Source
const AssetSignature = "Ardent"

AssetSignature is the signature prepended to all Ardent asset files.

Variables

View Source
var ErrInvalidFiletype = errors.New("invalid filetype")

ErrInvalidFiletype occurs when an asset file is of an invalid type.

Functions

This section is empty.

Types

type Animation

type Animation struct {
	Fps, Start, End uint16
	Loop            bool
}

Animation holds extra info for an animated Asset.

type Asset

type Asset struct {
	Img      Image
	AtlasMap map[string]AtlasRegion

	AnimationMap map[string]Animation
	AnimWidth    uint16
	AnimHeight   uint16

	Snd Sound

	Type AssetType
}

Asset is a basic implementation of engine.Asset.

func NewAsset

func NewAsset() *Asset

NewAsset creates an empty Asset.

func (Asset) Marshal

func (a Asset) Marshal() ([]byte, error)

Marshal marshals the asset as a []byte. It is purposefully named Marshal instead of MarshalBinary to prevent a never-ending loop of gob calling Marshal and Marshal calling on gob.

func (*Asset) Unmarshal

func (a *Asset) Unmarshal(data []byte) error

Unmarshal unmarshals the provided []byte as a binary. It is purposefully named Unmarshal instead of UnmarshalBinary to prevent a never-ending loop of gob calling Unmarshal and Unmarshal calling on gob.

type AssetType

type AssetType byte

AssetType indicates a certain type of asset.

const (
	// AssetTypeImage indicates a static image asset.
	AssetTypeImage AssetType = 1 << iota

	// AssetTypeAtlas indicates an image atlas asset.
	AssetTypeAtlas

	// AssetTypeAnimation indicates an animated image asset.
	AssetTypeAnimation

	// AssetTypeSound indicates an audio asset.
	AssetTypeSound
)

type AtlasRegion

type AtlasRegion struct {
	X, Y, W, H uint16
}

AtlasRegion describes a region of an Atlas.

type Camera

type Camera struct {
	engine.Vec2
}

Camera is a basic implementation of engine.Camera.

func (*Camera) LookAt

func (c *Camera) LookAt(x, y, t float64)

LookAt moves the Camera toward the point specified.

func (*Camera) Position

func (c *Camera) Position() (float64, float64)

Position returns the Camera's current position.

type Collider

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

Collider is a basic implementation of engine.Collider.

func (*Collider) Resolve

func (c *Collider) Resolve(src, dst engine.Vec2) engine.Vec2

Resolve handles a collision.

func (*Collider) SetTilemap

func (c *Collider) SetTilemap(m engine.Tilemap)

SetTilemap sets the Collider's Tilemap.

type Image

type Image struct {
	image.Image
}

Image is a wrapper around image.Image that serializes as a PNG.

func (Image) MarshalBinary

func (i Image) MarshalBinary() ([]byte, error)

MarshalBinary marshals the image as a PNG or just a null byte if there's no image.

func (*Image) UnmarshalBinary

func (i *Image) UnmarshalBinary(data []byte) error

UnmarshalBinary sets the image's content to nil if it's a null byte or the decoded PNG.

type InvalidAssetType

type InvalidAssetType AssetType

InvalidAssetType occurs when an invalid AssetType value is encountered.

func (InvalidAssetType) Error

func (i InvalidAssetType) Error() string

Error implements error.

type Sound

type Sound struct {
	// Group is the control group
	// the Sound belongs to.
	Group string

	// Options are the different audio
	// tracks that may represent the same sound.
	// A random option will be selected each time
	// the sound is played.
	Options [][]byte
}

Sound is a collection of audio data

type Tilemap

type Tilemap struct {
	Width        int
	Data         [2][][]int
	Mapper       map[int]engine.Image
	OverlapEvent engine.TileOverlapEvent
}

Tilemap is a basic implementation of engine.Tilemap.

func (*Tilemap) GetTileValue

func (t *Tilemap) GetTileValue(x, y, z int) int

GetTileValue returns the value associated with a tile.

func (*Tilemap) IndexToIso

func (t *Tilemap) IndexToIso(i, j int) (float64, float64)

IndexToIso converts a tile index to isometric coordinates.

func (*Tilemap) IsoToIndex

func (t *Tilemap) IsoToIndex(x, y float64) (int, int)

IsoToIndex converts isometric coordinates to a tile index.

Jump to

Keyboard shortcuts

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