pixelmunk

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2024 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DrawableBody = iota
	DrawableJoint
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyOptions added in v0.2.0

type BodyOptions struct {
	StaticBody    bool
	Position      vect.Vect
	Angle         vect.Float
	Mass          vect.Float
	Velocity      vect.Vect
	Elasticity    vect.Float
	Friction      vect.Float
	Type          chipmunk.ShapeType
	CircleOptions CircleOptions
	BoxOptions    BoxOptions
}

BodyOptions holds the physical attributes for the Object

type BoxOptions added in v0.2.0

type BoxOptions struct {
	Width  vect.Float
	Height vect.Float
}

BoxOptions holds the attributes for a Box object

type CircleOptions added in v0.2.0

type CircleOptions struct {
	Radius float32
}

CircleOptions holds the attributes for a Circle object

type CustomDrawFunc

type CustomDrawFunc func(object *Object, draw *imdraw.IMDraw)

CustomDrawFunc is the callback function to provide additional functionality when drawing an Option. This is called after the main shape is drawn.

type Drawable

type Drawable interface {
	Draw(imd *imdraw.IMDraw)
	GetOptions() DrawableOptions
	GetType() DrawableType
	GetBody() *chipmunk.Body
	GetJoint() *chipmunk.PivotJoint
}

Drawable interface for any drawable Object

type DrawableOptions added in v0.2.0

type DrawableOptions struct {
	Color          color.Color
	Thickness      float64
	CustomDrawFunc []CustomDrawFunc
	BodyOptions    BodyOptions
	JointOptions   JointOptions
}

DrawableOptions for a drawable

type DrawableType added in v0.2.0

type DrawableType int

DrawableType indicates the subtype of the drawable

type Joint added in v0.2.0

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

Joint joins two bodies together

func NewJointWithAnchor added in v0.2.0

func NewJointWithAnchor(object1, object2 *Object, offset1, offset2 vect.Vect, options DrawableOptions) *Joint

NewJointWithAnchor creates a constraint between two bodies at specified positions

func (Joint) Draw added in v0.2.0

func (j Joint) Draw(imd *imdraw.IMDraw)

Draw draws the Joint on the provided imdraw.IMDraw

func (Joint) GetBody added in v0.2.0

func (j Joint) GetBody() *chipmunk.Body

GetBody returns the chipmunk.Body that the Object represents

func (Joint) GetJoint added in v0.2.0

func (j Joint) GetJoint() *chipmunk.PivotJoint

GetJoint returns the chipmunk.PivotJoint that the Object represents

func (Joint) GetOptions added in v0.2.0

func (j Joint) GetOptions() DrawableOptions

GetOptions returns the DrawableOptions that were used to create the Object

func (Joint) GetType added in v0.2.0

func (j Joint) GetType() DrawableType

GetType returns the type of drawable

type JointOptions added in v0.2.0

type JointOptions struct {
	Draw bool
}

JointOptions contains options for drawing joints

type Object

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

Object represents an object inside the World

func NewBox

func NewBox(options DrawableOptions) *Object

NewBox creates a new Object for a rectangle

func NewCircle

func NewCircle(options DrawableOptions) *Object

NewCircle creates a new Object that represents a circle / disc / ball

func NewObject

func NewObject(body *chipmunk.Body, options DrawableOptions) *Object

NewObject creates a new Object for the provided Body and DrawableOptions

func NewObjectWithShape

func NewObjectWithShape(shape *chipmunk.Shape, options DrawableOptions) *Object

NewObjectWithShape creates a new Object for the provided Shape and DrawableOptions

func (Object) Draw

func (o Object) Draw(imd *imdraw.IMDraw)

Draw draws the Object on the provided imdraw.IMDraw

func (Object) GetBody

func (o Object) GetBody() *chipmunk.Body

GetBody returns the chipmunk.Body that the Object represents

func (Object) GetJoint added in v0.2.0

func (o Object) GetJoint() *chipmunk.PivotJoint

GetJoint returns the chipmunk.PivotJoint that the Object represents

func (Object) GetOptions

func (o Object) GetOptions() DrawableOptions

GetOptions returns the DrawableOptions that were used to create the Object

func (Object) GetType added in v0.2.0

func (o Object) GetType() DrawableType

GetType returns the type of drawable

type World

type World struct {
	Name        string
	Bounds      pixel.Rect
	FrameRate   int
	Space       *chipmunk.Space
	RunFunc     func(*opengl.Window)
	RunCallback func(*opengl.Window)
	Objects     []Drawable
}

World represents the world that chipmunk will simulate

func NewWorld

func NewWorld(name string, minX, minY, maxX, maxY float64) *World

NewWorld creates a new World

func (*World) Add

func (w *World) Add(objects ...Drawable)

Add adds a new Object to the World

func (*World) Draw

func (w *World) Draw(win pixel.Target)

Draw draws all Objects in the World

func (*World) Remove added in v0.2.0

func (w *World) Remove(objects ...Drawable)

Remove removes an Object from the World

func (*World) Run

func (w *World) Run()

Run runs the world simulation. This should be called from main():

		w := NewWorld("test", 0, 0, 1024, 1080)
     // add some objects
		opengl.Run(w.Run)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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