gfx

package module
v0.0.0-...-d8ab462 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HexColorToRGBA

func HexColorToRGBA(color int) *sdl.Color

HexColorToRGBA converts a colour stored in an int to RGBA values

Types

type Actor

type Actor struct {
	Name  string
	Scene *Scene
	// Props   []*Prop
	Visible bool
	Scale   float32
	Pos     Vec3
	Speed   Vec3
}

Actor represents a specific Actor in a game

func NewActor

func NewActor(name string) *Actor

NewActor factory

func (*Actor) SetScale

func (a *Actor) SetScale(scale float32)

SetScale ..

type Actors

type Actors interface {
	SetScale(float32)
	Start(*Scene)
	Update(ticks uint32)
	Draw()
}

Actors are objects that can be drawn

type AtlasCoord

type AtlasCoord struct {
	X, Y int
}

AtlasCoord indicates the location in bitmap/texture atlas

type Bitmap

type Bitmap struct {
	Pitch  int
	Pixels []int
}

Bitmap reqpresents a basic bitmap

func (*Bitmap) ToTexture

func (bm *Bitmap) ToTexture(stage *Stage) (*sdl.Texture, error)

ToTexture returnes a texture from a bitmap

type BitmapAtlas

type BitmapAtlas struct {
	Bitmap
	Keys       map[string]AtlasCoord
	Pitch      int // The width of the atlas
	TileWidth  int // The width of a tile
	TileHeight int // The height of a tile
}

BitmapAtlas represents an array of bitmap addressable by a key

func (*BitmapAtlas) GetBitmap

func (bma *BitmapAtlas) GetBitmap(key string) (*Bitmap, error)

GetBitmap returns the bitmap tile for key speified

func (*BitmapAtlas) GetKeys

func (bma *BitmapAtlas) GetKeys() []string

GetKeys returns a []rune of keys in the atlas

func (*BitmapAtlas) GetTexture

func (bma *BitmapAtlas) GetTexture(stage *Stage, key string) (*sdl.Texture, error)

GetTexture returns a texuter for the bitmap at the position associated witht he key

type Drawable

type Drawable interface {
	Texture() *sdl.Texture
	Vec3() (x, y, z int32)
	Scale() float32
	IsVisible() bool
}

Drawable represents nd object that can be drawn by a renderer

type KBState

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

KBState represents the state of the keyboard

func NewKBState

func NewKBState() *KBState

NewKBState fsceney

func (*KBState) IsKeyDown

func (kb *KBState) IsKeyDown(key uint8) bool

IsKeyDown returns true if the key state is down

func (*KBState) IsKeyUp

func (kb *KBState) IsKeyUp(key uint8) bool

IsKeyUp returns true if the key state is up

func (*KBState) OnKeyDown

func (kb *KBState) OnKeyDown(key uint8) bool

OnKeyDown returns true when the key state changes from up to down

func (*KBState) OnKeyUp

func (kb *KBState) OnKeyUp(key uint8) bool

OnKeyUp returns true when the key state changes from up to down

func (*KBState) Refresh

func (kb *KBState) Refresh()

Refresh the keyboard state

type Prop

type Prop struct {
	Name    string
	Pos     Vec3
	Texture *sdl.Texture
	Scale   float32

	Width  int32
	Height int32
	TransformXYZFunc
}

Prop represents an on-screen item.

func NewProp

func NewProp(name string, texture *sdl.Texture, transformFunc TransformXYZFunc) *Prop

NewProp factory

func (*Prop) Draw

func (p *Prop) Draw(renderer *sdl.Renderer)

Draw renders the props texture to the screen

type Scene

type Scene struct {
	Name   string
	Stage  *Stage
	Actors []Actors

	KeyboardEventHandler    func(e *sdl.KeyboardEvent)
	MouseButtonEventHandler func(e *sdl.MouseButtonEvent)
	MouseMotionEventHandler func(e *sdl.MouseMotionEvent)
	MouseWheelEventHandler  func(e *sdl.MouseWheelEvent)

	StartEventHandler  func()
	UpdateEventHandler func(ticks uint32)
	StopEventHandler   func()
}

Scene represents a specific Scene in a game

func NewScene

func NewScene(name string) *Scene

NewScene returns a new game Scene

func (*Scene) AddActor

func (s *Scene) AddActor(actor Actors)

AddActor adds a actor to the scene

func (*Scene) ClearActors

func (s *Scene) ClearActors()

ClearActors removes all actors

func (*Scene) Draw

func (s *Scene) Draw()

Draw draws the supplied props into the specified Stage

func (*Scene) ElapsedTime

func (s *Scene) ElapsedTime() float32

ElapsedTime returns the legnth of the last from in MS

func (*Scene) FireKeyboardEvent

func (s *Scene) FireKeyboardEvent(e *sdl.KeyboardEvent)

FireKeyboardEvent triggers the keyboard event handler for the director and the current scene

func (*Scene) FireUpdateEvent

func (s *Scene) FireUpdateEvent(ticks uint32)

FireUpdateEvent triggers the update event handler for the director and the current scene

func (*Scene) KBState

func (s *Scene) KBState() *KBState

KBState returns the keyboard

func (*Scene) RemoveActor

func (s *Scene) RemoveActor(actor Actors)

RemoveActor removes a actor from the scene

func (*Scene) Renderer

func (s *Scene) Renderer() *sdl.Renderer

Renderer returns the current renderer

func (*Scene) Scale

func (s *Scene) Scale() float32

Scale returns the default scale factor

func (*Scene) Start

func (s *Scene) Start(stage *Stage)

Start starts the scene on the specified stage

func (*Scene) Stop

func (s *Scene) Stop()

Stop stops the running scene

type Stage

type Stage struct {
	Title    string
	Window   *sdl.Window
	Renderer *sdl.Renderer
	KBState  *KBState

	Top    int32
	Left   int32
	Width  int32
	Height int32
	Scale  float32

	ElapsedTime float32

	FPSStart time.Time
	FPSCount int
	FPS      int
	Stopping bool

	KeyboardEventHandler func(e *sdl.KeyboardEvent)

	Scene *Scene
}

Stage represents a single Window

func NewStage

func NewStage(title string, top, left, width, height int, scale float32) (*Stage, error)

NewStage fsceney

func (*Stage) Destroy

func (s *Stage) Destroy()

Destroy cleans u resources

func (*Stage) DumpActors

func (s *Stage) DumpActors()

DumpActors dumps out basic details about loaded props

func (*Stage) FireKeyboardEvent

func (s *Stage) FireKeyboardEvent(e *sdl.KeyboardEvent)

FireKeyboardEvent triggers the keyboard event handler for the director and the current scene

func (*Stage) NewSinglePixelTexture

func (s *Stage) NewSinglePixelTexture(r, g, b, a uint8) (*sdl.Texture, error)

NewSinglePixelTexture returns a new texture comprising a single pixel

func (*Stage) SetBackgroundColor

func (s *Stage) SetBackgroundColor(color sdl.Color)

SetBackgroundColor sets the background color

func (*Stage) Start

func (s *Stage) Start()

Start the main event loop for the Stage..

func (*Stage) StartScene

func (s *Stage) StartScene(scene *Scene)

StartScene starts the supplied scene

func (*Stage) Stop

func (s *Stage) Stop()

Stop the stage

func (*Stage) StopScene

func (s *Stage) StopScene()

StopScene stops the running scene

func (*Stage) WindowSize

func (s *Stage) WindowSize() (w, h int32)

WindowSize returns the width and height of the widow

type TransformXYZFunc

type TransformXYZFunc func(pos Vec3) (tX, tY, tZ int32)

TransformXYZFunc transforms game X, Y, Z to diplay X, Y, Z

type Vec3

type Vec3 struct {
	X, Y, Z float32
}

Vec3 represents the position of an item

func (*Vec3) Float32

func (p *Vec3) Float32() (x, y, z float32)

Float32 returns the position as float32

func (*Vec3) Int32

func (p *Vec3) Int32() (x, y, z int32)

Int32 returns the position as int32

func (*Vec3) MoveVec3

func (p *Vec3) MoveVec3(x, y, z float32)

MoveVec3 moves the position by +/- x, y, z

func (*Vec3) MoveX

func (p *Vec3) MoveX(x float32)

MoveX moves the X pos by +/- x

func (*Vec3) MoveY

func (p *Vec3) MoveY(y float32)

MoveY moves the Y pos by +/- x

func (*Vec3) MoveZ

func (p *Vec3) MoveZ(z float32)

MoveZ moves the Z pos by +/- x

func (*Vec3) Set

func (p *Vec3) Set(x, y, z float32)

Set sets the pos

func (*Vec3) SetInt32

func (p *Vec3) SetInt32(x, y, z int32)

SetInt32 sets the pos

func (*Vec3) SetX

func (p *Vec3) SetX(x float32)

SetX sets the X pos

func (*Vec3) SetY

func (p *Vec3) SetY(y float32)

SetY sets the Y pos

func (*Vec3) SetZ

func (p *Vec3) SetZ(z float32)

SetZ sets the Z pos

func (*Vec3) Vec3Float32

func (p *Vec3) Vec3Float32() (x, y, z float32)

Vec3Float32 returns the pos as float32

func (*Vec3) Vec3Int32

func (p *Vec3) Vec3Int32() (x, y, z int32)

Vec3Int32 returns the pos as int32

Jump to

Keyboard shortcuts

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