private DirectionButton FindButtonWithPriority(int priority, DirectionButton currentButton)
 {
     foreach (DirectionButton button in directionButtons)
     {
         if (button.Priority == priority && button != currentButton)
         {
             return(button);
         }
     }
     return(null);
 }
        public void Update(GameTime gameTime)
        {
            int             temp       = -1;
            DirectionButton prevButton = null;

            timer += (float)gameTime.ElapsedGameTime.TotalSeconds;

            foreach (DirectionButton button in directionButtons)
            {
                button.Update(gameTime);
                if (button.Pressed)
                {
                    sound.Play();
                    temp       = button.Priority;
                    prevButton = button;
                    if (timer >= 0.2f)
                    {
                        if (button.Priority < 3)
                        {
                            button.Priority++;
                        }
                        else
                        {
                            button.Priority = 0;
                        }
                        timer      = 0;
                        prevButton = FindButtonWithPriority(button.Priority, button);
                        if (prevButton != null)
                        {
                            prevButton.Priority = temp;
                        }
                    }
                    button.Pressed = false;
                }
            }
        }
Beispiel #3
0
        protected override void LoadContent()
        {
            fileScore = "Score.txt";
            fonMusic  = Content.Load <Song>("mainMusic");
            MediaPlayer.Play(fonMusic);
            MediaPlayer.Volume       = 0.2f;//0.1
            SoundEffect.MasterVolume = 0.2f;
            MediaPlayer.IsRepeating  = true;
            spriteBatch   = new SpriteBatch(GraphicsDevice);
            font          = Content.Load <SpriteFont>("File");
            pathTexture   = Content.Load <Texture2D>("path");
            grass         = Content.Load <Texture2D>("grass");//0
            hill          = Content.Load <Texture2D>("road7");
            start         = Content.Load <Texture2D>("start");
            finish        = Content.Load <Texture2D>("finish");
            enemy1Texture = Content.Load <Texture2D>("robot464");

            enemySkins.Add(0, enemy1Texture);
            enemySkins.Add(1, Content.Load <Texture2D>("robot64"));
            enemySkins.Add(2, Content.Load <Texture2D>("robot264"));
            enemySkins.Add(3, Content.Load <Texture2D>("robot364"));

            SoundEffect shot = Content.Load <SoundEffect>("arrowShot");

            sounds.Add("shot", shot);
            sounds.Add("frostShot", Content.Load <SoundEffect>("frostShot"));
            sounds.Add("fireShot", Content.Load <SoundEffect>("fireShot"));
            sounds.Add("button_pressed", Content.Load <SoundEffect>("button_pressed"));
            sounds.Add("buildingTower", Content.Load <SoundEffect>("buildingTower"));
            sounds.Add("deleteTower", Content.Load <SoundEffect>("deleteTower"));
            sounds.Add("upgradeTower", Content.Load <SoundEffect>("lvlup"));
            sounds.Add("enemyPassed", Content.Load <SoundEffect>("enemyPassed"));


            soundDeathRobot = Content.Load <SoundEffect>("deathRobot");

            Texture2D textureButTower = Content.Load <Texture2D>("towerButton");
            Texture2D textureButFrost = Content.Load <Texture2D>("buttonFrostTower");
            Texture2D textureButFire  = Content.Load <Texture2D>("buttonFireTower");

            Texture2D bulletTexture      = Content.Load <Texture2D>("bulletStandart");
            Texture2D bulletFireTexture  = Content.Load <Texture2D>("bullet");
            Texture2D bulletFrostTexture = Content.Load <Texture2D>("snowFl");

            Texture2D towerTexture      = Content.Load <Texture2D>("tower");
            Texture2D frostTowerTexture = Content.Load <Texture2D>("frostTower");
            Texture2D fireTowerTexture  = Content.Load <Texture2D>("fireTower");

            healthBarTexture = Content.Load <Texture2D>("healthBar");
            selectFrame      = Content.Load <Texture2D>("selectFrame");
            upgradeButton    = Content.Load <Texture2D>("upgrade2");

            DirectionButton directionButtonLeft  = new DirectionButton(new Vector2(level.Width * 64 + 150, level.Height * 64 - 670), pathTexture, font, "", 0);
            DirectionButton directionButtonRight = new DirectionButton(new Vector2(level.Width * 64 + 214, level.Height * 64 - 670), pathTexture, font, "", 1);
            DirectionButton directionButtonUp    = new DirectionButton(new Vector2(level.Width * 64 + 182, level.Height * 64 - 734), pathTexture, font, "", 2);
            DirectionButton directionButtonDown  = new DirectionButton(new Vector2(level.Width * 64 + 182, level.Height * 64 - 606), pathTexture, font, "", 3);

            ///directionButtons.Add(directionButtonRight); // 23.05
            directionButtons.Add(directionButtonLeft);
            directionButtons.Add(directionButtonRight);
            //directionButtons.Add(directionButtonUp);
            directionButtons.Add(directionButtonDown);
            directionButtons.Add(directionButtonUp);

            directionButtonManager = new DirectionButtonManager(directionButtons);

            towerTextureStorages.Add(new TowerTextureStorage(1, towerTexture, bulletTexture));
            towerTextureStorages.Add(new TowerTextureStorage(2, frostTowerTexture, bulletFrostTexture));
            towerTextureStorages.Add(new TowerTextureStorage(3, fireTowerTexture, bulletFireTexture));

            level.AddTexture(grass);
            level.AddTexture(hill);
            level.AddTexture(start);
            level.AddTexture(finish);
            upGrade = new ButtonUpgrade(new Vector2(level.Width * 64 + 10, level.Height * 64 - 60), upgradeButton, font, "");
            player  = new Player(level, towerTextureStorages, selectFrame, upGrade);

            waveManager = new WaveManager(player, level, 2, enemy1Texture, healthBarTexture, pathTexture);

            button      = new ButtonTower(new Vector2(level.Width * 64 + 10, level.Height * 64 - 630), textureButTower, font, "", ArrowTower.GetPrice, 1); // последний параметр это тип действия 1 - ставит башни обычные // 2 - морозные
            buttonFrost = new ButtonTower(new Vector2(level.Width * 64 + 10, level.Height * 64 - 560), textureButFrost, font, "", FrostTower.GetPrice, 2);
            buttonFire  = new ButtonTower(new Vector2(level.Width * 64 + 10, level.Height * 64 - 490), textureButFire, font, "", FireTower.GetPrice, 3);

            Texture2D buttonPlaytexture = Content.Load <Texture2D>("buttonPlay1");
            Texture2D buttonExitTexture = Content.Load <Texture2D>("buttonExit1");
            Button    startGameButton   = new Button(new Vector2(widthScreen / 2 - buttonPlaytexture.Width / 2, heightScreen - 640), buttonPlaytexture, font, "");//upgradeButton
            Button    exitButton        = new Button(new Vector2(widthScreen / 2 - buttonExitTexture.Width / 2, heightScreen - 390), buttonExitTexture, font, "");

            Button playAgain  = new Button(new Vector2(widthScreen / 2 - upgradeButton.Width / 2 + 10, heightScreen - 640), upgradeButton, font, "Играть еще раз");
            Button inMainMenu = new Button(new Vector2(widthScreen / 2 - upgradeButton.Width / 2 + 10, heightScreen - 570), upgradeButton, font, "В главное меню");

            buttonsMenuGameover.Add(playAgain);
            buttonsMenuGameover.Add(inMainMenu);

            buttonsMenu.Add(startGameButton);
            //buttonsMenu.Add(settingsButton);
            buttonsMenu.Add(exitButton);


            buttons.Add(buttonFrost);
            buttons.Add(button);
            buttons.Add(buttonFire);
            buttonManager = new ButtonManager(buttons, player);

            menu = new Menu(buttonsMenu);
            //gameOverMenu = new GameOverMenu(player, font, buttonsMenuGameover);
        }