public void UpdateSprite(Game1 game, GameTime gameTime, int max_X, int max_Y, Sound1 so) { List<MovingObject> cleanup = new List<MovingObject>(); Vector2 old_position; if (!game.isGameOver()) { foreach (MovingObject a in SpriteList) { // Move the sprite by speed, scaled by elapsed time. // First sprite is the player sprite if (!a.first) { old_position = a.position; a.position += a.speed * (float)gameTime.ElapsedGameTime.TotalSeconds; if (a.immune > 0) a.immune--; foreach (MovingObject b in SpriteList) { if (a != b) { if (Intersects(a, b)) { if (b.first) { if (a.immune == 0) { game.PlayerHit(); a.speed = new Vector2(100 + (50.0f * (float)Math.Sin(MathHelper.ToRadians((float)(360 * RandGen.NextDouble())))), 100 + (50.0f * (float)Math.Sin(MathHelper.ToRadians((float)(360 * RandGen.NextDouble()))))); ; a.immune = 30; } } else { Vector2 tmp = a.speed; a.speed = b.speed; b.speed = tmp; a.position = old_position; } } } } int MaxX = max_X - sprite5.Width; int MinX = 0; int MaxY = max_Y - sprite5.Height; int MinY = 0; //a.rotation += a.rotation_speed; // Check for bounce. if ((a.position.X - sprite5.Width) > MaxX) { Vector2 dir; dir = Vector2.Normalize(a.speed); a.speed.X = 100 + ((float)RandGen.NextDouble() * 100.0f); a.speed.X *= -dir.X; a.position.X = MaxX + sprite5.Width; } else if (a.position.X < MinX) { Vector2 dir; dir = Vector2.Normalize(a.speed); a.speed.X = 100 + ((float)RandGen.NextDouble() * 100.0f); a.speed.X *= -dir.X; a.position.X = MinX; } if ((a.position.Y - sprite5.Height) > MaxY) { Vector2 dir; dir = Vector2.Normalize(a.speed); a.speed.Y = 100 + ((float)RandGen.NextDouble() * 100.0f); a.speed.Y *= -dir.Y; a.position.Y = MaxY + sprite5.Height; } else if (a.position.Y < MinY) { Vector2 dir; dir = Vector2.Normalize(a.speed); a.speed.Y = 100 + ((float)RandGen.NextDouble() * 100.0f); a.speed.Y *= -dir.Y; a.position.Y = MinY; } } } } foreach (MovingObject a in SpriteList2) { // Move the sprite by speed, scaled by elapsed time. a.position += a.speed * (float)gameTime.ElapsedGameTime.TotalSeconds; int MaxX = max_X - sprite7.Width; int MinX = 0; int MaxY = max_Y - sprite7.Height; int MinY = 0; a.rotation += 0.001f; // Check for bounce. if ((a.position.X - sprite7.Width) > MaxX) { Vector2 dir; dir = Vector2.Normalize(a.speed); a.speed.X = 10 + ((float)RandGen.NextDouble() * 20.0f); a.speed.X *= -dir.X; a.position.X = MaxX + sprite7.Width; } else if (a.position.X < MinX) { Vector2 dir; dir = Vector2.Normalize(a.speed); a.speed.X = 10 + ((float)RandGen.NextDouble() * 20.0f); a.speed.X *= -dir.X; a.position.X = MinX; } if ((a.position.Y - sprite7.Height) > MaxY) { Vector2 dir; dir = Vector2.Normalize(a.speed); a.speed.Y = 10 + ((float)RandGen.NextDouble() * 20.0f); a.speed.Y *= -dir.Y; a.position.Y = MaxY + sprite7.Height; } else if (a.position.Y < MinY) { Vector2 dir; dir = Vector2.Normalize(a.speed); a.speed.Y = 10 + ((float)RandGen.NextDouble() * 20.0f); a.speed.Y *= -dir.Y; a.position.Y = MinY; } if (!game.isGameOver() && Intersects(SpriteList.First(), a)) { if (!game.isPlayerImmune()) { game.IncrementFlowerCount(); cleanup.Add(a); } } } if (!game.isGameOver()) { foreach (MovingObject a in cleanup) { so.PlayFlowerPick(game); SpriteList2.Remove(a); } } }