Example #1
0
 public Player(Level level, Texture2D[] towerTextures, Texture2D bulletTexture, ContentManager content)
 {
     this.level = level;
     this.towerTextures = towerTextures;
     this.bulletTexture = bulletTexture;
     this.content = content;
     upgradeTexture = content.Load<Texture2D>("upgrade");
     upgradeButton = new UpgradeButton();
 }
Example #2
0
 public Player(Level level, Texture2D[] towerTextures, Texture2D bulletTexture, ContentManager content)
 {
     this.level         = level;
     this.towerTextures = towerTextures;
     this.bulletTexture = bulletTexture;
     this.content       = content;
     upgradeTexture     = content.Load <Texture2D>("upgrade");
     upgradeButton      = new UpgradeButton();
 }
Example #3
0
        public void Update(GameTime gameTime, List <Enemy> enemies)
        {
            mouseState = Mouse.GetState();

            cellX = (int)(mouseState.X / 50);
            cellY = (int)(mouseState.Y / 50);

            tileX = cellX * 50;
            tileY = cellY * 50;

            if (mouseState.LeftButton == ButtonState.Released && oldState.LeftButton == ButtonState.Pressed)
            {
                if (string.IsNullOrEmpty(newTowerType) == false)
                {
                    AddTower();
                }
                else
                {
                    if (selectedTower != null)
                    {
                        if (!selectedTower.Bounds.Contains(mouseState.X, mouseState.Y))
                        {
                            selectedTower.Selected = false;
                            if (buttonVisible)
                            {
                                buttonVisible = false;
                            }
                        }
                    }

                    foreach (Tower tower in towers)
                    {
                        //if (tower==selectedTower)
                        //{
                        //  continue;
                        //}

                        if (tower.Bounds.Contains(mouseState.X, mouseState.Y))
                        {
                            selectedTower  = tower;
                            tower.Selected = true;
                            buttonVisible  = true;
                            upgradeButton  = new UpgradeButton(upgradeTexture, new Vector2(64, level.Height * 50));
                            if (money >= 10 && tower.UpgradeLevel <= 2)
                            {
                                buttonVisible = true;
                                //upgradeButton = new UpgradeButton(upgradeTexture, new Vector2(64, level.Height * 32-32));
                                upgradeButton = new UpgradeButton(upgradeTexture, new Vector2(tileX + 5, tileY - 24));
                            }
                        }
                    }
                }
            }

            foreach (Tower tower in towers)
            {
                if (tower.HasTarget == false)
                {
                    tower.GetClosestEnemy(enemies);
                }

                tower.Update(gameTime);
            }
            oldState = mouseState;

            upgradeButton.Update();

            if (upgradeButton.Clicked)
            {
                upgradeButton.Clicked = false;
                buttonVisible         = false;
                //ArrowTower at = (ArrowTower)selectedTower;
                selectedTower.Upgrade(selectedTower.UpgradeLevel);
                selectedTower.UpgradeLevel += 1;
                money -= 10;
            }
            // Game1.endText = String.Format("Score : {0}",money);
        }
Example #4
0
        public void Update(GameTime gameTime, List<Enemy> enemies)
        {
            mouseState = Mouse.GetState();

            cellX = (int)(mouseState.X / 50);
            cellY = (int)(mouseState.Y /50);

            tileX = cellX * 50;
            tileY = cellY * 50;

            if (mouseState.LeftButton == ButtonState.Released && oldState.LeftButton == ButtonState.Pressed)
            {

                if (string.IsNullOrEmpty(newTowerType) == false)
                {
                    AddTower();
                }
                else
                {
                    if (selectedTower != null)
                    {
                        if (!selectedTower.Bounds.Contains(mouseState.X, mouseState.Y))
                        {
                            selectedTower.Selected = false;
                            if (buttonVisible)
                                buttonVisible = false;
                        }
                    }

                    foreach (Tower tower in towers)
                    {
                        //if (tower==selectedTower)
                        //{
                          //  continue;
                        //}

                        if (tower.Bounds.Contains(mouseState.X, mouseState.Y))
                        {
                            selectedTower = tower;
                            tower.Selected = true;
                            buttonVisible = true;
                            upgradeButton = new UpgradeButton(upgradeTexture, new Vector2(64,level.Height*50));
                            if (money >= 10 && tower.UpgradeLevel <= 2)
                            {
                                buttonVisible = true;
                                //upgradeButton = new UpgradeButton(upgradeTexture, new Vector2(64, level.Height * 32-32));
                                upgradeButton = new UpgradeButton(upgradeTexture, new Vector2(tileX + 5, tileY - 24));

                            }
                        }
                    }
                }
            }

            foreach (Tower tower in towers)
            {
                if (tower.HasTarget == false)
                {
                    tower.GetClosestEnemy(enemies);
                }

                tower.Update(gameTime);
            }
            oldState = mouseState;

            upgradeButton.Update();

            if (upgradeButton.Clicked)
            {
                upgradeButton.Clicked = false;
                buttonVisible = false;
                //ArrowTower at = (ArrowTower)selectedTower;
                selectedTower.Upgrade(selectedTower.UpgradeLevel);
                selectedTower.UpgradeLevel += 1;
                money -= 10;
            }
               // Game1.endText = String.Format("Score : {0}",money);
        }