Exemple #1
0
        private void UpdatePowerUps(float deltaTime)
        {
            // para cada powerup, atualizar a posição e a duração dele
            for (int i = 0; i < PowerUps.Count; i++)
            {
                PowerUps[i].Position += PowerUps[i].Velocity;
                if (PowerUps[i].Active)
                {
                    PowerUps[i].Duration -= deltaTime;

                    //se o powerup se tornar inativo, remover os efeitos que ele havia aplicado
                    if (PowerUps[i].Duration <= 0)
                    {
                        PowerUps[i].Active = false;
                        switch (PowerUps[i].Type)
                        {
                        case "speed":
                            Balls.ForEach(ball => ball.Velocity /= 1.5f);
                            break;

                        case "sticky":
                            bool isAnySticky = PowerUps.Any(p => p.Active && p.Type == "sticky");
                            Balls.ForEach(ball => ball.Sticky = isAnySticky);
                            if (!isAnySticky)
                            {
                                Player.Color = new Vector3(1);
                            }
                            break;

                        case "comet":
                            Balls.ForEach(ball =>
                            {
                                ball.Comet = PowerUps.Any(p => p.Active && p.Type == "comet");
                                ball.Color = Color.Aqua.ToVector3();
                            });
                            Ball.Color = Vector3.One;
                            break;

                        case "padIncrease":
                            Player.Size = new Vector2(Player.Size.X / 1.25f, Player.Size.Y);
                            break;

                        case "padDecrease":
                            Player.Size = new Vector2(Player.Size.X / .75f, Player.Size.Y);
                            break;

                        case "confuse":
                            PostProcessor.Confuse = PowerUps.Any(p => p.Active && p.Type == "confuse");
                            break;

                        case "chaos":
                            PostProcessor.Chaos = PowerUps.Any(p => p.Active && p.Type == "chaos");
                            break;
                        }
                    }
                }

                // remover powerups inativos
                if (!PowerUps[i].Active && PowerUps[i].Destroyed)
                {
                    PowerUps.RemoveAt(i);
                }
            }
        }