GameEngine

package
v0.0.0-...-bae11f2 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const NEGINF float64 = -1000000

NEGINF - helper const = -1_000_000

View Source
const PI = 3.141592

PI constant

Variables

This section is empty.

Functions

func Clamp

func Clamp(num, low, hi float64) float64

Clamp - returns number clamped between low and hi

func Clamp01

func Clamp01(num float64) float64

Clamp01 returns number clamped between 0 and 1

func Delay

func Delay(s uint32)

Delay in milliseconds

func NewRect

func NewRect(x, y, w, h float64) *sdl.Rect

NewRect - helper function to build and SDL rectangle from float64's

func NewSdlColor

func NewSdlColor(r, g, b, a float64) sdl.Color

NewSdlColor - takes floats and returs an sdl suitalbe color object

func R256

func R256() float64

R256 random number 0-255

func RandIntN

func RandIntN(i float64) float64

RandIntN - rand intn for sdl

func Sign

func Sign(s float64) float64

Sign - helper func - returns sign of input as -1,0,1

func Wrap

func Wrap(num, low, hi float64) float64

Wrap - returns number wraped around a low and hi boundary

Types

type Colour

type Colour struct {
	R float64
	G float64
	B float64
	A float64
}

Colour struct for float64 colour values

func NewColour

func NewColour(r, g, b, a float64) Colour

NewColour gives a new colour object

func (Colour) Fade

func (c Colour) Fade(normalised float64) Colour

Fade a colour by a percentage

func (Colour) ToSDLColor

func (c Colour) ToSDLColor() sdl.Color

ToSDLColor - returns a sdl.Color struct from a Colour struct

func (Colour) Unpack

func (c Colour) Unpack() (uint8, uint8, uint8, uint8)

Unpack - transforms Colour struct to 4 uint8 values

type Context

type Context struct {
	WindowTitle string
	WinWidth    float64
	WinHeight   float64
	Window      *sdl.Window
	Renderer    *sdl.Renderer
	Blocks      float64
	ScrnWidth   float64
	ScrnHeight  float64
	// contains filtered or unexported fields
}

Context - contains context object for game engine

func New

func New(b, sw, sh float64, title string, tf TransformFunc) *Context

New - create the GameEngine and initialises

func (*Context) Clear

func (c *Context) Clear()

Clear renderer

func (*Context) Destroy

func (c *Context) Destroy()

Destroy - cleans up window and renderer

func (*Context) DrawCircle

func (c *Context) DrawCircle(x, y, radius float64)

DrawCircle - draws circle using point function

func (*Context) DrawFillCircle

func (c *Context) DrawFillCircle(x, y, radius float64)

DrawFillCircle - draws filled circle using point function

func (*Context) DrawText

func (c *Context) DrawText(x, y, scale float64, text string)

DrawText to screen with a scaling factor to reduce

func (*Context) Elapsed

func (c *Context) Elapsed() float64

Elapsed - calculates the elapsed time between updates

func (*Context) Line

func (c *Context) Line(x0, y0, x1, y1 float64)

Line drawing (blocks)

func (*Context) Point

func (c *Context) Point(x0, y0 float64)

Point - Draws a blocky point transformed to screen with optional transform applied from func stored in Context

func (*Context) PointScale

func (c *Context) PointScale(x0, y0, scale float64)

PointScale - Draws a blocky point but scaled down by a factore (used mainly in text drawing) (blocks)

func (*Context) PollQuitandKeys

func (c *Context) PollQuitandKeys() (running bool, keys KeyStatus)

PollQuitandKeys - checks for events. Returns running=True and a Key struct

func (*Context) Present

func (c *Context) Present()

Present - Renders all to screen

func (*Context) SetDrawColor

func (c *Context) SetDrawColor(rgba Colour)

SetDrawColor for next use to Colour struct

func (*Context) Triangle

func (c *Context) Triangle(x0, y0, x1, y1, x2, y2 float64)

Triangle Draws outline Triangle (blocks)

type KeyStatus

type KeyStatus struct {
	Key       string // key pressed as string
	Pressed   bool
	Released  bool
	Repeating bool
	Modifier  uint16
	Event     bool
}

KeyStatus - Struct holding key status information

type P2D

type P2D struct {
	X float64
	Y float64
}

P2D - Struct for holding a 2D point

type P3D

type P3D struct {
	X float64
	Y float64
	Z float64
}

P3D - Struct for holding a 3D point

type Sprite

type Sprite struct {
	image.Image
	W float64
	H float64
}

Sprite struct

func NewSprite

func NewSprite(filename string) (s *Sprite, err error)

NewSprite - loads and builds a new sprite given a filename. Returns pointer to sprite structure

func (*Sprite) DrawPartialSprite

func (s *Sprite) DrawPartialSprite(c *Context, x, y, ox, oy, w, h float64)

DrawPartialSprite - draws a rectangle from a sprite at x,y given offset ox and oy into sprite size w, h. No bounds checking

func (*Sprite) DrawSprite

func (s *Sprite) DrawSprite(c *Context, x, y float64)

DrawSprite - at x,y location

func (*Sprite) SampleSprite

func (s *Sprite) SampleSprite(nx, ny float64) (rgba Colour)

SampleSprite - Samples from normal x, y of sprite

type SpriteSheet

type SpriteSheet struct {
	Sheet         *Sprite
	SpritesPerRow float64
	SpritesPerCol float64
	SpriteW       float64
	SpriteH       float64
}

SpriteSheet -

func NewSpriteSheet

func NewSpriteSheet(filename string, NumPerCol, NumPerRow float64) (sh *SpriteSheet, err error)

NewSpriteSheet -

func (*SpriteSheet) DrawSpriteFromSheet

func (s *SpriteSheet) DrawSpriteFromSheet(c *Context, x, y, row, col float64)

DrawSpriteFromSheet - given x and y coord draws the sprite from row x col of spritesheet

func (*SpriteSheet) DrawSpriteFromSheetI

func (s *SpriteSheet) DrawSpriteFromSheetI(c *Context, x, y, i float64)

DrawSpriteFromSheetI - indexes spritesheet as linear array.

type TransformFunc

type TransformFunc func(x, y float64) (float64, float64)

TransformFunc - type of function to modify Point drawing

type V2D

type V2D struct {
	Dx float64
	Dy float64
}

V2D - struct for holding a 2D vector

type V3D

type V3D struct {
	DX float64
	DY float64
	DZ float64
}

V3D - struct for holding a 2D vector

type ZBuffer

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

ZBuffer struct

func NewZBuffer

func NewZBuffer(w, h float64) *ZBuffer

NewZBuffer returns a pointer to a initilised and cleared z buffer

func (*ZBuffer) Clear

func (z *ZBuffer) Clear()

Clear - ZBuffer

func (*ZBuffer) SetIfNearer

func (z *ZBuffer) SetIfNearer(x, y, d float64) bool

SetIfNearer - sets z buffer to depth d if is nearer than prev val. Returns true or false

Jump to

Keyboard shortcuts

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