/// <summary>
 /// overridden logic allows the Seeker to fire a constand barrage of homing missiles
 /// </summary>
 /// <param name="player"></param>
 protected override void alienLogic(PlayerShip player)
 {
     base.alienLogic(player);
     fire();
     if (ShieldLevel < 1)
     {
         Escaping         = true;
         PreferredMinDist = Utilities.screenBounds.Width;
     }
 }
예제 #2
0
 /// <summary>
 /// Overloaded move function runs the logic (AI) of the alien and sets rotation = velocity
 /// </summary>
 /// <param name="player">the player's ship - used for AI</param>
 /// <param name="dt">the time step</param>
 public virtual void Move(PlayerShip player, float dt)
 {
     if (!IsDying)
     {
         if (Settings.shipUseDamper)
         {
             Velocity.addVector((float)-.01 * Velocity.getMagnitude(), Velocity.getDirection());
         }
         alienLogic(player);
         RadRotation = Velocity.getDirection() + (float)Math.PI / 2;
     }
     base.Move(dt);
     areaOfAwareness = new Rectangle(Bounds.X - awareness, Bounds.Y - awareness, Bounds.Width + awareness * 2, Bounds.Height + awareness * 2);
     if (bulletCoolDown > 0)
     {
         bulletCoolDown--;
     }
 }
예제 #3
0
        /// <summary>
        /// The main artificial intelligence algorithm for the aliens
        /// </summary>
        /// <param name="player">the player's ship</param>
        protected virtual void alienLogic(PlayerShip player)
        {
            try //One task at a time...
            {
                // Object avoidance logic first - don't let meteors or bullets hit me
                if (visibleObjs.Count > 0)
                {
                    avoid();
                }

                // Player stalking logic second - get in close enough to kill
                else if (Position.getMagnitudeTo(player.Position) > preferredMaxDist)
                {
                    approach(player.Position);
                }

                // Prevent player from using the edge to trick me - don't sit on the edge
                else if (Math.Abs(Position.X - Utilities.screenBounds.X) < 60 || Math.Abs(Position.X - Utilities.screenBounds.Width) < 60 ||
                         Math.Abs(Position.Y - Utilities.screenBounds.Y) < 60 || Math.Abs(Position.Y - Utilities.screenBounds.Height) < 60)
                {
                    flank(player.RadRotation, player.Position);
                    getAwayFromEdge();
                }

                // If the player's getting too close, run away
                else if (Position.getMagnitudeTo(player.Position) < preferredMinDist && player.Velocity.getMagnitude() > .5)
                {
                    flee(player.Position);
                }

                // If I'm a coward, get around behind the player - don't let the player aim at me
                else if (Math.Abs(player.Position.getDirectionTo(Position) - (player.RadRotation - (float)Math.PI / 2)) < cowardAngle && isCoward)
                {
                    flank(player.RadRotation, player.Position);
                }

                // Player shooting logic last - if all else is golden, blow the player up
                else
                {
                    aim(player.Position, player.Velocity);
                }
            }
            catch (Exception e) { MessageBox.Show(e.Message, "Alien Logic"); }
        }
예제 #4
0
        /// <summary>
        /// Intializes the game creating everything that is needed
        /// </summary>
        /// <param name="Display">The form being drawn on</param>
        public void IntializeGame(Form1 Display)
        {
            Threads.initializeTasks();
            level                  = 1;
            score                  = 0;
            lives                  = 3;
            extraLivesCounter      = 0;
            Utilities.screenBounds = Screen.PrimaryScreen.Bounds;//Display.ClientRectangle;
            Utilities.screenCenter = new Coordinates(Utilities.screenBounds.Width / 2, Utilities.screenBounds.Height / 2);
            isRunning              = true;
            PlayerShip             = new PlayerShip(Utilities.screenBounds.Width / 2, Utilities.screenBounds.Height / 2);
            InGameMeteors          = new List <Meteor>();
            inGameAlienShips       = new List <AlienBase>();
            alienSpawnTimer        = Settings.SpawnTimer;
            ACollision             = new Collisions();
            stateDescription       = "fine";
            needsToExit            = false;

            int x;
            int y;
            int i = 0;

            while (i < Settings.meteorInitAmount)
            {
                //create asteriod away from middle
                x = (Utilities.getRand10() * (Utilities.screenBounds.Width / 10));
                while (x > Utilities.screenBounds.Width / 2 - 300 && x < Utilities.screenBounds.Width / 2 + 300)
                {
                    x = (Utilities.getRand10() * (Utilities.screenBounds.Width / 10));
                }

                y = (Utilities.getRand10() * (Utilities.screenBounds.Height / 10));
                while (y > Utilities.screenBounds.Height / 2 - 300 && y < Utilities.screenBounds.Height / 2 + 300)
                {
                    y = (Utilities.getRand10() * (Utilities.screenBounds.Height / 10));
                }

                InGameMeteors.Add(new Meteor(new Coordinates(x, y),
                                             Settings.meteorStartSize, new Coordinates((Utilities.getRandBase(Settings.meteorSpawnSpeed) - Settings.meteorSpawnSpeed / 2) / (float)10.0,
                                                                                       (Utilities.getRandBase(Settings.meteorSpawnSpeed) - Settings.meteorSpawnSpeed / 2) / (float)10.0)));
                i++;
            }
        }
 /// <summary>
 /// Checks collisions between the aliens' bullets and the player's ship
 /// </summary>
 /// <param name="Lbullet">alien bullet list</param>
 /// <param name="ship">player's ship</param>
 public void DidCollisionOccur(List <Weapon> Lbullet, PlayerShip ship)
 {
     for (int i = Lbullet.Count - 1; i >= 0; i--)
     {
         if (!Lbullet[i].IsDying)
         {
             if (Check(Lbullet[i].Bounds, ship.Bounds))
             {
                 if (Settings.debug)
                 {
                     Lbullet[i].isCollided = true;
                     ship.isCollided       = true;
                 }
                 if (Settings.useFancyCollisions)
                 {
                     if (Settings.debug)
                     {
                         Lbullet[i].isCollidedFoReal = false;
                         ship.isCollidedFoReal       = false;
                     }
                     if (FancyCollisions.isColliding(Lbullet[i], ship))
                     {
                         if (Settings.debug)
                         {
                             Lbullet[i].isCollidedFoReal = true;
                             ship.isCollidedFoReal       = true;
                         }
                         Lbullet[i].IsDying = true;
                         UsedBullets.Add(Lbullet[i]);
                         ship.IsDying = true;
                     }
                 }
                 else
                 {
                     Lbullet[i].IsDying = true;
                     UsedBullets.Add(Lbullet[i]);
                     ship.IsDying = true;
                 }
             }
         }
     }
 }
 /// <summary>
 /// Check if Collision occurs between Meteor and playerShip
 /// </summary>
 /// <param name="Lmeteor">Meteor List</param>
 /// <param name="ship">Vehicle Object</param>
 public void DidCollisionOccur(List <Meteor> Lmeteor, PlayerShip ship)
 {
     ship.isCollided = false;
     for (int i = Lmeteor.Count - 1; i >= 0; i--)
     {
         Lmeteor[i].isCollided = false;
         if (!Lmeteor[i].IsDying)
         {
             if (Check(Lmeteor[i].Bounds, ship.Bounds))
             {
                 if (Settings.debug)
                 {
                     Lmeteor[i].isCollided = true;
                     ship.isCollided       = true;
                 }
                 if (Settings.useFancyCollisions)
                 {
                     if (Settings.debug)
                     {
                         Lmeteor[i].isCollidedFoReal = false;
                         ship.isCollidedFoReal       = false;
                     }
                     if (FancyCollisions.isColliding(Lmeteor[i], ship))
                     {
                         if (Settings.debug)
                         {
                             Lmeteor[i].isCollidedFoReal = true;
                             ship.isCollidedFoReal       = true;
                         }
                         Lmeteor[i].IsDying = true;
                         ship.IsDying       = true;
                     }
                 }
                 else
                 {
                     Lmeteor[i].IsDying = true;
                     ship.IsDying       = true;
                 }
             }
         }
     }
 }
예제 #7
0
 /// <summary>
 /// overridded behavior routine allows the Caller to change to a 'coward' when it's shields go down.
 /// </summary>
 /// <param name="player">the player's ship</param>
 protected override void alienLogic(PlayerShip player)
 {
     base.alienLogic(player);
     abilityCoolDown--;
     if (abilityCoolDown == 195)
     {
         GameSounds.effect(GameMedia.getDir["callSigSND"]);
     }
     if (abilityCoolDown <= 0)
     {
         if (ShieldLevel < 1)
         {
             ShieldLevel++;
             IsCoward = false;
             try { GameSounds.effect(GameMedia.getDir["shieldsUpSND"]); }
             catch { }
         }
         callAllies();
         abilityCoolDown = 3000;
     }
 }
예제 #8
0
        /// <summary>
        /// loops to run the draw each game object each frame
        /// </summary>
        public void runGameGraphics(Graphics gameGraphics)
        {
            List <Weapon> playersBullets = PlayerShip.Bullets.ToList();

            for (int i = playersBullets.Count - 1; i >= 0; i--)
            {
                try
                {
                    if (playersBullets[i].IsActive)
                    {
                        playersBullets[i].DrawObj(gameGraphics);
                    }
                }
                catch { }
            }

            List <Meteor> meteors = inGameMeteors.ToList();

            for (int i = meteors.Count - 1; i >= 0; i--)
            {
                try
                {
                    if (meteors[i].IsActive)
                    {
                        meteors[i].DrawObj(gameGraphics);
                    }
                }
                catch { }
            }

            List <AlienBase> aliens = inGameAlienShips.ToList();

            for (int i = aliens.Count - 1; i >= 0; i--)
            {
                try
                {
                    if (aliens[i].IsActive)
                    {
                        aliens[i].DrawObj(gameGraphics);
                    }
                }
                catch (Exception e) { MessageBox.Show(e.Message, "Alien Ship Draw"); }
                for (int j = aliens[i].Bullets.Count - 1; j >= 0; j--)
                {
                    try
                    {
                        if (aliens[i].Bullets[j].IsActive)
                        {
                            aliens[i].Bullets[j].DrawObj(gameGraphics);
                        }
                    }
                    catch (Exception e) { MessageBox.Show(e.Message, "Alien Bullet Draw"); }
                }
            }

            if (playerShip != null)
            {
                if (PlayerShip.IsActive)
                {
                    PlayerShip.DrawObj(gameGraphics);
                }
            }
        }
예제 #9
0
        /// <summary>
        /// initialized the next level
        /// </summary>
        /// <param name="Display">the form on which to operate</param>
        public void InitializeNextLevel(Form Display)
        {
            //GameSounds.CloseSFX();
            //GameSounds.InitializeSFX();
            //Task.WaitAll()

            Threads.initializeTasks();
            InGameMeteors       = new List <Meteor>();
            inGameAlienShips    = new List <AlienBase>();
            alienSpawnTimer     = Settings.SpawnTimer;
            ACollision          = new Collisions();
            PlayerShip          = new PlayerShip(Display.ClientRectangle.Width / 2, Display.ClientRectangle.Height / 2);
            PlayerShip.Position = new Coordinates(Display.ClientRectangle.Width / 2, Display.ClientRectangle.Height / 2);
            Utilities.populateRandPool();

            Settings.chancePool = 160 - level * 10;                         // at level 15 an alien should spawn every time the alien spawner loops
            if (Settings.chancePool <= 10)
            {
                Settings.chancePool = 10;
            }
            Settings.WussRemover = level / 5;                               // at level 35 only the tough aliens will spawn
            if (Settings.WussRemover >= 7)
            {
                Settings.WussRemover = 7;
            }
            int totalMeteorMaterial = 200 + level * 75;

            if (totalMeteorMaterial >= 2100)
            {
                totalMeteorMaterial = 2100;                                 // 10 large asteroids will be the max ever spawned
            }
            Settings.meteorInitAmount = totalMeteorMaterial / 200;
            Settings.meteorStartSize  = totalMeteorMaterial / Settings.meteorInitAmount;
            Settings.meteorSpawnSpeed = 6 + level / 12;                     // every 12 levels meteor speed will increase (can't go over 10)
            if (Settings.meteorSpawnSpeed <= 10)
            {
                Settings.meteorSpawnSpeed = 10;
            }

            int x;
            int y;
            int i = 0;

            while (i < Settings.meteorInitAmount)
            {
                //create asteriod away from middle
                x = (Utilities.getRand10() * (Utilities.screenBounds.Width / 10));
                while (x > Utilities.screenBounds.Width / 2 - 300 && x < Utilities.screenBounds.Width / 2 + 300)
                {
                    x = (Utilities.getRand10() * (Utilities.screenBounds.Width / 10));
                }

                y = (Utilities.getRand10() * (Utilities.screenBounds.Height / 10));
                while (y > Utilities.screenBounds.Height / 2 - 300 && y < Utilities.screenBounds.Height / 2 + 300)
                {
                    y = (Utilities.getRand10() * (Utilities.screenBounds.Height / 10));
                }

                InGameMeteors.Add(new Meteor(new Coordinates(x, y),
                                             Settings.meteorStartSize, new Coordinates((Utilities.getRandBase(Settings.meteorSpawnSpeed) - Settings.meteorSpawnSpeed / 2) / (float)10.0,
                                                                                       (Utilities.getRandBase(Settings.meteorSpawnSpeed) - Settings.meteorSpawnSpeed / 2) / (float)10.0)));
                i++;
            }
        }