2019-04-10 02:17:56 +00:00
|
|
|
package doodads
|
|
|
|
|
|
|
|
import (
|
2019-12-23 02:21:58 +00:00
|
|
|
"git.kirsle.net/go/render"
|
2019-12-22 22:11:01 +00:00
|
|
|
"github.com/google/uuid"
|
2019-04-10 02:17:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Drawing is a Doodad Actor that is based on drawings made inside the game.
|
|
|
|
type Drawing struct {
|
|
|
|
Doodad *Doodad
|
|
|
|
|
|
|
|
id string
|
|
|
|
point render.Point
|
|
|
|
velocity render.Point
|
|
|
|
accel int
|
|
|
|
size render.Rect
|
2019-05-29 04:43:30 +00:00
|
|
|
hitbox render.Rect
|
2019-04-10 02:17:56 +00:00
|
|
|
grounded bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewDrawing creates a Drawing actor based on a Doodad drawing. If you pass
|
|
|
|
// an empty ID string, it will make a random UUIDv4 ID.
|
2020-04-05 04:00:32 +00:00
|
|
|
func NewDrawing(id string, doodad *Doodad) *Drawing {
|
2019-04-10 02:17:56 +00:00
|
|
|
if id == "" {
|
2021-08-12 03:40:31 +00:00
|
|
|
id = uuid.Must(uuid.NewUUID()).String()
|
2019-04-10 02:17:56 +00:00
|
|
|
}
|
2020-04-05 04:00:32 +00:00
|
|
|
return &Drawing{
|
2019-04-10 02:17:56 +00:00
|
|
|
id: id,
|
|
|
|
Doodad: doodad,
|
|
|
|
size: doodad.Rect(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ID to get the Drawing ID.
|
|
|
|
func (d *Drawing) ID() string {
|
|
|
|
return d.id
|
|
|
|
}
|
|
|
|
|
|
|
|
// Position returns the Drawing's position.
|
|
|
|
func (d *Drawing) Position() render.Point {
|
|
|
|
return d.point
|
|
|
|
}
|
|
|
|
|
|
|
|
// Size returns the Drawing's size.
|
|
|
|
func (d *Drawing) Size() render.Rect {
|
|
|
|
return d.size
|
|
|
|
}
|
|
|
|
|
|
|
|
// MoveTo an absolute world value.
|
2024-04-27 07:10:28 +00:00
|
|
|
//
|
|
|
|
// NOTE: used only by unit test.
|
2019-04-10 02:17:56 +00:00
|
|
|
func (d *Drawing) MoveTo(to render.Point) {
|
|
|
|
d.point = to
|
|
|
|
}
|