From 70f041ae5d16686b65ffb77c9528b216d19c4310 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Sat, 1 Aug 2020 11:09:15 +0100 Subject: [PATCH] Spawn rover parts in the world --- pkg/rove/worldgen.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/rove/worldgen.go b/pkg/rove/worldgen.go index dd864b8..a1593c6 100644 --- a/pkg/rove/worldgen.go +++ b/pkg/rove/worldgen.go @@ -35,6 +35,7 @@ func NewNoiseWorldGen(seed int64) WorldGen { const ( terrainNoiseScale = 15 rockNoiseScale = 3 + partsNoiseScale = 2 ) // GetTile returns the chosen tile at a location @@ -52,12 +53,21 @@ func (g *NoiseWorldGen) GetTile(v maths.Vector) roveapi.Tile { // GetObject returns the chosen object at a location func (g *NoiseWorldGen) GetObject(v maths.Vector) (obj Object) { - o := g.noise.Eval2(float64(v.X)/rockNoiseScale, float64(v.Y)/rockNoiseScale) + r := g.noise.Eval2(float64(v.X)/rockNoiseScale, float64(v.Y)/rockNoiseScale) switch { - case o > 0.6: + // Prioritise rocks + case r > 0.6: obj.Type = roveapi.Object_RockLarge - case o > 0.5: + case r > 0.5: obj.Type = roveapi.Object_RockSmall + + default: + // Otherwise, try some rover parts + p := g.noise.Eval2(float64(v.X)/partsNoiseScale, float64(v.Y)/partsNoiseScale) + switch { + case p > 0.8: + obj.Type = roveapi.Object_RoverParts + } } // Very rarely spawn a dormant rover