Documentation ¶
Index ¶
- func IsIntersecting(rect1 engo.AABB, rect2 engo.AABB) bool
- func MinimumTranslation(rect1 engo.AABB, rect2 engo.AABB) engo.Point
- type CollisionComponent
- type CollisionFace
- type CollisionGroup
- type CollisionMessage
- type CollisionSystem
- type Collisionable
- type NotCollisionComponent
- type NotCollisionable
- type SpaceComponent
- func (sc SpaceComponent) AABB() engo.AABB
- func (sc *SpaceComponent) Center() engo.Point
- func (sc SpaceComponent) Contains(p engo.Point) bool
- func (sc SpaceComponent) Corners() (points [4]engo.Point)
- func (c *SpaceComponent) GetSpaceComponent() *SpaceComponent
- func (sc *SpaceComponent) SetCenter(p engo.Point)
- type SpaceFace
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsIntersecting ¶
IsIntersecting tells if two engo.AABBs intersect.
Types ¶
type CollisionComponent ¶
type CollisionComponent struct { // if a.Main & (bitwise) b.Group, items can collide // if a.Main == 0, it will not loop for other items Main, Group CollisionGroup Extra engo.Point Collides CollisionGroup }
CollisionComponent keeps track of the entity's collisions.
Main tells the system to check all collisions against this entity.
Group tells which collision group his entity belongs to.
Extra is the allowed buffer for detecting collisions.
Collides is all the groups this component collides with ORed together
func (*CollisionComponent) GetCollisionComponent ¶
func (c *CollisionComponent) GetCollisionComponent() *CollisionComponent
GetCollisionComponent Provides container classes ability to fulfil the interface and be accessed more simply by systems, eg in AddByInterface Methods
type CollisionFace ¶
type CollisionFace interface {
GetCollisionComponent() *CollisionComponent
}
CollisionFace allows typesafe access to an anonymous CollisionComponent
type CollisionGroup ¶
type CollisionGroup byte
CollisionGroup is intended to be used in bitwise comparisons The user is expected to create a const ( a = 1 << iota \n b \n c etc) for the different kinds of collisions they hope to use
type CollisionMessage ¶
type CollisionMessage struct { Entity collisionEntity To collisionEntity Groups CollisionGroup }
CollisionMessage is sent whenever a collision is detected by the CollisionSystem.
func (CollisionMessage) Type ¶
func (CollisionMessage) Type() string
Type implements the engo.Message interface
type CollisionSystem ¶
type CollisionSystem struct { // Solids, used to tell which collisions should be treated as solid by bitwise comparison. // if a.Main & b.Group & sys.Solids{ Collisions are treated as solid. } Solids CollisionGroup // contains filtered or unexported fields }
CollisionSystem is a system that detects collisions between entities, sends a message if collisions are detected, and updates their SpaceComponent so entities cannot pass through Solids.
func (*CollisionSystem) Add ¶
func (c *CollisionSystem) Add(basic *ecs.BasicEntity, collision *CollisionComponent, space *SpaceComponent)
Add adds an entity to the CollisionSystem. To be added, the entity has to have a basic, collision, and space component.
func (*CollisionSystem) AddByInterface ¶
func (c *CollisionSystem) AddByInterface(i ecs.Identifier)
AddByInterface Provides a simple way to add an entity to the system that satisfies Collisionable. Any entity containing, BasicEntity,CollisionComponent, and SpaceComponent anonymously, automatically does this.
func (*CollisionSystem) Remove ¶
func (c *CollisionSystem) Remove(basic ecs.BasicEntity)
Remove removes an entity from the CollisionSystem.
func (*CollisionSystem) Update ¶
func (c *CollisionSystem) Update(dt float32)
Update checks the entities for collision with eachother. Only Main entities are check for collision explicitly. If one of the entities are solid, the SpaceComponent is adjusted so that the other entities don't pass through it.
type Collisionable ¶
type Collisionable interface { basic.BasicFace CollisionFace SpaceFace }
Collisionable is the required interface for the CollisionSystem.AddByInterface method
type NotCollisionComponent ¶
type NotCollisionComponent struct{}
NotCollisionComponent is used to flag an entity as not in the CollisionSystem even if it has the proper components
func (*NotCollisionComponent) GetNotCollisionComponent ¶
func (n *NotCollisionComponent) GetNotCollisionComponent() *NotCollisionComponent
GetNotCollisionComponent implements the NotCollisionable interface
type NotCollisionable ¶
type NotCollisionable interface {
GetNotCollisionComponent() *NotCollisionComponent
}
NotCollisionable is an interface used to flag an entity as not in the CollisionSystem even if it has the proper components
type SpaceComponent ¶
type SpaceComponent struct { Position engo.Point Width float32 Height float32 Rotation float32 // angle in degrees for the rotation to apply clockwise. }
SpaceComponent keeps track of the position, size, and rotation of entities.
func (SpaceComponent) AABB ¶
func (sc SpaceComponent) AABB() engo.AABB
AABB returns the minimum and maximum point for the given SpaceComponent. It hereby takes into account the rotation of the Component - it may very well be that the Minimum as given by engo.AABB, is smaller than the Position of the object (i.e. when rotated).
This basically returns the "outer rectangle" of the plane defined by the `SpaceComponent`. Since this returns two points, a minimum and a maximum, the "rectangle" resulting from this `AABB`, is not rotated in any way. However, depending on the rotation of the `SpaceComponent`, this `AABB` may be larger than the original `SpaceComponent`.
func (*SpaceComponent) Center ¶
func (sc *SpaceComponent) Center() engo.Point
Center gets the center position of the space component instead of its top-left point (this avoids doing the same math each time in your systems)
func (SpaceComponent) Contains ¶
func (sc SpaceComponent) Contains(p engo.Point) bool
Contains indicates whether or not the given point is within the rectangular plane as defined by this `SpaceComponent`. If it's on the border, it is considered "not within".
func (SpaceComponent) Corners ¶
func (sc SpaceComponent) Corners() (points [4]engo.Point)
Corners returns the location of the four corners of the rectangular plane defined by the `SpaceComponent`, taking into account any possible rotation.
func (*SpaceComponent) GetSpaceComponent ¶
func (c *SpaceComponent) GetSpaceComponent() *SpaceComponent
GetSpaceComponent Provides container classes ability to fulfil the interface and be accessed more simply by systems, eg in AddByInterface Methods
func (*SpaceComponent) SetCenter ¶
func (sc *SpaceComponent) SetCenter(p engo.Point)
SetCenter positions the space component according to its center instead of its top-left point (this avoids doing the same math each time in your systems)
type SpaceFace ¶
type SpaceFace interface {
GetSpaceComponent() *SpaceComponent
}
SpaceFace allows typesafe access to an anonymous SpaceComponent