pixelmunk

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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)
	GetBody() *chipmunk.Body
	GetOptions() ObjectOptions
}

Drawable interface for any drawable Object

type Object

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

Object represents an object inside the World

func NewBox

func NewBox(options ObjectOptions) Object

NewBox creates a new Object for a rectangle

func NewCircle

func NewCircle(options ObjectOptions) Object

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

func NewObject

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

NewObject creates a new Object for the provided Body and ObjectOptions

func NewObjectWithShape

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

NewObjectWithShape creates a new Object for the provided Shape and ObjectOptions

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) GetOptions

func (o Object) GetOptions() ObjectOptions

GetOptions returns the ObjectOptions that were used to create the Object

type ObjectBodyOptions

type ObjectBodyOptions 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 ObjectCircleOptions
	BoxOptions    ObjectBoxOptions
}

ObjectBodyOptions holds the physical attributes for the Object

type ObjectBoxOptions

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

ObjectBoxOptions holds the attributes for a Box object

type ObjectCircleOptions

type ObjectCircleOptions struct {
	Radius float32
}

ObjectCircleOptions holds the attributes for a Circle object

type ObjectOptions

type ObjectOptions struct {
	Color          color.Color
	Thickness      float64
	CustomDrawFunc []CustomDrawFunc
	BodyOptions    ObjectBodyOptions
}

ObjectOptions for creating a new Object

type World

type World struct {
	Name      string
	Bounds    pixel.Rect
	FrameRate int
	Space     *chipmunk.Space
	RunFunc   func(*pixelgl.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(object 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) 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
		pixelgl.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