Exemplo n.º 1
0
        public override void Update()
        {
            damaged = false;

            if (isDying)
            {
                if (dyingCount < 30)
                {
                    if (dyingCount % 2 == 0)
                    {
                        Effect effect = new SmallExplosionEffect(Game, X + Game.Random.Next(-64, 64 + 1), Y + Game.Random.Next(-32, 32 + - +1), Game.Random.Next(0, 360));
                        Game.AddEffect(effect);
                        if (dyingCount % 4 == 0)
                        {
                            Game.PlaySound(Sound.Explosion);
                        }
                    }
                    dyingCount++;
                    if (dyingCount == 30)
                    {
                        int startAngle = Game.Random.Next(90);
                        for (int i = 0; i < 20; i++)
                        {
                            int    angle  = startAngle + i * 18 + Game.Random.Next(-18, 19);
                            double x      = X + 64 * Utility.Cos(angle);
                            double y      = Y - 32 * Utility.Sin(angle);
                            double speed  = 0.5 + 1.5 * Game.Random.NextDouble();
                            Effect debris = new Debris(Game, x, y, 80, 80, 80, speed, angle);
                            Game.AddEffect(debris);
                        }
                        for (int i = -1; i <= 1; i++)
                        {
                            Effect effect = new BigExplosionEffect(Game, X - i * 48, Y, Game.Random.Next(0, 360), 255, 255, 255);
                            Game.AddEffect(effect);
                        }
                        Game.PlaySound(Sound.Explosion);
                    }
                }
                return;
            }

            if (moveCount > 0)
            {
                moveCount--;
                if (attackMode == 0)
                {
                    if (!(Math.Abs(X - targetX) < 32 && Math.Abs(Y - targetY) < 32))
                    {
                        Effect smoke1 = new Smoke(Game, X - 24, Y - 24, Game.Random.Next(0, 360));
                        Effect smoke2 = new Smoke(Game, X + 24, Y - 24, Game.Random.Next(0, 360));
                        Game.AddEffect(smoke1);
                        Game.AddEffect(smoke2);
                    }
                }
                if (!Game.Player.IsDead)
                {
                    if (attackMode == 1)
                    {
                        if (moveCount == 4)
                        {
                            Bullet bullet1 = new OrangeBullet(Game, X - 32 + 32 * Utility.Cos(255), Y - 32 * Utility.Sin(255), 12, 255);
                            Bullet bullet2 = new OrangeBullet(Game, X - 32 + 32 * Utility.Cos(270), Y - 32 * Utility.Sin(270), 12, 270);
                            Bullet bullet3 = new OrangeBullet(Game, X - 32 + 32 * Utility.Cos(285), Y - 32 * Utility.Sin(285), 12, 285);
                            Game.AddEnemyBullet(bullet1);
                            Game.AddEnemyBullet(bullet2);
                            Game.AddEnemyBullet(bullet3);
                            Game.PlaySound(Sound.OrangeFire);
                        }
                        else if (moveCount == 8)
                        {
                            Bullet bullet1 = new OrangeBullet(Game, X + 32 + 32 * Utility.Cos(255), Y - 32 * Utility.Sin(255), 12, 255);
                            Bullet bullet2 = new OrangeBullet(Game, X + 32 + 32 * Utility.Cos(270), Y - 32 * Utility.Sin(270), 12, 270);
                            Bullet bullet3 = new OrangeBullet(Game, X + 32 + 32 * Utility.Cos(285), Y - 32 * Utility.Sin(285), 12, 285);
                            Game.AddEnemyBullet(bullet1);
                            Game.AddEnemyBullet(bullet2);
                            Game.AddEnemyBullet(bullet3);
                            Game.PlaySound(Sound.OrangeFire);
                        }
                    }
                    else if (attackMode == 2)
                    {
                        if (moveCount == 4)
                        {
                            Bullet bullet1 = new OrangeBullet(Game, X + 32 + 32 * Utility.Cos(255), Y - 32 * Utility.Sin(255), 12, 255);
                            Bullet bullet2 = new OrangeBullet(Game, X + 32 + 32 * Utility.Cos(270), Y - 32 * Utility.Sin(270), 12, 270);
                            Bullet bullet3 = new OrangeBullet(Game, X + 32 + 32 * Utility.Cos(285), Y - 32 * Utility.Sin(285), 12, 285);
                            Game.AddEnemyBullet(bullet1);
                            Game.AddEnemyBullet(bullet2);
                            Game.AddEnemyBullet(bullet3);
                            Game.PlaySound(Sound.OrangeFire);
                        }
                        else if (moveCount == 8)
                        {
                            Bullet bullet1 = new OrangeBullet(Game, X - 32 + 32 * Utility.Cos(255), Y - 32 * Utility.Sin(255), 12, 255);
                            Bullet bullet2 = new OrangeBullet(Game, X - 32 + 32 * Utility.Cos(270), Y - 32 * Utility.Sin(270), 12, 270);
                            Bullet bullet3 = new OrangeBullet(Game, X - 32 + 32 * Utility.Cos(285), Y - 32 * Utility.Sin(285), 12, 285);
                            Game.AddEnemyBullet(bullet1);
                            Game.AddEnemyBullet(bullet2);
                            Game.AddEnemyBullet(bullet3);
                            Game.PlaySound(Sound.OrangeFire);
                        }
                    }
                    else if (attackMode == 3)
                    {
                        if (moveCount == 12)
                        {
                            Bullet missile = new Missile(Game, X, Y + 16 - 32 * Utility.Sin(255), 270);
                            Game.AddEnemyBullet(missile);
                            Game.PlaySound(Sound.MissileFire);
                        }
                    }
                }
            }
            else
            {
                if (attackMode > 0)
                {
                    attackMode = Game.Random.Next(0, 4);
                }
                else
                {
                    attackMode = Game.Random.Next(1, 4);
                }
                targetX = (int)Math.Round(Game.Player.X) + Game.Random.Next(-32, 32 + 1);
                if (attackMode == 0)
                {
                    targetY = Game.FieldHeight - 32;
                }
                else
                {
                    targetY = Game.FieldHeight / 4 + Game.Random.Next(-32, 64 + 1);
                }

                /*
                 * if (hitPoints > 48)
                 * {
                 *  moveCount = Game.Random.Next(30, 60);
                 * }
                 * else if (hitPoints > 24)
                 * {
                 *  moveCount = Game.Random.Next(25, 50);
                 * }
                 * else
                 * {
                 *  moveCount = Game.Random.Next(20, 40);
                 * }
                 */
                moveCount = Game.Random.Next(20, 30);
                if (targetX < 80)
                {
                    targetX = 80;
                }
                else if (targetX > Game.FieldWidth - 80)
                {
                    targetX = Game.FieldWidth - 80;
                }
            }
            x2 = targetX * 0.125 + x2 * 0.875;
            y2 = targetY * 0.125 + y2 * 0.875;
            X  = x2 * 0.125 + X * 0.875;
            Y  = y2 * 0.125 + Y * 0.875;
        }
Exemplo n.º 2
0
 public override void Update()
 {
     if (waitCount > 0)
     {
         double newX = waitX + swingWidth * Utility.Sin(Game.Ticks * 8);
         double newY = waitY + swingHeight * Utility.Sin(Game.Ticks * 8);
         vx = newX - X;
         vy = newY - Y;
         X  = newX;
         Y  = newY;
         waitCount--;
     }
     if (waitCount == 0)
     {
         if (!attacking)
         {
             if (angle == 90)
             {
                 angle += Game.Random.Next(2) == 0 ? 1 : -1;
             }
             else
             {
                 int deg = Utility.NormalizeDeg(270 - angle);
                 if (Math.Abs(deg) < 8)
                 {
                     angle     = 270;
                     attacking = true;
                 }
                 else
                 {
                     if (deg < 0)
                     {
                         angle -= 8;
                     }
                     else if (deg > 0)
                     {
                         angle += 8;
                     }
                 }
             }
             vx += 0.5 * Utility.Cos(angle);
             vy -= 0.5 * Utility.Sin(angle);
             Move();
         }
         else
         {
             if (X < Game.Player.X + playerXTraceOffset)
             {
                 vx += 0.25;
             }
             else if (X > Game.Player.X + playerXTraceOffset)
             {
                 vx -= 0.25;
             }
             vy += 0.25;
             Move();
             {
                 int deg = Utility.NormalizeDeg(Utility.Atan2(Y - Game.Player.Y, Game.Player.X - X) - angle);
                 if (deg == -180)
                 {
                     angle += Game.Random.Next(2) == 0 ? 1 : -1;
                 }
                 else if (Math.Abs(deg) < 2)
                 {
                     angle = Utility.Atan2(Y - Game.Player.Y, Game.Player.X - X);
                 }
                 else
                 {
                     if (deg < 0)
                     {
                         angle -= 2;
                     }
                     else if (deg > 0)
                     {
                         angle += 2;
                     }
                 }
                 angle = (angle % 360 + 360) % 360;
                 if (angle < 225)
                 {
                     angle = 225;
                 }
                 else if (angle > 315)
                 {
                     angle = 315;
                 }
             }
             if (fireCount > 0)
             {
                 fireCount--;
             }
             else if (!Game.Player.IsDead)
             {
                 if (Y < Game.Player.Y)
                 {
                     Bullet bullet = new Missile(Game, X + 32 * Utility.Cos(angle), Y - 32 * Utility.Sin(angle), angle);
                     Game.AddEnemyBullet(bullet);
                     Game.PlaySound(Sound.MissileFire);
                     fireCount          = Game.Random.Next(60, 90);
                     playerXTraceOffset = Game.Random.Next(-96, 96 + 1);
                 }
                 else
                 {
                     fireCount          = Game.Random.Next(15, 30);
                     playerXTraceOffset = Game.Random.Next(-96, 96 + 1);
                 }
             }
         }
     }
     damaged   = false;
     animation = (animation + 1) % 10;
 }
Exemplo n.º 3
0
        public override void Update()
        {
            damaged = false;

            if (isDying)
            {
                if (dyingCount < 30)
                {
                    if (dyingCount % 2 == 0)
                    {
                        Effect effect = new SmallExplosionEffect(Game, X + Game.Random.Next(-64, 64 + 1), Y + Game.Random.Next(-32, 32 + -+1), Game.Random.Next(0, 360));
                        Game.AddEffect(effect);
                        if (dyingCount % 4 == 0)
                        {
                            Game.PlaySound(Sound.Explosion);
                        }
                    }
                    dyingCount++;
                    if (dyingCount == 30)
                    {
                        int startAngle = Game.Random.Next(90);
                        for (int i = 0; i < 20; i++)
                        {
                            int angle = startAngle + i * 18 + Game.Random.Next(-18, 19);
                            double x = X + 64 * Utility.Cos(angle);
                            double y = Y - 32 * Utility.Sin(angle);
                            double speed = 0.5 + 1.5 * Game.Random.NextDouble();
                            Effect debris = new Debris(Game, x, y, 80, 80, 80, speed, angle);
                            Game.AddEffect(debris);
                        }
                        for (int i = -1; i <= 1; i++)
                        {
                            Effect effect = new BigExplosionEffect(Game, X - i * 48, Y, Game.Random.Next(0, 360), 255, 255, 255);
                            Game.AddEffect(effect);
                        }
                        Game.PlaySound(Sound.Explosion);
                    }
                }
                return;
            }

            if (moveCount > 0)
            {
                moveCount--;
                if (attackMode == 0)
                {
                    if (!(Math.Abs(X - targetX) < 32 && Math.Abs(Y - targetY) < 32))
                    {
                        Effect smoke1 = new Smoke(Game, X - 24, Y - 24, Game.Random.Next(0, 360));
                        Effect smoke2 = new Smoke(Game, X + 24, Y - 24, Game.Random.Next(0, 360));
                        Game.AddEffect(smoke1);
                        Game.AddEffect(smoke2);
                    }
                }
                if (!Game.Player.IsDead)
                {
                    if (attackMode == 1)
                    {
                        if (moveCount == 4)
                        {
                            Bullet bullet1 = new OrangeBullet(Game, X - 32 + 32 * Utility.Cos(255), Y - 32 * Utility.Sin(255), 12, 255);
                            Bullet bullet2 = new OrangeBullet(Game, X - 32 + 32 * Utility.Cos(270), Y - 32 * Utility.Sin(270), 12, 270);
                            Bullet bullet3 = new OrangeBullet(Game, X - 32 + 32 * Utility.Cos(285), Y - 32 * Utility.Sin(285), 12, 285);
                            Game.AddEnemyBullet(bullet1);
                            Game.AddEnemyBullet(bullet2);
                            Game.AddEnemyBullet(bullet3);
                            Game.PlaySound(Sound.OrangeFire);
                        }
                        else if (moveCount == 8)
                        {
                            Bullet bullet1 = new OrangeBullet(Game, X + 32 + 32 * Utility.Cos(255), Y - 32 * Utility.Sin(255), 12, 255);
                            Bullet bullet2 = new OrangeBullet(Game, X + 32 + 32 * Utility.Cos(270), Y - 32 * Utility.Sin(270), 12, 270);
                            Bullet bullet3 = new OrangeBullet(Game, X + 32 + 32 * Utility.Cos(285), Y - 32 * Utility.Sin(285), 12, 285);
                            Game.AddEnemyBullet(bullet1);
                            Game.AddEnemyBullet(bullet2);
                            Game.AddEnemyBullet(bullet3);
                            Game.PlaySound(Sound.OrangeFire);
                        }
                    }
                    else if (attackMode == 2)
                    {
                        if (moveCount == 4)
                        {
                            Bullet bullet1 = new OrangeBullet(Game, X + 32 + 32 * Utility.Cos(255), Y - 32 * Utility.Sin(255), 12, 255);
                            Bullet bullet2 = new OrangeBullet(Game, X + 32 + 32 * Utility.Cos(270), Y - 32 * Utility.Sin(270), 12, 270);
                            Bullet bullet3 = new OrangeBullet(Game, X + 32 + 32 * Utility.Cos(285), Y - 32 * Utility.Sin(285), 12, 285);
                            Game.AddEnemyBullet(bullet1);
                            Game.AddEnemyBullet(bullet2);
                            Game.AddEnemyBullet(bullet3);
                            Game.PlaySound(Sound.OrangeFire);
                        }
                        else if (moveCount == 8)
                        {
                            Bullet bullet1 = new OrangeBullet(Game, X - 32 + 32 * Utility.Cos(255), Y - 32 * Utility.Sin(255), 12, 255);
                            Bullet bullet2 = new OrangeBullet(Game, X - 32 + 32 * Utility.Cos(270), Y - 32 * Utility.Sin(270), 12, 270);
                            Bullet bullet3 = new OrangeBullet(Game, X - 32 + 32 * Utility.Cos(285), Y - 32 * Utility.Sin(285), 12, 285);
                            Game.AddEnemyBullet(bullet1);
                            Game.AddEnemyBullet(bullet2);
                            Game.AddEnemyBullet(bullet3);
                            Game.PlaySound(Sound.OrangeFire);
                        }
                    }
                    else if (attackMode == 3)
                    {
                        if (moveCount == 12)
                        {
                            Bullet missile = new Missile(Game, X, Y + 16 - 32 * Utility.Sin(255), 270);
                            Game.AddEnemyBullet(missile);
                            Game.PlaySound(Sound.MissileFire);
                        }
                    }
                }
            }
            else
            {
                if (attackMode > 0)
                {
                    attackMode = Game.Random.Next(0, 4);
                }
                else
                {
                    attackMode = Game.Random.Next(1, 4);
                }
                targetX = (int)Math.Round(Game.Player.X) + Game.Random.Next(-32, 32 + 1);
                if (attackMode == 0)
                {
                    targetY = Game.FieldHeight - 32;
                }
                else
                {
                    targetY = Game.FieldHeight / 4 + Game.Random.Next(-32, 64 + 1);
                }
                if (hitPoints > 48)
                {
                    moveCount = Game.Random.Next(30, 60);
                }
                else if (hitPoints > 24)
                {
                    moveCount = Game.Random.Next(25, 50);
                }
                else
                {
                    moveCount = Game.Random.Next(20, 40);
                }
                if (targetX < 80)
                {
                    targetX = 80;
                }
                else if (targetX > Game.FieldWidth - 80)
                {
                    targetX = Game.FieldWidth - 80;
                }
            }
            x2 = targetX * 0.125 + x2 * 0.875;
            y2 = targetY * 0.125 + y2 * 0.875;
            X = x2 * 0.125 + X * 0.875;
            Y = y2 * 0.125 + Y * 0.875;
        }
Exemplo n.º 4
0
 public override void Update()
 {
     if (waitCount > 0)
     {
         double newX = waitX + swingWidth * Utility.Sin(Game.Ticks * 8);
         double newY = waitY + swingHeight * Utility.Sin(Game.Ticks * 8);
         vx = newX - X;
         vy = newY - Y;
         X = newX;
         Y = newY;
         waitCount--;
     }
     if (waitCount == 0)
     {
         if (!attacking)
         {
             if (angle == 90)
             {
                 angle += Game.Random.Next(2) == 0 ? 1 : -1;
             }
             else
             {
                 int deg = Utility.NormalizeDeg(270 - angle);
                 if (Math.Abs(deg) < 8)
                 {
                     angle = 270;
                     attacking = true;
                 }
                 else
                 {
                     if (deg < 0)
                     {
                         angle -= 8;
                     }
                     else if (deg > 0)
                     {
                         angle += 8;
                     }
                 }
             }
             vx += 0.5 * Utility.Cos(angle);
             vy -= 0.5 * Utility.Sin(angle);
             Move();
         }
         else
         {
             if (X < Game.Player.X + playerXTraceOffset)
             {
                 vx += 0.25;
             }
             else if (X > Game.Player.X + playerXTraceOffset)
             {
                 vx -= 0.25;
             }
             vy += 0.25;
             Move();
             {
                 int deg = Utility.NormalizeDeg(Utility.Atan2(Y - Game.Player.Y, Game.Player.X - X) - angle);
                 if (deg == -180)
                 {
                     angle += Game.Random.Next(2) == 0 ? 1 : -1;
                 }
                 else if (Math.Abs(deg) < 2)
                 {
                     angle = Utility.Atan2(Y - Game.Player.Y, Game.Player.X - X);
                 }
                 else
                 {
                     if (deg < 0)
                     {
                         angle -= 2;
                     }
                     else if (deg > 0)
                     {
                         angle += 2;
                     }
                 }
                 angle = (angle % 360 + 360) % 360;
                 if (angle < 225)
                 {
                     angle = 225;
                 }
                 else if (angle > 315)
                 {
                     angle = 315;
                 }
             }
             if (fireCount > 0)
             {
                 fireCount--;
             }
             else if (!Game.Player.IsDead)
             {
                 if (Y < Game.Player.Y)
                 {
                     Bullet bullet = new Missile(Game, X + 32 * Utility.Cos(angle), Y - 32 * Utility.Sin(angle), angle);
                     Game.AddEnemyBullet(bullet);
                     Game.PlaySound(Sound.MissileFire);
                     fireCount = Game.Random.Next(60, 90);
                     playerXTraceOffset = Game.Random.Next(-96, 96 + 1);
                 }
                 else
                 {
                     fireCount = Game.Random.Next(15, 30);
                     playerXTraceOffset = Game.Random.Next(-96, 96 + 1);
                 }
             }
         }
     }
     damaged = false;
     animation = (animation + 1) % 10;
 }