Noah Petherbridge
08e65c32b5
* Player character now experiences acceleration and friction when walking around the map! * Actor position and movement had to be converted from int's (render.Point) to float64's to support fine-grained acceleration steps. * Added "physics" package and physics.Vector to be a float64 counterpart for render.Point. Vector is used for uix.Actor.Position() for the sake of movement math. Vector is flattened back to a render.Point for collision purposes, since the levels and hitboxes are pixel-bound. * Refactor the uix.Actor to no longer extend the doodads.Drawing (so it can have a Position that's a Vector instead of a Point). This broke some code that expected `.Doodad` to directly reference the Drawing.Doodad: now you had to refer to it as `a.Drawing.Doodad` which was ugly. Added convenience method .Doodad() for a shortcut. * Moved functions like GetBoundingRect() from doodads package to collision, where it uses its own slimmer Actor interface for just the relevant methods it needs.
93 lines
1.8 KiB
Go
93 lines
1.8 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.NewRandom()).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
|
|
}
|
|
|
|
// Velocity returns the Drawing's velocity.
|
|
func (d *Drawing) Velocity() render.Point {
|
|
return d.velocity
|
|
}
|
|
|
|
// SetVelocity to set the speed.
|
|
func (d *Drawing) SetVelocity(v render.Point) {
|
|
d.velocity = v
|
|
}
|
|
|
|
// Acceleration returns the Drawing's acceleration.
|
|
func (d *Drawing) Acceleration() int {
|
|
return d.accel
|
|
}
|
|
|
|
// SetAcceleration to set the acceleration.
|
|
func (d *Drawing) SetAcceleration(v int) {
|
|
d.accel = v
|
|
}
|
|
|
|
// Size returns the Drawing's size.
|
|
func (d *Drawing) Size() render.Rect {
|
|
return d.size
|
|
}
|
|
|
|
// Grounded returns whether the Drawing is standing on solid ground.
|
|
func (d *Drawing) Grounded() bool {
|
|
return d.grounded
|
|
}
|
|
|
|
// SetGrounded sets the grounded state.
|
|
func (d *Drawing) SetGrounded(v bool) {
|
|
d.grounded = v
|
|
}
|
|
|
|
// MoveBy a relative value.
|
|
func (d *Drawing) MoveBy(by render.Point) {
|
|
d.point.Add(by)
|
|
}
|
|
|
|
// MoveTo an absolute world value.
|
|
func (d *Drawing) MoveTo(to render.Point) {
|
|
d.point = to
|
|
}
|
|
|
|
// Draw the drawing.
|
|
func (d *Drawing) Draw(e render.Engine) {
|
|
|
|
}
|