Example #1
0
        void LoadMotionStep()
        {
            MotionStep.stepBoxImage = Game.Content.Load <Texture2D>("backgrounds/reference_level_step");
            motionStepList.Add(new MotionStep(new Vector2(1100, 80)));
            MotionStep step = motionStepList[0];

            step.xRight = 1190;
            step.xLeft  = 1100;

            motionStepList.Add(new MotionStep(new Vector2(1280, 150)));
            step        = motionStepList[1];
            step.xRight = 1380;
            step.xLeft  = 1280;

            motionStepList.Add(new MotionStep(new Vector2(1450, 150)));
            step        = motionStepList[2];
            step.xRight = 1535;
            step.xLeft  = 1450;

            motionStepList.Add(new MotionStep(new Vector2(2700, 150)));
            step        = motionStepList[3];
            step.xRight = 3400;
            step.xLeft  = 2700;
        }
Example #2
0
        public override void Update(GameTime gameTime)
        {
            if ((player.currentHP <= 0) || (player.yPos > 190))
            {
                System.Threading.Thread.Sleep(1000);
                Game.Exit();
            }

            player.Update(gameTime);

            if (player.pulledTheTrigger && (!player.isInvulnerable || player.invulnCounter > 15))
            {
                if (player.isBlaster && blaster.countBull > 0)
                {
                    blaster.MakeBullet(blastBulObj, player);
                }

                /* if (player.isBoomerang && boomerang.countBull > 0)//Если в руках бумеранг
                 *   boomerang.MakeBoom(boomBulObj, player);*/

                if (player.isLauncher && grenade.countBull > 0)//Стреляем гранатометом
                {
                    grenade.MakeBoom(granBulObj, player);
                }
            }
            if (player.isBlaster)//Стреляем из бластера
            {
                blaster.Fire(blastBulObj, gameTime, cameraXPos);
            }

            /*if (player.isBoomerang)
             *  boomerang.Fire(boomBulObj, gameTime, cameraXPos);*/
            if (player.isLauncher)//Стреляем гранатометом
            {
                grenade.Fire(granBulObj, gameTime, cameraXPos);
            }

            for (int i = 0; i < bulletObjectList.Count; ++i)//Игрок собирает пули для бластера
            {
                Sprite bullet = bulletObjectList[i];

                if (player.boundingBox.Intersects(bullet.boundingBox))
                {
                    blaster.countBull++;
                    bulletObjectList.RemoveAt(0);
                    --i;
                }
            }

            for (int i = 0; i < heartObjectList.Count; ++i)//Игрок собирает жизни
            {
                Sprite heart = heartObjectList[i];

                if ((player.boundingBox.Intersects(heart.boundingBox)) && (player.currentHP < 100))
                {
                    player.currentHP += 5;
                    heartObjectList.RemoveAt(0);
                    --i;
                }
            }

            for (int i = 0; i < waterObjectList.Count; ++i)//Игрок собирает воду
            {
                Sprite water = waterObjectList[i];

                if ((player.boundingBox.Intersects(water.boundingBox)))
                {
                    player.waterCount++;
                    waterObjectList.RemoveAt(0);
                    --i;
                }
            }

            for (int i = 0; i < foodObjectList.Count; ++i)//Игрок собирает еду
            {
                Sprite food = foodObjectList[i];

                if ((player.boundingBox.Intersects(food.boundingBox)))
                {
                    player.foodCount++;
                    foodObjectList.RemoveAt(0);
                    --i;
                }
            }

            for (int i = 0; i < oilObjectList.Count; ++i)//Игрок собирает топливо
            {
                Sprite oil = oilObjectList[i];

                if ((player.boundingBox.Intersects(oil.boundingBox)))
                {
                    player.oilCount++;
                    oilObjectList.RemoveAt(0);
                    --i;
                }
            }
            for (int i = 0; i < monsterBoomList.Count; ++i)//Проверка на различные взаимодействия птицы
            {
                Monster bird = monsterBoomList[i];
                bird.Update(gameTime);
                int hitCount = 0;
                for (int j = 0; j < boomBulObj.Count; ++j)
                {
                    Sprite boom = boomBulObj[j];

                    if (boom.boundingBox.Intersects(bird.boundingBox))
                    {
                        boomBulObj.RemoveAt(j);
                        --j;
                        ++hitCount;
                    }
                }
                int count = 0;
                while ((grenade.timerThis >= 0) && (count != granBulObj.Count))
                {
                    Sprite pp = granBulObj[count];
                    if (grenade.timerThis == 0)
                    {
                        var distanceToMonster = Math.Sqrt(Math.Pow((pp.xPos - bird.xPos), 2) + Math.Pow((pp.yPos - bird.yPos), 2));
                        if (distanceToMonster <= grenade.radiusFire)
                        {
                            granBulObj.RemoveAt(count);
                            --count;
                            ++hitCount;
                        }
                    }
                    else
                    {
                        grenade.timerThis--;
                    }
                    count++;
                }
                if (hitCount > 0)
                {
                    bird.isHit      = true;
                    bird.currentHP -= hitCount;
                    if (bird.currentHP <= 0)
                    {
                        score += monsterBoomList[i].maxHP;
                        monsterBoomList.RemoveAt(i);
                        --i;
                    }
                }
                else if (bird.boundingBox.Intersects(player.boundingBox))
                {
                    player.PlayerIsHit();
                }
            }
            for (int i = 0; i < monsterBullList.Count; ++i)//Проверка на различные взаимодействия монстров
            {
                Monster monster = monsterBullList[i];
                if (monster.maxHP == 1)
                {
                    if (Math.Abs(monster.yPos - player.yPos) < 35)
                    {
                        if ((monster.xPos - player.xPos) < 32)
                        {
                            if ((monster.xPos - player.xPos) > 0)
                            {
                                monster.isLeftOfPlayer = true;
                            }
                            else if ((player.xPos - monster.xPos) < 42)
                            {
                                if ((player.xPos - monster.xPos) > 10)
                                {
                                    monster.isRightOfPlayer = true;
                                }
                            }
                        }
                    }
                }
                monster.Update(gameTime);
                int hitCount = 0;
                for (int j = 0; j < blastBulObj.Count; ++j)
                {
                    Sprite p = blastBulObj[j];
                    if (p.boundingBox.Intersects(monster.boundingBox))
                    {
                        blastBulObj.RemoveAt(j);
                        --j;
                        ++hitCount;
                    }
                }
                int kol = 0;
                while ((grenade.timerThis >= 0) && (kol != granBulObj.Count))
                {
                    Sprite pp = granBulObj[kol];
                    if (grenade.timerThis == 0)
                    {
                        var distanceToMonster = Math.Sqrt(Math.Pow((pp.xPos - monster.xPos), 2) + Math.Pow((pp.yPos - monster.yPos), 2));
                        if (distanceToMonster <= grenade.radiusFire)
                        {
                            granBulObj.RemoveAt(kol);
                            --kol;
                            ++hitCount;
                        }
                    }
                    else
                    {
                        grenade.timerThis--;
                    }
                    kol++;
                }
                for (int t = 0; t < motionStepList.Count; ++t)//Обновляем движущиеся платформы
                {
                    MotionStep motionStep = motionStepList[t];
                    motionStep.Update(gameTime);
                }
                if (hitCount > 0)
                {
                    monster.isHit      = true;
                    monster.currentHP -= hitCount;
                    if (monster.currentHP <= 0)
                    {
                        score += monsterBullList[i].maxHP;
                        monsterBullList.RemoveAt(i);
                        --i;
                    }
                }

                else if (monster.boundingBox.Intersects(player.boundingBox))
                {
                    player.PlayerIsHit();
                }
            }

            player.FlashPlayerAndUpdateVulnerability();

            CheckForTerrainCollisions();

            MoveCamera_X();

            base.Update(gameTime);
        }