Documentation ¶
Overview ¶
Package physics defines physical components and transformations.
Index ¶
- func Halt(b *Body, dir pixel.Vec) bool
- type Acc
- type AirborneSubscriber
- type Body
- func (b *Body) AddAirborneSubscriber(s AirborneSubscriber)
- func (b *Body) AddCollisionSubscriber(s CollisionSubscriber)
- func (b Body) Bounds() *Rect
- func (b *Body) Down() pixel.Vec
- func (b *Body) HandleCollision(event *CollisionEvent)
- func (b *Body) Left() pixel.Vec
- func (b *Body) Right() pixel.Vec
- func (b *Body) Speed() float64
- func (b *Body) SpeedAlong(direction pixel.Vec) float64
- func (b *Body) Up() pixel.Vec
- func (b *Body) Update(ptx *PhysicsContext)
- type CollisionComponent
- type CollisionEvent
- type CollisionSubscriber
- type CollisionSystem
- type Dec
- type Direction
- type GravityComponent
- type MovementComponent
- type PhysicsContext
- type Rect
- type ReferenceFrame
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AirborneSubscriber ¶
type AirborneSubscriber = func()
type Body ¶
type Body struct { Acc pixel.Vec Vel pixel.Vec Pos pixel.Vec Rot float64 Size *Rect Collision *CollisionComponent Movement *MovementComponent Gravity *GravityComponent // contains filtered or unexported fields }
Body represents a physical object.
The object has a position which is affected each game turn by its velocity and Gravity. TODO: Add more.
func (*Body) AddAirborneSubscriber ¶
func (b *Body) AddAirborneSubscriber(s AirborneSubscriber)
func (*Body) AddCollisionSubscriber ¶
func (b *Body) AddCollisionSubscriber(s CollisionSubscriber)
func (*Body) HandleCollision ¶
func (b *Body) HandleCollision(event *CollisionEvent)
func (*Body) Update ¶
func (b *Body) Update(ptx *PhysicsContext)
type CollisionComponent ¶
type CollisionComponent struct{}
func (*CollisionComponent) Update ¶
func (c *CollisionComponent) Update(ptx *PhysicsContext, body *Body)
type CollisionEvent ¶
type CollisionEvent struct { // Whether the collider collided with the left side of the target // object. LeftSide bool // Whether the collider collided with the right side of the target // object. RightSide bool // Whether the collider collided with the top side of the target // object. TopSide bool // Whether the collider collided with the bottom side of the target // object. BottomSide bool // The amount the collider needs to adjust its X position to stop // colliding with the target object. ResolveX float64 // The amount the collider needs to adjust its Y position to stop // colliding with the target object. ResolveY float64 // The direction the collider was moving when the collision occurred. Vec pixel.Vec // contains filtered or unexported fields }
func (*CollisionEvent) Resolve ¶
func (e *CollisionEvent) Resolve(body *Body)
type CollisionSubscriber ¶
type CollisionSubscriber = func(CollisionEvent)
type CollisionSystem ¶
type CollisionSystem struct { BoundingBox *Rect // contains filtered or unexported fields }
func (*CollisionSystem) AddTerrain ¶
func (cs *CollisionSystem) AddTerrain(rect *Rect)
func (*CollisionSystem) GetBoundingBoxCollision ¶
func (cs *CollisionSystem) GetBoundingBoxCollision(rect *Rect) *CollisionEvent
Returns a CollisionEvent describing rect's collision with the BoundingBox, if any.
func (*CollisionSystem) GetCollision ¶
func (cs *CollisionSystem) GetCollision(a, b *Rect) *CollisionEvent
Returns a CollisionEvent describing a's collision with b, if any.
func (*CollisionSystem) GetTerrainCollision ¶
func (cs *CollisionSystem) GetTerrainCollision(rect *Rect) *CollisionEvent
Returns a CollisionEvent describing rect's collision with map terrain objects, if any.
type GravityComponent ¶
type GravityComponent struct { // The amount of change to a Body's velocity per frame. // For example, to accelerate an object at 10 units squared per // second at 60 fps, use Acceleration = 10 / 60. Acceleration float64 }
GravityComponent applies a constant acceleration to a Body.
Acceleration is applied relative the given Body's reference frame.
func (GravityComponent) Update ¶
func (c GravityComponent) Update(_ *PhysicsContext, body *Body)
type MovementComponent ¶
type MovementComponent struct{}
MovementComponent updates a Body's position accoriding to it velocity.
func (MovementComponent) Update ¶
func (c MovementComponent) Update(_ *PhysicsContext, body *Body)
type PhysicsContext ¶
type PhysicsContext struct {
CollisionSystem *CollisionSystem
}
type ReferenceFrame ¶
func (*ReferenceFrame) Down ¶
func (rf *ReferenceFrame) Down() pixel.Vec
func (*ReferenceFrame) Left ¶
func (rf *ReferenceFrame) Left() pixel.Vec
func (*ReferenceFrame) Right ¶
func (rf *ReferenceFrame) Right() pixel.Vec
func (*ReferenceFrame) Up ¶
func (rf *ReferenceFrame) Up() pixel.Vec
Click to show internal directories.
Click to hide internal directories.