private void clearTunnel(Tile start, Tile goal) { var goalPosition = level.GetPosition(goal); var tile = start; var currentDirection = (goalPosition - level.GetPosition(tile)).Direction; open(tile); while (tile != goal) { var vectorToGoal = goalPosition - level.GetPosition(tile); var directionToGoal = vectorToGoal.Direction; var distance = vectorToGoal.LengthSquared; var variationFactor = (1 - 1 / (distance.NumericValue * 0.2f + 1)); var variation = variationFactor * 60; currentDirection += StaticRandom.Float(-variation, variation).Degrees(); currentDirection = currentDirection.TurnedTowards(directionToGoal, 0.3f / variationFactor); var directionToStep = currentDirection.Hexagonal(); var newTile = tile.Neighbour(directionToStep); if (!newTile.IsValid) { newTile = tile.Neighbour(directionToGoal.Hexagonal()); currentDirection = directionToGoal; } tile = newTile; open(tile); spray(tile.Neighbours, open, 0.1); } }
public Position2 RandomPointInsideUniform() { var uv = new Vector2(StaticRandom.Float(), StaticRandom.Float()); var isTriangle2 = uv.X + uv.Y > 1; var needsToBeTriangle2 = StaticRandom.Float() < this.area2 / this.Area; if (isTriangle2 != needsToBeTriangle2) { uv = new Vector2(1) - uv; } return(this.uvToPoint(uv)); }
private void generateIntersectionsOnCircle(int count, float radius) { var angleBetweenIntersections = 360.Degrees() / count; var levelRadius = radius * Constants.Game.World.HexagonWidth.U(); var startAngle = Direction2.FromDegrees(StaticRandom.Float(360)); var angleVariance = angleBetweenIntersections.Radians * 0.3f; for (var i = 0; i < count; i++) { var angle = startAngle + angleBetweenIntersections * i + StaticRandom.Float(-angleVariance, angleVariance).Radians(); var point = new Position2() + angle.Vector * (levelRadius * StaticRandom.Float(0.8f, 1)); intersections.Add(point); } }
private Unit divide(Unit p0, Unit p1, out Unit streetWidth) { if (p0 > p1) { Do.Swap(ref p0, ref p1); } var d = p1 - p0; var sw = d.NumericValue.Sqrted() * 0.3f; streetWidth = Math.Floor(sw).Clamped(1.5f, 5).U(); var ret = p0 + d * StaticRandom.Float(0.3f, 0.7f); var offset = streetWidth + minBlockSize * 0.5f; var ret2 = ret.NumericValue.Clamped((p0 + offset).NumericValue, (p1 - offset).NumericValue).U(); return(ret2); }
public Position2 RandomPoint() { return(Position2.Lerp(this.P0, this.P1, StaticRandom.Float())); }
public Position2 RandomPointInside() { var uv = new Vector2(StaticRandom.Float(), StaticRandom.Float()); return(this.uvToPoint(uv)); }