Ejemplo n.º 1
0
 /// <summary>Takes money from the player when purchasing a tower.</summary>
 /// <param name="_tower">The Tower being bought.</param>
 public void PurchaseTower(Tower _tower)
 {
     money -= _tower.Cost;
 }
Ejemplo n.º 2
0
 public void AddTowerToTile(Tower tower)
 {
     towerOnTile = tower;
 }
Ejemplo n.º 3
0
 public void DoFocusFire(Tower owner)
 {
     owner.currAttackTime += Time.FromSeconds((float)modBaseAttackTime[owner.level - 1]);
 }
Ejemplo n.º 4
0
 public void Replace(Tower owner, Tower target)
 {
     target.Replace(owner.position);
     target.LevelUp();
     owner.Death();
 }
Ejemplo n.º 5
0
 public void Absorb(Tower owner, Tower target)
 {
     owner.LevelUp();
     target.Death();
 }
Ejemplo n.º 6
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Reference page contains links to related code samples. </summary>
        ///
        /// <remarks>   Frost, 16.11.2010. </remarks>
        ///
        /// <param name="gameTime"> Time passed since the last call to Update. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        protected override void Update(GameTime gameTime)
        {
            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;

            base.Update(gameTime);

            audioEngine.Update();
            exitGameOnEsc();
        }
Ejemplo n.º 7
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Button pressed. </summary>
        ///
        /// <remarks>   Frost, 16.11.2010. </remarks>
        ///
        /// <param name="sender">   Source of the event. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        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;
                }
            }
        }