Exemple #1
0
        public void update(Player p1, int eLeft)
        {
            int score = p1.Score;
            int health = p1.Health;

            hudScore = "         " + score;
            hudHealth = "        " + health;
        }
Exemple #2
0
 public QuestionScreen(string msg, GameplayScreen caller, HeadsUpDisplay HUD,
     Player p1)
 {
     parent = caller;
     player = p1;
     hud = HUD;
     string question = RandomGenerator.RandomQuestion( parent.CurrentScore,
                                           out correctAnswer, out answers);
     lifeSpan = 240;
     questionMessage = msg + "\n" + question;
     answerMessage = "\n" + answers[0].ToString().PadLeft(8) + "\n" +
               answers[1] + answers[2].ToString().PadLeft(12) + "\n" +
                            answers[3].ToString().PadLeft(8);
     timeMessage = "\nTime Left: " + lifeSpan;
     message = questionMessage + answerMessage + timeMessage + usageText;
     IsPopup = true;
     TransitionOnTime = TimeSpan.FromSeconds(0.1);
     TransitionOffTime = TimeSpan.Zero;
 }
Exemple #3
0
 public static void AddEnemy(List<Enemy> eList, int numToAdd, int numMovers,
     List<Texture2D> enemyTexList, Vector2 wSize, Player p1)
 {
     int count = 0;
     while(count < numToAdd)
     {
         int enemyType = RandomGenerator.RandomInt(enemyTexList.Count);
         eList.Add(new Enemy(RandomGenerator.RandomMoveStrategy(numMovers, p1.Score),
                                wSize, 100, RandomGenerator.RandomEnemySize(false)));
         int index = eList.Count - 1;
         switch(enemyType)
         {
             case 0: eList[index].InitializeAnim(enemyTexList[0], 2, 400, 44, 40);
                 break;
             case 1: eList[index].InitializeAnim(enemyTexList[1], 8, 200, 46, 50);
                 break;
             case 2: eList[index].InitializeAnim(enemyTexList[2], 4, 150, 70, 50);
                 break;
         }
         count++;
     }
 }
Exemple #4
0
        public static string RandomQuestion(Player p1, out int answer, out int[] answers)
        {
            answer = rand.Next(1, 5);
            answers = new[] {0, 0, 0, 0};

            string question = "";
            int firstVal;
            int SecondVal;
            int myOperator = Random4Choice1(p1.Score);
            int correctAnswer;

            switch(myOperator)
            {
                case 1:
                    firstVal = rand.Next(p1.MaxAddSub);
                    SecondVal = rand.Next(p1.MaxAddSub);
                    question = firstVal + " + " + SecondVal + " = ?";
                    correctAnswer = firstVal + SecondVal;
                    break;
                case 2:
                    firstVal = rand.Next(p1.MaxAddSub);
                    SecondVal = rand.Next(p1.MaxAddSub);
                    question = firstVal + " - " + SecondVal + " = ?";
                    correctAnswer = firstVal - SecondVal;
                    break;
                case 3:
                    firstVal = rand.Next(p1.MaxMul);
                    SecondVal = rand.Next(p1.MaxMul);
                    question = firstVal + " * " + SecondVal + " = ?";
                    correctAnswer = firstVal * SecondVal;
                    break;
                default:
                    firstVal = rand.Next(p1.MaxDiv);
                    SecondVal = rand.Next(p1.MaxDiv);
                    correctAnswer = HandleDivision(ref firstVal, ref SecondVal,
                                                                    p1.MaxDiv);
                    question = firstVal + " / " + SecondVal + " = ?";
                    break;
            }

            for(int i = 1; i < 5; i++)
            {
                if(i == answer)
                {
                    answers[i - 1] = correctAnswer;
                }
                else
                {
                    answers[i - 1] = WrongAnswer(correctAnswer);
                }
            }
            p1.MaxAddSub++;
            p1.MaxDiv++;
            p1.MaxMul++;
            return question;
        }
Exemple #5
0
        public static void CheckCollision(List<Bullet> defaultBulletList,
            List<Enemy> enemyList, Player p1,
            ref bool shield_active, List<Health> hlist,
            SpriteBatch sb, Texture2D heart, List<Shield> sList,
            SoundEffect grabHealth, SoundEffect grabShield)
        {
            Rectangle r1 = new Rectangle();
            Rectangle r2 = new Rectangle();
            bool grabShieldInstance = false;
            bool grabHealthInstance = false;

            int index = 0;
            if(defaultBulletList.Count > 0)
            {
                foreach(Bullet b in defaultBulletList)
                {
                    r1.Width = (int)Math.Round(b.CharacterSize.X);
                    r1.Height = (int)Math.Round(b.CharacterSize.Y);
                    r1.X = (int)Math.Round(b.Position.X);
                    r1.Y = (int)Math.Round(b.Position.Y);
                    foreach(var e in enemyList)
                    {
                        double ratio = Math.Sqrt(e.ResizeRation);
                        r2.Width = (int)Math.Round(e.CharacterSize.X * ratio);
                        r2.Height = (int)Math.Round(e.CharacterSize.Y * ratio);
                        r2.X = (int)Math.Round(e.Position.X);
                        r2.Y = (int)Math.Round(e.Position.Y);
                        if(r1.Intersects(r2))
                        {
                            e.GetHit(b.Damage);
                            if (!e.IsAlive())
                            {
                                bool isBoss = e.GetType().ToString() ==
                                                     "MathInfection.Boss";
                                p1.Score += 100;
                                if (isBoss)
                                {
                                    p1.Score += 100;
                                }
                                GeneratePowerUps(hlist, sList, e.Position, ref index);
                            }
                            b.IsValid = false;
                        }
                    }
                }
            }
            // endof Bullet Collision Detection

            // Player Collision Detection
            r1.Width = (int)Math.Round(p1.CharacterSize.X);
            r1.Height = (int)Math.Round(p1.CharacterSize.Y);
            r1.X = (int)Math.Round(p1.PlayerPosition.X);
            r1.Y = (int)Math.Round(p1.PlayerPosition.Y);
            foreach (Enemy e in enemyList)
            {
                double ratio = Math.Sqrt(e.ResizeRation);
                r2.Width = (int)Math.Round(e.CharacterSize.X * ratio);
                r2.Height = (int)Math.Round(e.CharacterSize.Y * ratio);
                r2.X = (int)Math.Round(e.Position.X);
                r2.Y = (int)Math.Round(e.Position.Y);

                if (r1.Intersects(r2))
                {
                    p1.EnemyType = e.GetType().ToString();
                    e.Health = 0;
                    if (shield_active)
                    {
                        shield_active = false;
                    }
                    else
                    {
                        p1.WasHit = true;
                        break;
                    }
                }
            }
            index = 0;
            while (index < hlist.Count)
            {
                if (hlist[index].drawIcon)
                {
                    r2.Width = (int)Math.Round(hlist[index].healthDimensions.X);
                    r2.Height = (int)Math.Round(hlist[index].healthDimensions.Y);
                    r2.X = (int)Math.Round(hlist[index].healthPosition.X);
                    r2.Y = (int)Math.Round(hlist[index].healthPosition.Y);

                    if (r1.Intersects(r2))
                    {
                        grabHealthInstance = grabHealth.Play();
                        hlist[index].drawIcon = false;
                        p1.Health += 10;
                    }
                }
                index++;
            }
            index = 0;
            while (index < sList.Count)
            {
                if (sList[index].drawShieldF)
                {
                    r2.Width = (int)sList[index].shield_sizeF.X;
                    r2.Width = (int)sList[index].shield_sizeF.Y;
                    r2.X = (int)sList[index].shield_positionF.X;
                    r2.Y = (int)sList[index].shield_positionF.Y;

                    if (r1.Intersects(r2))
                    {
                        grabShieldInstance = grabShield.Play();
                        sList[index].drawShieldF = false;
                        shield_active = true;
                    }
                }
                index++;
            }
            // endof Player Collision Detection
        }
Exemple #6
0
 public static void UpdateShieldList(ref List<Shield> sList, Player p1)
 {
     int index = 0;
     while (index < sList.Count)
     {
         if (!sList[index].drawShieldF)
         {
             sList.RemoveAt(index);
             index--;
         }
         index++;
     }
 }
Exemple #7
0
 public static void UpdateHealthList(ref List<Health> hlist, Player p1)
 {
     int index = 0;
     while (index < hlist.Count)
     {
         if (!hlist[index].drawIcon)
         {
             hlist.RemoveAt(index);
             index--;
         }
         index++;
     }
 }
Exemple #8
0
        public static void UpdateGameData(GameData data, Player player)
        {
            data.CurrentScore = player.Score;
            data.CurrentHealth = player.Health;
            if(player.Health > 0)
            {
                data.LastGameDied = false;
            }
            else
            {
                data.LastGameDied = true;
            }

            if(data.TopScores.Count < data.TopScoreCapacity && data.CurrentScore > 0)
            {
                if(!data.TopScores.Contains(data.CurrentScore) && !player.IsAlive())
                {
                    data.TopScores.Add(data.CurrentScore);
                    data.TopScoresDateTime.Add(DateTime.Now);
                }
            }
            else if(data.TopScores.Count > 0 && data.CurrentScore > data.TopScores.Min())
            {
                if (!data.TopScores.Contains(data.CurrentScore) && !player.IsAlive())
                {
                    int lowest = data.TopScores.Min();
                    int lowestIndex = data.TopScores.IndexOf(lowest);
                    data.TopScores.RemoveAt(lowestIndex);
                    data.TopScoresDateTime.RemoveAt(lowestIndex);
                    data.TopScores.Add(data.CurrentScore);
                    data.TopScoresDateTime.Add(DateTime.Now);
                }
            }
        }
Exemple #9
0
 public static void ModifyShield(ref Shield shield, SpriteBatch sb,
     Player player1, Texture2D player_shield)
 {
     Color color = new Color(0, 155, 155, 75);
     shield.player1_position.X = player1.PlayerPosition.X +
                                (player_shield.Bounds.X / 2) - 6;
     shield.player1_position.Y = player1.PlayerPosition.Y +
                                    (player_shield.Bounds.Y / 2);
     sb.Draw(player_shield, shield.player1_position, color);
 }
Exemple #10
0
        public static void CheckInput(GameTime gameTime, Player player1,
            List<Bullet> dBulletList, List<Texture2D> bulletTexList,
            TimeSpan previousFireTime, TimeSpan dFireRate,
            Vector2 wSize, GameplayScreen caller, SoundEffect gunSound)
        {
            // BoostButton pressing
            GamePadState newGamePadState = GamePad.GetState(PlayerIndex.One);
            KeyboardState newKeyboardState = Keyboard.GetState();
            if (newGamePadState.IsButtonDown(Buttons.LeftTrigger) ||
                newKeyboardState.IsKeyDown(Keys.RightShift))
            {
                player1.StartBoost = true;
            }
            else
            {
                player1.StartBoost = false;
            }
            // endof BoostButton pressing

            // Bullet Generation
            bool gunSoundInstance = false;
            if (gameTime.TotalGameTime - previousFireTime > dFireRate)
            {
                if (newGamePadState.Triggers.Right > .2f ||
                    newKeyboardState.IsKeyDown(Keys.Space))
                {
                    gunSoundInstance = gunSound.Play();
                    Vector2 bSize = new Vector2(bulletTexList[0].Width,
                                                bulletTexList[0].Height);
                    Vector2 bPos = new Vector2(player1.PlayerPosition.X +
                                               player1.CharacterSize.X / 2,
                                               player1.PlayerPosition.Y);

                    dBulletList.Add(new Bullet(bulletTexList[0], bPos,
                                    new Vector2(bSize.X / 2, bSize.Y),
                                        wSize, Vector2.Zero, 10, 20));
                    caller.PreviousFireTime = gameTime.TotalGameTime;
                }
            }
            // endof Bullet Generation
        }
Exemple #11
0
        private void GameplayLoad()
        {
            spriteBatch = ScreenManager.SpriteBatch;

            gunIconF    = content.Load<Texture2D>(@"PowerUps/GunFieldIcon");
            healthIconF = content.Load<Texture2D>(@"PowerUps/HealthUpgrade");
            shieldIconP = content.Load<Texture2D>(@"PowerUps/Shield");
            shieldIconF = content.Load<Texture2D>(@"PowerUps/ShieldFieldIcon");

            gunSound       = content.Load<SoundEffect>(@"Sounds/shootGun");
            getHealth      = content.Load<SoundEffect>(@"Sounds/grabHealth");
            getShield      = content.Load<SoundEffect>(@"Sounds/grabShield");
            noHealth       = content.Load<SoundEffect>(@"Sounds/noHealth");
            questionNotice = content.Load<SoundEffect>(@"Sounds/notice");

            hudFont    = content.Load<SpriteFont>("HUDFont");
            background = new Background();
            background.Load(ScreenManager.GraphicsDevice,
                                     content.Load<Texture2D>(@"BackgroundImages/BloodVein"),
                                     content.Load<Texture2D>(@"BackgroundImages/BloodCells"));

            player1Texture = content.Load<Texture2D>(@"CharacterImages/Player1");
            jettexture     = content.Load<Texture2D>(@"CharacterImages/Jet1Normal");
            jettexture2    = content.Load<Texture2D>(@"CharacterImages/Jet1Boost");
            playerSize = new Vector2(player1Texture.Width, player1Texture.Height);
            if(!singleMode)
            {
                // TODO: use player1's texture for now, might make another for player2 later.
                // player2Texture = Content.Load<Texture2D>(@"CharacterImages/Player2");
            }
            player1 = new Player(player1Texture, jettexture, jettexture2, initialPlayerPosition,
                                    playerVelocity, playerSize, windowSize, player1CurrentScore,
                                                                          player1CurrentHealth);

            enemyTexList.Add(content.Load<Texture2D>(@"CharacterImages/VirusGreen"));
            enemyTexList.Add(content.Load<Texture2D>(@"CharacterImages/VirusPurple"));
            enemyTexList.Add(content.Load<Texture2D>(@"CharacterImages/ShockingBloodCell"));

            GameUpdate.AddEnemy(enemyList, numEnemies, numMoveStrategies, enemyTexList,
                                                                  windowSize, player1);

            bulletTexList.Add(content.Load<Texture2D>(@"BulletImages/Bullets"));
            shield = new Shield(new Vector2(0, 0));
        }
Exemple #12
0
        private void GameplayLoad()
        {
            spriteBatch = ScreenManager.SpriteBatch;

            healthIconF = content.Load<Texture2D>(@"PowerUps/HealthUpgrade");
            shieldIconF = content.Load<Texture2D>(@"PowerUps/ShieldFieldIcon");
            shieldIconP = content.Load<Texture2D>(@"PowerUps/Shield");
            gunIconF = content.Load<Texture2D>(@"PowerUps/GunFieldIcon");

            gunSound = content.Load<SoundEffect>(@"Sounds/shootGun");
            getHealth = content.Load<SoundEffect>(@"Sounds/grabHealth");
            getShield = content.Load <SoundEffect>(@"Sounds/grabShield");
            noHealth = content.Load<SoundEffect>(@"Sounds/noHealth");
            questionNotice = content.Load<SoundEffect>(@"Sounds/notice");

            hudFont = content.Load<SpriteFont>("HUDFont");
            background = new Background();
            background.Load(ScreenManager.GraphicsDevice, content.Load<Texture2D>("BloodVein"), content.Load<Texture2D>("BCbg"));

            player1Texture = content.Load<Texture2D>(@"CharacterImages/Player1");
            jettexture = content.Load<Texture2D>(@"CharacterImages/Character Jets");
            jettexture2 = content.Load<Texture2D>(@"CharacterImages/Character Jets2");
            playerSize = new Vector2(player1Texture.Width, player1Texture.Height);
            if(!singleMode)
            {
                // TODO: use player1's texture for now, might make another for player2 later.
                // player2Texture = Content.Load<Texture2D>(@"CharacterImages/Player2");
            }
            player1 = new Player(player1Texture, jettexture, jettexture2, initialPlayerPosition,
                                                        playerVelocity, playerSize, windowSize);

            enemyTexList.Add(content.Load<Texture2D>(@"CharacterImages/Boss"));
            enemyTexList.Add(content.Load<Texture2D>(@"CharacterImages/PurpleVirus"));
            enemyTexList.Add(content.Load<Texture2D>(@"CharacterImages/ShockingInfectedBloodCell"));

            Vector2 charSize = new Vector2(enemyTexList[0].Width , enemyTexList[0].Height);
            int count = 0;
            while(count < numEnemies)
            {
                int r = RandomGenerator.RandomInt(enemyTexList.Count);
                enemyList.Add(new Enemy(RandomGenerator.RandomMoveStrategy(numMoveStrategies),
                                        RandomGenerator.RandomPosition(windowSize, charSize),
                                        windowSize,
                                        100,
                                        RandomGenerator.RandomEnemySize(false)));
                switch (r)
                {
                    case 0: enemyList[count].InitializeAnim(enemyTexList[0], 2, 400, 64, 64);
                        break;
                    case 1: enemyList[count].InitializeAnim(enemyTexList[1], 8, 200, 46, 50);
                        break;
                    case 2: enemyList[count].InitializeAnim(enemyTexList[2], 4, 150, 70, 50);
                        break;
                }
                count++;
            }
            bulletTexList.Add(content.Load<Texture2D>(@"BulletImages/Bullets"));
            shield = new Shield(new Vector2(0, 0));
        }
Exemple #13
0
 public void ModifyShield(SpriteBatch sb, Player player1)
 {
     player1_position.X = player1.position.X + player1_size.X/2 - 50;
     player1_position.Y = player1.position.Y + player1_size.Y/2 - 50;
     sb.Draw(powerUpTex_shield, player1_position, Color.White);
 }
Exemple #14
0
 public void update(Player p1)
 {
     hudScore = "         " + p1.Score;
     hudHealth = "        " + p1.Health;
 }
Exemple #15
0
 public void QuestionAnswered(Player p1)
 {
     update(p1);
 }
Exemple #16
0
        public static void CheckCollision(List<Bullet> defaultBulletList, List<Enemy> enemyList,
                                                                Player p1, out int currentScore, ref bool shield_active,
                                                                List<Health> hlist, SpriteBatch sb, Texture2D heart,
                                                                List<Shield> sList, SoundEffect grabHealth, SoundEffect grabShield)
        {
            Vector2 vec = new Vector2();
            Rectangle r1 = new Rectangle();
            Rectangle r2 = new Rectangle();
            bool grabShieldInstance = false;
            bool grabHealthInstance = false;

            currentScore = 0;
            int index = 0;
            if(defaultBulletList.Count > 0)
            {
                foreach(Bullet b in defaultBulletList)
                {
                    r1.Width = (int)Math.Round(b.CharacterSize.X);
                    r1.Height = (int)Math.Round(b.CharacterSize.Y);
                    r1.X = (int)Math.Round(b.Position.X);
                    r1.Y = (int)Math.Round(b.Position.Y);
                    foreach(var e in enemyList)
                    {
                        Random rand = new Random();
                        int randInt = rand.Next(1, 5);
                        double ratio = Math.Sqrt(e.ResizeRation);
                        r2.Width = (int)Math.Round(e.CharacterSize.X * ratio);
                        r2.Height = (int)Math.Round(e.CharacterSize.Y * ratio);
                        r2.X = (int)Math.Round(e.Position.X);
                        r2.Y = (int)Math.Round(e.Position.Y);
                        if(r1.Intersects(r2))
                        {
                            e.GetHit(b.Damage);
                            if (!e.IsAlive())
                            {
                                bool isBoss = e.GetType().ToString() == "MathInfection.Boss";
                                currentScore = 50;
                                if (isBoss)
                                {
                                    currentScore += 50;
                                }
                                switch(randInt)
                                {
                                    case 1:
                                        {
                                            vec = e.Position;
                                            hlist.Add(new Health(vec));
                                            hlist[index].drawIcon = true;
                                            index++;
                                            break;
                                        }
                                    case 2:
                                        {
                                            vec = e.Position;
                                            sList.Add(new Shield(vec));
                                            sList[index].drawShieldF = true;
                                            index++;
                                            break;
                                        }
                                    default: break;
                                }
                            }
                            b.IsValid = false;
                        }
                    }
                }
            }
            // endof Bullet Collision Detection
            index = 0;
            // Player Collision Detection
            r1.Width = (int)Math.Round(p1.CharacterSize.X);
            r1.Height = (int)Math.Round(p1.CharacterSize.Y);
            r1.X = (int)Math.Round(p1.PlayerPosition.X);
            r1.Y = (int)Math.Round(p1.PlayerPosition.Y);
            foreach (Enemy e in enemyList)
            {
                double ratio = Math.Sqrt(e.ResizeRation);
                r2.Width = (int)Math.Round(e.CharacterSize.X * ratio);
                r2.Height = (int)Math.Round(e.CharacterSize.Y * ratio);
                r2.X = (int)Math.Round(e.Position.X);
                r2.Y = (int)Math.Round(e.Position.Y);

                if (r1.Intersects(r2))
                {
                    if (shield_active)
                    {
                        shield_active = false;
                        p1.EnemyType = e.GetType().ToString();
                        e.Health = 0;
                        index++;
                    }
                    else
                    {
                        p1.WasHit = true;
                        p1.EnemyType = e.GetType().ToString();
                        e.Health = 0;
                        break;
                    }
                }
            }
            index = 0;
            while (index < hlist.Count)
            {
                if (hlist[index].drawIcon)
                {
                    r2.Width = (int)Math.Round(hlist[index].healthDimensions.X);
                    r2.Height = (int)Math.Round(hlist[index].healthDimensions.Y);
                    r2.X = (int)Math.Round(hlist[index].healthPosition.X);
                    r2.Y = (int)Math.Round(hlist[index].healthPosition.Y);

                    if (r1.Intersects(r2))
                    {
                        grabHealthInstance = grabHealth.Play();
                        hlist[index].drawIcon = false;
                        p1.Health += 5;
                    }
                }
                index++;
            }
            index = 0;
            while (index < sList.Count)
            {
                if (sList[index].drawShieldF)
                {
                    r2.Width = (int)sList[index].shield_sizeF.X;
                    r2.Width = (int)sList[index].shield_sizeF.Y;
                    r2.X = (int)sList[index].shield_positionF.X;
                    r2.Y = (int)sList[index].shield_positionF.Y;

                    if (r1.Intersects(r2))
                    {
                        grabShieldInstance = grabShield.Play();
                        sList[index].drawShieldF = false;
                        shield_active = true;

                    }
                }
                index++;
            }
        }