public override void Step(IEnumerable <object> data) { base.Step(data); // if (MovableShapes.Count(a => !(a is Stroller || a is Tracker)) == 0) { FeedMap(Extensions.Random.Next(10) + 5); } // CalculateCollisions(); }
public void FeedMap(int TargetAmount) { bool permanentAdded = false; for (int i = 0; i < TargetAmount; i++) { // Initializing Block Block block; var r = Extensions.Random.Next(5); //var r = 0; if (r == 0) { block = new Square(this, TeamColor.Mustard); } else if (r == 1) { block = new Circle(this, TeamColor.LightGreen); } else if (r == 2) { block = new Triangle(this, TeamColor.IndianRed); } else if (r == 3) { block = new Tracker(this, TeamColor.HotPink); } else if (r == 4 && !PermanentAdded) { permanentAdded = true; block = new Stroller(this, TeamColor.White); } else { block = new Square(this, TeamColor.Mustard); } // Randomizing Position and Angle var blockSize = new SizeF((Int32)(Map.SquareSize * 1.2f), (Int32)(Map.SquareSize * 1.2f)); Single xPos = -1, yPos = -1; while (xPos < 0 || xPos > Map.Bounds.Width - blockSize.Width) { xPos = (Single)(Extensions.Random.NextDouble() * Map.Bounds.Width); } while (yPos < 0 || yPos > Map.Bounds.Height - blockSize.Height) { yPos = (Single)(Extensions.Random.NextDouble() * Map.Bounds.Height); } var angle = (Single)(Extensions.Random.NextDouble() * Math.PI * 2); var spin = (Single)(Extensions.Random.NextDouble() * Math.PI * 2); // Defining Properties block.Angle = angle; block.Spin = spin; if (block is Tracker || block is Stroller) { var triangleSize = (Single)(blockSize.Width * (Extensions.Random.NextDouble() + .5)); block.Bounds = new RectangleF(xPos, yPos, (Single)(Math.Sqrt(Math.Pow(triangleSize, 2) - Math.Pow(triangleSize / 2, 2))), triangleSize); block.Speed = (Single)(Extensions.Random.NextDouble() * .00003) + .00003f; } else { if (block is Triangle) { block.Bounds = new RectangleF(xPos, yPos, blockSize.Width, (Single)(Math.Sqrt(Math.Pow(blockSize.Width, 2) - Math.Pow(blockSize.Width / 2, 2)))); } else { block.Bounds = new RectangleF(xPos, yPos, blockSize.Width, blockSize.Height); } block.Speed = (Single)(Extensions.Random.NextDouble() * .00001f) + .00001f; block.Rotation = (Single)(Extensions.Random.NextDouble() * .0005) + .0005f; } if (Extensions.Random.Next(2) == 0) { block.Rotation *= -1; } // MovableShapes.Add(block); } // Avoiding post-spawn of permanent ships PermanentAdded = permanentAdded; }