Ejemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            initialPosition = new Vector2(player.position.X + (player.dimension.X / 2) - (tex.Width / 2) - 10, player.position.Y + 10);
            if (isFlying)
            {
                position += speed;
                float xDiff = (initialPosition.X - 48) - position.X;
                float yDiff = (initialPosition.Y - (speed.Y * 3)) - position.Y;

                if (position.X < 0)
                {
                    explosion.Position = position;
                    explosion.StartAnimation();
                    explodeSound.Play();
                    isReturning      = false;
                    isFlying         = false;
                    speed.X          = Math.Abs(speed.X);
                    position         = initialPosition;
                    score.multiplier = 1;
                    score.shieldScore--;
                }

                if (position.X >= 0 & speed.X < 0 & Math.Abs(xDiff) < ALLOWANCE_AREA & Math.Abs(yDiff) < ALLOWANCE_AREA)
                {
                    isReturning = true;
                    speed.X     = SHIELD_SPEED_X;
                }

                if (position.X >= Shared.stage.X - tex.Width)
                {
                    speed.X = -SHIELD_SPEED_X;
                    hitWallSound.Play();
                }

                if (position.Y <= 0)
                {
                    score.multiplier++;
                    speed.Y = SHIELD_SPEED_Y;
                    hitWallSound.Play();
                }

                if (position.Y + tex.Height >= Shared.stage.Y)
                {
                    score.multiplier++;
                    speed.Y = -SHIELD_SPEED_Y;
                    hitWallSound.Play();
                }
            }
            else
            {
                position    = initialPosition;
                isReturning = false;
                KeyboardState ks = Keyboard.GetState();

                if (ks.IsKeyDown(Keys.Up) && ks.IsKeyDown(Keys.Space))
                {
                    speed.Y  = -SHIELD_SPEED_Y;
                    isFlying = true;
                    shieldThrowSound.Play();
                }
                else if (ks.IsKeyDown(Keys.Down) && ks.IsKeyDown(Keys.Space))
                {
                    speed.Y  = SHIELD_SPEED_Y;
                    isFlying = true;
                    shieldThrowSound.Play();
                }
                else if (ks.IsKeyDown(Keys.Space))
                {
                    speed.Y  = 0;
                    isFlying = true;
                    shieldThrowSound.Play();
                }
            }

            if (isReturning)
            {
                score.multiplier = 1;
                float xDiff = (initialPosition.X - 48) - position.X;
                float yDiff = (initialPosition.Y - (speed.Y * 3)) - position.Y;

                position.X += xDiff * 0.2f;
                position.Y += yDiff * 0.2f;

                //When the shield gets closer, set the position to initial position
                if (Math.Abs(initialPosition.X - position.X) < 9f)
                {
                    isFlying    = false;
                    isReturning = false;
                    getShieldSound.Play();
                }
            }

            base.Update(gameTime);
        }
Ejemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            foreach (var enemy in enemyList)
            {
                if (enemy.Visible)
                {
                    //shield is going right and touching left side of the enemy
                    if (shield.speed.X > 0 &&
                        shield.getBound().Right + shield.speed.X > enemy.getBound().Left&&
                        shield.getBound().Left < enemy.getBound().Left&&
                        shield.getBound().Bottom > enemy.getBound().Top&&
                        shield.getBound().Top < enemy.getBound().Bottom)
                    {
                        shield.speed.X = -shield.speed.X;
                        score.score   += (score.multiplier * enemy.enemyScore);
                        score.multiplier++;
                        enemy.Visible      = false;
                        explosion.Position = enemy.position;
                        explosion.StartAnimation();
                        hitSound.Play();
                        explodeSound.Play();
                    }

                    //shield is going left and touching right side of the enemy
                    if (shield.speed.X < 0 &&
                        shield.getBound().Left + shield.speed.X < enemy.getBound().Right&&
                        shield.getBound().Right > enemy.getBound().Right&&
                        shield.getBound().Bottom > enemy.getBound().Top&&
                        shield.getBound().Top < enemy.getBound().Bottom)
                    {
                        shield.speed.X = -shield.speed.X;
                        score.score   += (score.multiplier * enemy.enemyScore);
                        score.multiplier++;
                        enemy.Visible      = false;
                        explosion.Position = enemy.position;
                        explosion.StartAnimation();
                        hitSound.Play();
                        explodeSound.Play();
                    }

                    //shield is going down and touching top side of the enemy
                    if (shield.speed.Y > 0 &&
                        shield.getBound().Bottom + shield.speed.Y > enemy.getBound().Top&&
                        shield.getBound().Top < enemy.getBound().Top&&
                        shield.getBound().Right > enemy.getBound().Left&&
                        shield.getBound().Left < enemy.getBound().Right)
                    {
                        shield.speed.Y = -shield.speed.Y;
                        score.score   += (score.multiplier * enemy.enemyScore);
                        score.multiplier++;
                        enemy.Visible      = false;
                        explosion.Position = enemy.position;
                        explosion.StartAnimation();
                        hitSound.Play();
                        explodeSound.Play();
                    }

                    //shield is going up and touching bottom side of the enemy
                    if (shield.speed.Y < 0 &&
                        shield.getBound().Top + shield.speed.Y < enemy.getBound().Bottom&&
                        shield.getBound().Bottom > enemy.getBound().Bottom&&
                        shield.getBound().Right > enemy.getBound().Left&&
                        shield.getBound().Left < enemy.getBound().Right)
                    {
                        shield.speed.Y = -shield.speed.Y;
                        score.score   += (score.multiplier * enemy.enemyScore);
                        score.multiplier++;
                        enemy.Visible      = false;
                        explosion.Position = enemy.position;
                        explosion.StartAnimation();
                        hitSound.Play();
                        explodeSound.Play();
                    }
                }
            }


            base.Update(gameTime);
        }