Noah Petherbridge
866e5e7fd8
* Remove several unused functions in doodad.Drawing (velocity, acceleration, grounded, etc.) - uix.Actor is where these are actually managed. * In the JavaScript API, setTimeout() and setInterval() will translate the milliseconds from wallclock time into a fixed number of game ticks to match the target frame rate for better deterministic timing.
55 lines
1.0 KiB
Go
55 lines
1.0 KiB
Go
package doodads
|
|
|
|
import (
|
|
"git.kirsle.net/go/render"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// 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
|
|
hitbox render.Rect
|
|
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.
|
|
func NewDrawing(id string, doodad *Doodad) *Drawing {
|
|
if id == "" {
|
|
id = uuid.Must(uuid.NewUUID()).String()
|
|
}
|
|
return &Drawing{
|
|
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.
|
|
//
|
|
// NOTE: used only by unit test.
|
|
func (d *Drawing) MoveTo(to render.Point) {
|
|
d.point = to
|
|
}
|