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.
39 lines
649 B
Go
39 lines
649 B
Go
package physics_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/physics"
|
|
)
|
|
|
|
func TestLerp(t *testing.T) {
|
|
var tests = []struct {
|
|
Inputs []float64
|
|
Expect float64
|
|
}{
|
|
{
|
|
Inputs: []float64{0, 1, 0.75},
|
|
Expect: 0.75,
|
|
},
|
|
{
|
|
Inputs: []float64{0, 100, 0.5},
|
|
Expect: 50.0,
|
|
},
|
|
{
|
|
Inputs: []float64{10, 75, 0.3},
|
|
Expect: 29.5,
|
|
},
|
|
{
|
|
Inputs: []float64{30, 2, 0.75},
|
|
Expect: 9,
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
result := physics.Lerp(test.Inputs[0], test.Inputs[1], test.Inputs[2])
|
|
if result != test.Expect {
|
|
t.Errorf("Lerp(%+v) expected %f but got %f", test.Inputs, test.Expect, result)
|
|
}
|
|
}
|
|
}
|