2018-09-26 17:04:46 +00:00
|
|
|
package doodads
|
|
|
|
|
|
|
|
import (
|
2019-12-23 02:21:58 +00:00
|
|
|
"git.kirsle.net/go/render"
|
2018-09-26 17:04:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Actor is a reusable run-time drawing component used in Doodle. Actors are an
|
|
|
|
// active instance of a Doodad which have a position, velocity, etc.
|
|
|
|
type Actor interface {
|
|
|
|
ID() string
|
|
|
|
|
|
|
|
// Position and velocity, not saved to disk.
|
|
|
|
Position() render.Point
|
|
|
|
Velocity() render.Point
|
|
|
|
Size() render.Rect
|
|
|
|
Grounded() bool
|
|
|
|
SetGrounded(bool)
|
|
|
|
|
2019-05-29 04:43:30 +00:00
|
|
|
// Actor's elected hitbox set by their script.
|
2019-06-09 00:02:28 +00:00
|
|
|
// SetHitbox(x, y, w, h int)
|
|
|
|
// Hitbox() render.Rect
|
2019-05-29 04:43:30 +00:00
|
|
|
|
2018-09-26 17:04:46 +00:00
|
|
|
// Movement commands.
|
|
|
|
MoveBy(render.Point) // Add {X,Y} to current Position.
|
|
|
|
MoveTo(render.Point) // Set current Position to {X,Y}.
|
|
|
|
}
|
|
|
|
|
2019-12-31 02:13:28 +00:00
|
|
|
// GetBoundingRect computes the full pairs of points for the bounding box of
|
|
|
|
// the actor.
|
|
|
|
//
|
|
|
|
// The X,Y coordinates are the position in the level of the actor,
|
|
|
|
// The W,H are the size of the actor's drawn box.
|
2018-09-26 17:04:46 +00:00
|
|
|
func GetBoundingRect(d Actor) render.Rect {
|
|
|
|
var (
|
|
|
|
P = d.Position()
|
|
|
|
S = d.Size()
|
|
|
|
)
|
|
|
|
return render.Rect{
|
|
|
|
X: P.X,
|
|
|
|
Y: P.Y,
|
|
|
|
W: S.W,
|
|
|
|
H: S.H,
|
|
|
|
}
|
|
|
|
}
|
2019-06-09 00:02:28 +00:00
|
|
|
|
2019-12-31 02:13:28 +00:00
|
|
|
// GetBoundingRectHitbox returns the bounding rect of the Actor taking into
|
|
|
|
// account their self-declared collision hitbox.
|
|
|
|
//
|
|
|
|
// The rect returned has the X,Y coordinate set to the actor's position, plus
|
|
|
|
// the X,Y of their hitbox, if any.
|
|
|
|
//
|
|
|
|
// The W,H of the rect is the W,H of their declared hitbox.
|
|
|
|
//
|
|
|
|
// If the actor has NOT declared its hitbox, this function returns exactly the
|
|
|
|
// same way as GetBoundingRect() does.
|
|
|
|
func GetBoundingRectHitbox(d Actor, hitbox render.Rect) render.Rect {
|
|
|
|
rect := GetBoundingRect(d)
|
|
|
|
if !hitbox.IsZero() {
|
|
|
|
rect.X += hitbox.X
|
|
|
|
rect.Y += hitbox.Y
|
|
|
|
rect.W = hitbox.W
|
|
|
|
rect.H = hitbox.H
|
|
|
|
}
|
|
|
|
return rect
|
|
|
|
}
|
|
|
|
|
2019-06-09 00:02:28 +00:00
|
|
|
// GetBoundingRectWithHitbox is like GetBoundingRect but adjusts it for the
|
|
|
|
// relative hitbox of the actor.
|
|
|
|
// func GetBoundingRectWithHitbox(d Actor, hitbox render.Rect) render.Rect {
|
|
|
|
// rect := GetBoundingRect(d)
|
|
|
|
// rect.W = hitbox.W
|
|
|
|
// rect.H = hitbox.H
|
|
|
|
// return rect
|
|
|
|
// }
|