game

package
v0.0.0-...-5254d27 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capsule

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

Capsule represents a line that can collide with circles

func NewCapsule

func NewCapsule(start, end Vec2, r float64, shader *ebiten.Shader) *Capsule

NewCapsule creates a new line from (x1, y1) to (x2, y2)

func (*Capsule) Draw

func (c *Capsule) Draw(screen *ebiten.Image)

Draw the line to the screen.

type Circle

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

Circle represents a circle

func NewCircle

func NewCircle(x, y, r float64, shader *ebiten.Shader) *Circle

NewCircle creates a new circle at position x,y with radius r

func (Circle) Draw

func (c Circle) Draw(screen *ebiten.Image)

Draw the circle to the screen.

type Engine

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

Engine handles collisions

func NewEngine

func NewEngine(width, height int, circles []*Circle, capsules []*Capsule, rectangles []*collisionRect) *Engine

NewEngine initializes a new physics engine

type Game

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

Game implements ebiten.Game interface and stores the game state.

The methods run in the following order (each one is run once in this order if fps is 60 and display is 60 Hz):

Update
Draw
Layout

func NewGame

func NewGame(width, height int) *Game

NewGame creates a new Game

func (*Game) Draw

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

Draw is called every frame. The frame frequency depends on the display's refresh rate, so if the display is 60 Hz, Draw will be called 60 times per second.

func (*Game) Draw2

func (g *Game) Draw2(screen *ebiten.Image)

Draw2 for testing shader

func (*Game) Layout

func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int)

Layout accepts the window size on desktop as the outside size, and return's the game's internal or pixel screen size, which is then scaled up to fit in the outside size. This does more for resizeable windows.

func (*Game) Update

func (g *Game) Update() error

Update function is called every tick and updates the game's logical state.

type SpeedControl

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

SpeedControl handles time dilation and pausing.

func NewSpeedControl

func NewSpeedControl() *SpeedControl

NewSpeedControl initializes a new control at full speed.

type Vec2

type Vec2 struct {
	X float64
	Y float64
}

Vec2 is a 2D vector

func (Vec2) Add

func (u Vec2) Add(v Vec2) Vec2

Add two vectors

func (Vec2) Angle

func (u Vec2) Angle() float64

Angle returns the angle of the vector u to the X axis in the range -Pi, Pi.

func (Vec2) Cross

func (u Vec2) Cross(v Vec2) float64

Cross returns the cross product of vectors u and v

func (Vec2) Dot

func (u Vec2) Dot(v Vec2) float64

Dot returns the dot product of vectors u and v

func (Vec2) Len

func (u Vec2) Len() float64

Len returns the length of vector u

func (Vec2) Normal

func (u Vec2) Normal() Vec2

Normal returns a vector normal to u

func (Vec2) Scaled

func (u Vec2) Scaled(s float64) Vec2

Scaled returns vector u multiplied by s

func (Vec2) Sub

func (u Vec2) Sub(v Vec2) Vec2

Sub subtracts vector v from u

func (Vec2) To

func (u Vec2) To(v Vec2) Vec2

To returns vector from u to v (same as v.Sub(u))

func (Vec2) Unit

func (u Vec2) Unit() Vec2

Unit returns a unit vector with len 1 in the direction of u

Jump to

Keyboard shortcuts

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