public override void Update(GameTime gameTime) { base.Update(gameTime); foreach (GameObject obj in children) { SpriteGameObject c = obj as SpriteGameObject; if ((c.Velocity.X < 0 && c.Position.X + c.Width < 0) || (c.Velocity.X > 0 && c.Position.X > GameEnvironment.Screen.X)) { Remove(c); SpriteGameObject cloud = new HalfLockedSpriteGameObject("Backgrounds/spr_cloud_" + (GameEnvironment.Random.Next(5) + 1), scalingFactor: scalingFactor); cloud.Velocity = new Vector2((float)((GameEnvironment.Random.NextDouble() * 2) - 1) * 20, 0); float cloudHeight = ((float)GameEnvironment.Random.NextDouble() * (layerHeight - cloud.Height * 1.3f) + minHeight - 10); if (cloud.Velocity.X < 0) { cloud.Position = new Vector2(GameEnvironment.Screen.X, cloudHeight); } else { cloud.Position = new Vector2(-cloud.Width, cloudHeight); } Add(cloud); return; } } }
public Clouds(int layer = 0, string id = "", int layerHeight = 0, int minHeight = 0, int scalingFactor = 7) : base(layer, id) { this.scalingFactor = scalingFactor; this.layerHeight = layerHeight; this.minHeight = minHeight; for (int i = 0; i < 3; i++) { if (layerHeight == 0) { SpriteGameObject cloud = new HalfLockedSpriteGameObject("Backgrounds/spr_cloud_" + (GameEnvironment.Random.Next(5) + 1), 2, scalingFactor: scalingFactor); cloud.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.X - cloud.Width / 2, (float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.Y - cloud.Height / 2); cloud.Velocity = new Vector2((float)((GameEnvironment.Random.NextDouble() * 2) - 1) * 20, 0); Add(cloud); } else { SpriteGameObject cloud = new HalfLockedSpriteGameObject("Backgrounds/spr_cloud_" + (GameEnvironment.Random.Next(5) + 1), 2, scalingFactor: scalingFactor); cloud.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.X - cloud.Width / 2, (float)GameEnvironment.Random.NextDouble() * (layerHeight - cloud.Height * 1.3f) + minHeight - 10); cloud.Velocity = new Vector2((float)((GameEnvironment.Random.NextDouble() * 2) - 1) * 20, 0); Add(cloud); } } }
public void newMountainLayer(GameObjectList backgrounds, int amount, int scalingFactor, int layer) { int height = 0; for (int i = 0; i < amount; i++) { SpriteGameObject mountain = new HalfLockedSpriteGameObject("Backgrounds/spr_mountain_" + (GameEnvironment.Random.Next(2) + 1), layer + 1, scalingFactor: scalingFactor); mountain.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.X - mountain.Width / 2, GameEnvironment.Screen.Y - mountain.Height - scalingFactor * 5); backgrounds.Add(mountain); height = mountain.Height; } if (GameEnvironment.Random.Next(2) == 0) { Clouds clouds = new Clouds(layer, "", (int)(height / 1.5), GameEnvironment.Screen.Y - height - scalingFactor * 5, scalingFactor: scalingFactor + 5); backgrounds.Add(clouds); } }