private void HandleInput()
        {
            if (keystate.IsKeyDown(Keys.A) && prevKeystate.IsKeyUp(Keys.A))
            {
                tower = new ArrowTower(arrowTower, Vector2.Zero, bullet, 1, soundBank);
                if (tower.Cost <= money)
                {
                    towerPreview.ChangeTowerTexture(arrowTower);
                    towerPreview.ChangeRangeTexture(arrowRange, tower.Range);
                }

                else tower = null;
            }

            if (keystate.IsKeyDown(Keys.S) && prevKeystate.IsKeyUp(Keys.S))
            {
                tower = new SpikeTower(spikeTower, Vector2.Zero, bullet, 1, soundBank);
                if (tower.Cost <= money)
                {
                    towerPreview.ChangeTowerTexture(spikeTower);
                    towerPreview.ChangeRangeTexture(spikeRange, tower.Range);
                }

                else tower = null;
            }

            if (keystate.IsKeyDown(Keys.B) && prevKeystate.IsKeyUp(Keys.B))
            {
                tower = new BombTower(bombTower, Vector2.Zero, bullet, 1, soundBank);
                if (tower.Cost <= money)
                {
                    towerPreview.ChangeTowerTexture(bombTower);
                    towerPreview.ChangeRangeTexture(arrowRange, tower.Range);
                }

                else tower = null;
            }

            if (keystate.IsKeyDown(Keys.Space) && prevKeystate.IsKeyUp(Keys.Space))
            {
                Button waveButton = guiManager.GetButton("wave");

                if (waveButton.Visible)
                    waveManager.StartNextWave();
                waveButton.Visible = false;
            }
        }
        private void CreateTower()
        {
            Rectangle tempRect = new Rectangle(tileX, tileY, Engine.TileWidth, Engine.TileHeight);

            if (!towerManager.IsOnTower(tileX, tileY))
            {
                if (tower is ArrowTower)
                {
                    ArrowTower arrow = new ArrowTower(arrowTower,
                        new Vector2(tileX, tileY), bullet, 1, soundBank);
                    towerManager.AddTower(arrow);
                    money -= tower.Cost;
                    tower = null;
                }

                else if (tower is SpikeTower)
                {
                    SpikeTower spike = new SpikeTower(spikeTower,
                        new Vector2(tileX, tileY), bullet, 1, soundBank);
                    towerManager.AddTower(spike);
                    //money -= tower.Cost;
                    money -= 1;
                    tower = null;
                }

                else if (tower is BombTower)
                {
                    BombTower bomb = new BombTower(bombTower,
                        new Vector2(tileX, tileY), bullet, 1, soundBank);
                    towerManager.AddTower(bomb);
                    //money -= tower.Cost;
                    money -= 1;
                    tower = null;
                }

                else if (tower is OneandOneTower)
                {
                    OneandOneTower oneandone = new OneandOneTower(bombTower,
                        new Vector2(tileX, tileY), bullet, 1, soundBank);
                    towerManager.AddTower(oneandone);
                    money -= tower.Cost;
                    tower = null;
                }
                if (tower is ofLoveTower)
                {
                    ofLoveTower love = new ofLoveTower(ofLoveTower,
                        new Vector2(tileX, tileY), bullet, 1, soundBank);
                    towerManager.AddTower(love);
                    money -= tower.Cost;
                    soundBank.PlayCue("liebe2");
                    tower = null;
                }

            }
        }
        private void ButtonPressed(object sender)
        {
            Button button = sender as Button;

            if (button != null)
            {
                switch (button.Name)
                {
                    case "arrow":
                        tower = new ArrowTower(arrowTower, Vector2.Zero, bullet, 1, soundBank);
                        if (tower.Cost <= money)
                        {
                            towerPreview.ChangeTowerTexture(arrowTower);
                            towerPreview.ChangeRangeTexture(arrowRange, tower.Range);
                        }

                        else tower = null;

                        break;

                    case "spike":
                        tower = new SpikeTower(spikeTower, Vector2.Zero, bullet, 1, soundBank);
                        if (tower.Cost <= money)
                        {
                            towerPreview.ChangeTowerTexture(spikeTower);
                            towerPreview.ChangeRangeTexture(spikeRange, tower.Range);
                        }

                        else tower = null;
                        break;

                    case "bomb":
                        tower = new BombTower(bombTower, Vector2.Zero, bullet, 1, soundBank);
                        if (tower.Cost <= money)
                        {
                            towerPreview.ChangeTowerTexture(bombTower);
                            towerPreview.ChangeRangeTexture(arrowRange, tower.Range);
                        }

                        else tower = null;
                        break;

                    // button der 1und1 tower baut
                    case "oneandone":
                        tower = new OneandOneTower(oneandOneTower, Vector2.Zero, bullet, 1, soundBank);
                        if (tower.Cost <= money)
                        { //towerPreview.ChangeRangeTexture(arrowTower);
                            towerPreview.ChangeRangeTexture(arrowRange, tower.Range);
                        }
                        else tower = null;
                        break;

                    // Tower of  Love ersteller
                    case "oflove":
                        tower = new ofLoveTower(ofLoveTower, Vector2.Zero, bullet, 1, soundBank);
                        if (tower.Cost <= money)
                        {
                            towerPreview.ChangeTowerTexture(ofLoveTower);
                            towerPreview.ChangeRangeTexture(ofLoveRange, tower.Range);
                        }
                        else tower = null;
                        break;

                    case "nuclear":
                        if (100 <= money && nukularcount <= 2)
                        {
                            money -= 100;
                            nukularcount++;
                            soundBank.PlayCue("nukular3");

                            foreach (Enemy enemy in waveManager.GetEnemies())
                            {
                                enemy.IsDead = true;
                            }
                        }
                        break;

                    case "wave":
                        waveManager.StartNextWave();
                        button.Visible = false;
                        break;
                }
            }
        }
        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
            bool coveredByOtherScreen)
        {
            mouseState = Mouse.GetState();

            keystate = Keyboard.GetState();

            //this.Window.Title = "X : " + mouseState.X.ToString() + "    Y  : " + mouseState.Y.ToString();

            cellX = (int)(mouseState.X / Engine.TileWidth);
            cellY = (int)(mouseState.Y / Engine.TileHeight);

            tileX = cellX * Engine.TileWidth;
            tileY = cellY * Engine.TileHeight;

            HandleInput();

            waveManager.Update(gameTime);

            if (waveManager.CurrentWave.EnemyReachedEnd)
            {
                lives--;
                waveManager.CurrentWave.EnemyReachedEnd = false;
            }

            if (waveManager.waveFinished)
            {
                Button waveButton = guiManager.GetButton("wave");
                waveButton.Visible = true;
            }

            guiManager.Update(gameTime);

            if (mouseState.RightButton == ButtonState.Released && oldState.RightButton == ButtonState.Pressed)
            {
                tower = null;
                towerSelected = false;
            }

            if (IsInBounds(cellX, cellY) && this.IsActive && level.GetCellIndex(cellX, cellY) != 1)
            {
                if (mouseState.LeftButton == ButtonState.Released && oldState.LeftButton == ButtonState.Pressed)
                {
                    selectedTower = towerManager.IsTowerSelected(tileX, tileY);
                    if (selectedTower != null)
                    {
                        selectedTower.Selected = true;
                        towerSelected = true;
                        selectedTowerPos = selectedTower.Position;

                        if (selectedTower is ArrowTower || selectedTower is BombTower)
                        {
                            selectedType = 1;
                        }

                        else
                        {
                            selectedType = 2;
                        }
                    }

                    else
                    {
                        towerSelected = false;
                        CreateTower();
                    }
                }
            }

            if (towerSelected)
            {
                if (keystate.IsKeyDown(Keys.U) && prevKeystate.IsKeyUp(Keys.U))
                {
                    if (money >= selectedTower.CostNextLevel && selectedTower.Tier != 3)
                    {
                        money -= selectedTower.CostNextLevel;
                        selectedTower.Upgrade();
                    }
                }
            }

            towerManager.Update(gameTime, waveManager.GetEnemies());

            foreach (Enemy enemy in waveManager.GetEnemies())
            {
                if (enemy.IsDead)
                {
                    money += enemy.BountyGiven;
                }
            }

            prevKeystate = keystate;
            oldState = mouseState;

            audioEngine.Update();
        }
예제 #5
0
 public void AddTower(Tower tower)
 {
     towers.Add(tower);
 }
예제 #6
0
 public void AddTower(Tower tower)
 {
     towers.Add(tower);
 }