Example #1
0
        public void AddTower()
        {
            Tower towerToAdd = null;

            switch (_newTowerType)
            {
                case "FireTower":
                {
                    towerToAdd = new FireTower(_towerTexture,
                        _bulletTexture, new Vector2(_tileX, _tileY));
                    break;
                }
            }
            if (IsCellClear() == true && towerToAdd.Cost <= Money)
            {
                _towers.Add(towerToAdd);
                Money -= towerToAdd.Cost;

                // Reset the newTowerType field.
                _newTowerType = string.Empty;
            }
        }
Example #2
0
 public void Update(GameTime gameTime, List<Enemy> enemies)
 {
     _currentState = Mouse.GetState();
     _cellX = (int) (_currentState.X/Level.BlockSize);
     _cellY = (int) (_currentState.Y/Level.BlockSize);
     _tileX = _cellX*Level.BlockSize;
     _tileY = _cellY*Level.BlockSize;
     if (_currentState.LeftButton == ButtonState.Released && _oldState.LeftButton == ButtonState.Pressed)
     {
         if (IsCellClear())
         {
             var tower = new FireTower(_towerTexture, _bulletTexture,new Vector2(_tileX, _tileY));
             _towers.Add(tower);
         }
     }
     _oldState = _currentState;
     foreach (var tower in _towers)
     {
         if (tower.Target == null)
         {
             tower.SetTarget(enemies);
         }
         tower.Update(gameTime);
     }
 }