pt

package
v0.0.0-...-2351b9c Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreColliding

func AreColliding(h1, h2 Hitbox) bool

Return true if two hitboxes are currently colliding where colliding means either they overlap or their surfaces are touching

func Run

func Run(name string, w, h int, level LevelIface)

Types

type Game

type Game struct {
	Name   string
	Width  int
	Height int
	Level  LevelIface
	Image  *image.RGBA
	Debug  bool
}

func New

func New(name string, w, h int, level LevelIface) *Game

func (*Game) Draw

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

func (*Game) Layout

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

func (*Game) Update

func (g *Game) Update() error

type Hitbox

type Hitbox struct {
	Solid bool // Should this hitbox be included in collision detection
	// Two points representing corner vertices of the hitbox in 3D space
	BV1 Vec
	BV2 Vec
}

type Kinematics

type Kinematics struct {
	Pos Vec
	Vel Vec
	Acc Vec
}

type Level

type Level struct {
	Object
}

func NewLevel

func NewLevel() *Level

func (*Level) ChildrenByZ

func (l *Level) ChildrenByZ() []ObjectIface

func (*Level) Draw

func (l *Level) Draw(drawContext *gg.Context)

func (*Level) Update

func (l *Level) Update() error

type LevelIface

type LevelIface interface {
	ChildrenByZ() []ObjectIface
	Draw(drawContext *gg.Context)
	Update() error
}

type Object

type Object struct {
	Name       string
	ID         ObjectID
	LK         Kinematics // Structure for linear kinematics (angular kinematics may be added later)
	HB         Hitbox
	UpdateFunc func() error
	Children   map[ObjectID]ObjectIface // If this object contains any children, they go in this map
}

***************************************

  • Functions implementing the interface * **************************************

Generic object implementing the ObjectIface interface

func NewObjAtPos

func NewObjAtPos(name string, pos Vec) *Object

func NewObject

func NewObject(name string) *Object

func (*Object) Accelerate

func (o *Object) Accelerate(v Vec)

Adjust the object's velocity according to the given vector v

func (*Object) AddChildren

func (o *Object) AddChildren(children ...ObjectIface)

func (*Object) CopyTo

func (rdr *Object) CopyTo(wrtr *Object)

func (*Object) Draw

func (o *Object) Draw(drawContext *gg.Context)

Intended to be implemented by the specific object

func (*Object) GenID

func (o *Object) GenID() error

func (*Object) GetAcc

func (o *Object) GetAcc() Vec

Get the velocity Vec of the object

func (*Object) GetChildren

func (o *Object) GetChildren() []ObjectIface

func (*Object) GetID

func (o *Object) GetID() ObjectID

func (*Object) GetKinematics

func (o *Object) GetKinematics() Kinematics

func (*Object) GetName

func (o *Object) GetName() string

func (*Object) GetPos

func (o *Object) GetPos() Vec

Get the velocity Vec of the object

func (*Object) GetPosOffset

func (o1 *Object) GetPosOffset(o2 ObjectIface) Vec

Get the offset position vector of o1 as compared to o2

func (*Object) GetVel

func (o *Object) GetVel() Vec

Get the velocity Vec of the object

func (*Object) Init

func (o *Object) Init()

func (*Object) Move

func (o *Object) Move(v Vec)

Move an object relatively according to the given vector v.

func (*Object) ObjAddChildren

func (o *Object) ObjAddChildren(children ...ObjectIface)

func (*Object) ObjDrawPos

func (o *Object) ObjDrawPos(dc *gg.Context, at Vec)

func (*Object) ObjGenID

func (o *Object) ObjGenID() error

If the object's ID is unset (ie. zero), generate a new unique object ID

func (*Object) ObjGetAcc

func (o *Object) ObjGetAcc() Vec

Get the velocity Vec of the object

func (*Object) ObjGetChildren

func (o *Object) ObjGetChildren() []ObjectIface

Recursively

func (*Object) ObjGetID

func (o *Object) ObjGetID() ObjectID

func (*Object) ObjGetKinematics

func (o *Object) ObjGetKinematics() Kinematics

func (*Object) ObjGetName

func (o *Object) ObjGetName() string

func (*Object) ObjGetPos

func (o *Object) ObjGetPos() Vec

func (*Object) ObjGetVel

func (o *Object) ObjGetVel() Vec

Get the velocity Vec of the object

func (*Object) ObjInit

func (o *Object) ObjInit()

func (*Object) ObjRemoveChildren

func (o *Object) ObjRemoveChildren(children ...ObjectIface)

func (*Object) ObjSetAcc

func (o *Object) ObjSetAcc(acc Vec)

Set acceleration of the object and of all child objects

func (*Object) ObjSetChildren

func (o *Object) ObjSetChildren(children []ObjectIface)

func (*Object) ObjSetKinematics

func (o *Object) ObjSetKinematics(lk Kinematics)

func (*Object) ObjSetPos

func (o *Object) ObjSetPos(pos Vec)

Set the position of the object and the relative position of all child objects

func (*Object) ObjSetVel

func (o *Object) ObjSetVel(vel Vec)

Set velocity of the object and of all child objects

func (*Object) ObjUpdate

func (o *Object) ObjUpdate() error

func (*Object) RemoveChildren

func (o *Object) RemoveChildren(children ...ObjectIface)

func (*Object) SetAcc

func (o *Object) SetAcc(acc Vec)

Get the velocity Vec of the object

func (*Object) SetChildren

func (o *Object) SetChildren(children []ObjectIface)

func (*Object) SetKinematics

func (o *Object) SetKinematics(lk Kinematics)

func (*Object) SetPos

func (o *Object) SetPos(pos Vec)

Get the velocity Vec of the object

func (*Object) SetVel

func (o *Object) SetVel(vel Vec)

Get the velocity Vec of the object

func (*Object) Update

func (o *Object) Update() error

func (*Object) UpdateKinematics

func (o *Object) UpdateKinematics()

Convenience function update velocity from acceleration and position from velocity

func (*Object) UpdatePos

func (o *Object) UpdatePos()

Update this object's position using this object's velocity. Does not recursively call child objects

func (*Object) UpdateVel

func (o *Object) UpdateVel()

Update this object's velocity using this object's acceleration. Does not recursively call child objects

type ObjectID

type ObjectID uint64

func UniqueObjectID

func UniqueObjectID() ObjectID

type ObjectIface

type ObjectIface interface {
	// Accounting functions
	Init()
	GetName() string
	GetID() ObjectID
	GenID() error

	// Movement Functions (position, velocity, acceleration)
	GetPos() Vec
	SetPos(Vec)
	Move(Vec)
	GetPosOffset(ObjectIface) Vec
	GetVel() Vec
	SetVel(Vec)
	GetAcc() Vec
	SetAcc(Vec)
	GetKinematics() Kinematics
	SetKinematics(Kinematics)

	// Child functions
	GetChildren() []ObjectIface
	SetChildren([]ObjectIface)
	AddChildren(...ObjectIface)
	RemoveChildren(...ObjectIface)

	// Game loop functions
	Update() error
	Draw(drawContext *gg.Context)
}

type Vec

type Vec struct {
	X, Y, Z float64
}

These coordinates are restricted based on a 2D representation. The reference coordinate 0, 0, 0 is at the top left corner of the screen. X has positive going to the right. Y has positive going down. Z functions as depth, and has positive going out of the screen toward the player

func (Vec) Add

func (v1 Vec) Add(v2 Vec) Vec

Add two Vecs and return the resulting Vec struct

func (Vec) RotateXY180

func (v Vec) RotateXY180() Vec

Uses a vector rotate trick to rotate the 2D vector of just X and Y around 0, 0.

func (Vec) RotateXY180Around

func (v Vec) RotateXY180Around(r Vec) Vec

func (Vec) RotateXY270

func (v Vec) RotateXY270() Vec

Uses a vector rotate trick to rotate the 2D vector of just X and Y around 0, 0.

func (Vec) RotateXY270Around

func (v Vec) RotateXY270Around(r Vec) Vec

func (Vec) RotateXY90

func (v Vec) RotateXY90() Vec

Uses a vector rotate trick to rotate the 2D vector of just X and Y around 0, 0.

func (Vec) RotateXY90Around

func (v Vec) RotateXY90Around(r Vec) Vec

func (Vec) Scale

func (v Vec) Scale(a float64) Vec

func (Vec) Subtract

func (v1 Vec) Subtract(v2 Vec) Vec

Subtract v2 from v1 and return the Vec result

func (Vec) Thousandths

func (v Vec) Thousandths() Vec

Round each dimension to the nearest 1000th to avoid arithmetic errors with floating points from propagating

func (Vec) ToInt

func (v Vec) ToInt() (int, int, int)

func (Vec) ToInt64

func (v Vec) ToInt64() (int64, int64, int64)

func (Vec) ToString

func (v Vec) ToString() string

Jump to

Keyboard shortcuts

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