private void GenerateClouds() { for (int i = 0; i < cloudCount; i++) { clouds[i] = new Cloud { Scale = random.Next (2, 3), Speed = 0.09f }; int tries = 0; int maxTries = 5; do { clouds[i].Position = random.GetRandomVector2 (managerWidth, managerHeight); tries++; if (tries > maxTries) break; } while (IsCollidingWithAnotherCloud (clouds[i])); } }
private Rectangle GetCloudRectangle(Cloud cloud) { return new Rectangle ( (int)cloud.Position.X, (int)cloud.Position.Y, (int)(cloudTexture.Width * cloud.Scale), (int)(cloudTexture.Height * cloud.Scale)); }
private bool IsCollidingWithAnotherCloud(Cloud src) { Rectangle srcRect = GetCloudRectangle (src); for (int i=0; i < clouds.Length; i++) { Cloud dest = clouds[i]; if (dest == null || dest == src) continue; if (GetCloudRectangle (dest).Intersects (srcRect)) return true; } return false; }