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.
37 lines
818 B
Go
37 lines
818 B
Go
package uix
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
|
"git.kirsle.net/apps/doodle/pkg/shmem"
|
|
)
|
|
|
|
// LinkStart initializes the Link tool.
|
|
func (w *Canvas) LinkStart() {
|
|
w.Tool = drawtool.LinkTool
|
|
w.linkFirst = nil
|
|
}
|
|
|
|
// LinkAdd adds an actor to be linked in the Link tool.
|
|
func (w *Canvas) LinkAdd(a *Actor) error {
|
|
if w.linkFirst == nil {
|
|
// First click, hold onto this actor.
|
|
w.linkFirst = a
|
|
shmem.Flash("Doodad '%s' selected, click the next Doodad to link it to",
|
|
a.Doodad().Title,
|
|
)
|
|
} else {
|
|
// Second click, call the OnLinkActors handler with the two actors.
|
|
if w.OnLinkActors != nil {
|
|
w.OnLinkActors(w.linkFirst, a)
|
|
} else {
|
|
return errors.New("Canvas.LinkAdd: no OnLinkActors handler is ready")
|
|
}
|
|
|
|
// Reset the link state.
|
|
w.linkFirst = nil
|
|
}
|
|
return nil
|
|
}
|