diff --git a/pkg/atlas/atlas.go b/pkg/atlas/atlas.go index 3181442..1446cad 100644 --- a/pkg/atlas/atlas.go +++ b/pkg/atlas/atlas.go @@ -42,8 +42,12 @@ func NewAtlas(size, chunkSize int) Atlas { // Initialise all the chunks for i := range a.Chunks { + tiles := make([]byte, chunkSize*chunkSize) + for i := 0; i < len(tiles); i++ { + tiles[i] = TileEmpty + } a.Chunks[i] = Chunk{ - Tiles: make([]byte, chunkSize*chunkSize), + Tiles: tiles, } } diff --git a/pkg/game/world.go b/pkg/game/world.go index 488a7bd..aad9a26 100644 --- a/pkg/game/world.go +++ b/pkg/game/world.go @@ -110,7 +110,7 @@ func (w *World) SpawnRover() (uuid.UUID, error) { if tile, err := w.Atlas.GetTile(rover.Attributes.Pos); err != nil { return uuid.Nil, err } else { - if tile == atlas.TileEmpty { + if !atlas.IsBlocking(tile) { break } else { // Try and spawn to the east of the blockage @@ -278,7 +278,10 @@ func (w *World) RadarFromRover(id uuid.UUID) ([]byte, error) { // Add all rovers to the radar for _, r := range w.Rovers { // If the rover is in range - if r.Attributes.Pos.Distance(roverPos) < float64(radarSpan) { + dist := r.Attributes.Pos.Added(roverPos.Negated()) + dist = dist.Abs() + + if dist.X <= r.Attributes.Range && dist.Y <= r.Attributes.Range { relative := r.Attributes.Pos.Added(radarMin.Negated()) index := relative.X + relative.Y*radarSpan radar[index] = atlas.TileRover @@ -400,7 +403,7 @@ func PrintTiles(tiles []byte) { num := int(math.Sqrt(float64(len(tiles)))) for j := num - 1; j >= 0; j-- { for i := 0; i < num; i++ { - fmt.Printf("%d", tiles[i+num*j]) + fmt.Printf("%c", tiles[i+num*j]) } fmt.Print("\n") } diff --git a/pkg/game/world_test.go b/pkg/game/world_test.go index 6267894..cc6ccac 100644 --- a/pkg/game/world_test.go +++ b/pkg/game/world_test.go @@ -135,8 +135,8 @@ func TestWorld_RadarFromRover(t *testing.T) { PrintTiles(radar) // Test all expected values - //assert.Equal(t, atlas.TileRover, radar[1+fullRange]) - //assert.Equal(t, atlas.TileRover, radar[4+4*fullRange]) + assert.Equal(t, atlas.TileRover, radar[1+fullRange]) + assert.Equal(t, atlas.TileRover, radar[4+4*fullRange]) for i := 0; i < 8; i++ { assert.Equal(t, atlas.TileLargeRock, radar[i]) assert.Equal(t, atlas.TileLargeRock, radar[i+(7*9)]) diff --git a/pkg/vector/vector.go b/pkg/vector/vector.go index f6c8215..1b82c5a 100644 --- a/pkg/vector/vector.go +++ b/pkg/vector/vector.go @@ -1,6 +1,10 @@ package vector -import "math" +import ( + "math" + + "github.com/mdiluz/rove/pkg/maths" +) // Vector desribes a 3D vector type Vector struct { @@ -45,3 +49,8 @@ func (v Vector) Multiplied(val int) Vector { func (v Vector) Divided(val int) Vector { return Vector{v.X / val, v.Y / val} } + +// Abs returns an absolute version of the vector +func (v Vector) Abs() Vector { + return Vector{maths.Abs(v.X), maths.Abs(v.Y)} +}