Fully implement the bearing based movement
Instant, and without limit, for now
This commit is contained in:
parent
0fbad15c01
commit
6461b51c5c
7 changed files with 105 additions and 82 deletions
|
@ -77,7 +77,7 @@ type Command struct {
|
|||
|
||||
// Used for CommandMove
|
||||
Bearing float64 `json:"bearing"` // The direction to move in degrees
|
||||
Duration int64 `json:"duration"` // The duration of the move in seconds
|
||||
Duration float64 `json:"duration"` // The duration of the move in seconds
|
||||
}
|
||||
|
||||
// ================
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/mdiluz/rove/pkg/game"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -80,6 +81,9 @@ func TestHandleCommands(t *testing.T) {
|
|||
// Spawn the rover rover for the account
|
||||
_, inst, err := s.SpawnRoverForAccount(a.Id)
|
||||
|
||||
pos, err := s.world.RoverPosition(inst)
|
||||
assert.NoError(t, err, "Couldn't get rover position")
|
||||
|
||||
data := CommandsData{
|
||||
Id: a.Id.String(),
|
||||
Commands: []Command{
|
||||
|
@ -106,9 +110,11 @@ func TestHandleCommands(t *testing.T) {
|
|||
t.Errorf("got false for /commands")
|
||||
}
|
||||
|
||||
if _, err := s.world.GetPosition(inst); err != nil {
|
||||
t.Error("Couldn't get position for the rover rover")
|
||||
}
|
||||
attrib, err := s.world.RoverAttributes(inst)
|
||||
assert.NoError(t, err, "Couldn't get rover attribs")
|
||||
|
||||
// TODO: Check position is correct
|
||||
pos2, err := s.world.RoverPosition(inst)
|
||||
assert.NoError(t, err, "Couldn't get rover position")
|
||||
pos.Add(game.Vector{X: 0.0, Y: attrib.Speed * 1}) // Should have moved north by the speed and duration
|
||||
assert.Equal(t, pos, pos2, "Rover should have moved by bearing")
|
||||
}
|
||||
|
|
|
@ -163,9 +163,8 @@ func (s *Server) wrapHandler(method string, handler Handler) func(w http.Respons
|
|||
|
||||
// SpawnRoverForAccount spawns the rover rover for an account
|
||||
func (s *Server) SpawnRoverForAccount(accountid uuid.UUID) (game.Vector, uuid.UUID, error) {
|
||||
inst := uuid.New()
|
||||
s.world.SpawnRover(inst)
|
||||
if pos, err := s.world.GetPosition(inst); err != nil {
|
||||
inst := s.world.SpawnRover()
|
||||
if pos, err := s.world.RoverPosition(inst); err != nil {
|
||||
return game.Vector{}, uuid.UUID{}, fmt.Errorf("No position found for created rover")
|
||||
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue