Esempio n. 1
0
        public override void Update(float deltaTime)
        {
            float s = speed.MinMax(MAX_SPEED, MIN_SPEED);

            if (pressedKeys.Contains(Keys.Up) ||
                pressedKeys.Contains(Keys.W))
            {
                direction.Y = -1 * s;
            }
            else if (pressedKeys.Contains(Keys.Down) ||
                     pressedKeys.Contains(Keys.S))
            {
                direction.Y = 1 * s;
            }
            else
            {
                direction.Y = 0;
            }

            if (pressedKeys.Contains(Keys.Left) ||
                pressedKeys.Contains(Keys.A))
            {
                direction.X = -1 * s;
            }
            else if (pressedKeys.Contains(Keys.Right) ||
                     pressedKeys.Contains(Keys.D))
            {
                direction.X = 1 * s;
            }
            else
            {
                direction.X = 0;
            }


            X += direction.X * deltaTime;
            Y += direction.Y * deltaTime;
            KeepInsideOwner();


            CheckForPowerUps();
            if (CheckForCollision())
            {
                if (!shieldActivated)
                {
                    Explosion.Burst(Parent, Center, 1000, 30, 450, 2, 2, -1);
                    Explosion.Burst(Parent, TopLeft, 500, 30, 400, 1, 3, -1);
                    Explosion.Burst(Parent, TopRight, 500, 30, 400, 1, 3, -1);
                    Explosion.Burst(Parent, BottomLeft, 500, 30, 400, 1, 3, -1);
                    Explosion.Burst(Parent, BottomRight, 500, 30, 400, 1, 3, -1);
                    Delete();
                }
            }
            else if (pressedKeys.Contains(Keys.Space) ||
                     pressedKeys.Contains(Keys.Enter))
            {
                Shoot();
            }
        }
 public void Explode()
 {
     if (rnd.NextDouble() > 0.95)
     {
         PowerUp pup = new PowerUp();
         pup.Center = Center;
         Root.AddChild(pup);
     }
     Explosion.Burst(Parent, Center);
     Delete();
 }