コード例 #1
0
        public void Update(GameTime gameTime, List <Enemy> enemies)
        {
            mouseState = Mouse.GetState();

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

            tileX = cellX * 32;
            tileY = cellY * 32;

            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;
                            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.Target == null)
                {
                    tower.GetClosestEnemy(enemies);
                }

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

            upgradeButton.Update();

            if (upgradeButton.Clicked)
            {
                upgradeButton.Clicked = false;
                buttonVisible         = false;
                ArrowTower at = (ArrowTower)selectedTower;
                at.Upgrade(selectedTower.UpgradeLevel);
                selectedTower.UpgradeLevel += 1;
                money -= 10;
            }
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: rohit12/BaseDefender
        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);
        }
コード例 #3
0
ファイル: Player.cs プロジェクト: krohini1593/BaseDefender
        public void Update(GameTime gameTime, List<Enemy> enemies)
        {
            mouseState = Mouse.GetState();

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

            tileX = cellX * 32;
            tileY = cellY * 32;

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

                    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 Button(upgradeTexture, new Vector2(32,level.Height*32 -32));
                        }
                    }
                }
            }

            foreach (Tower tower in towers)
            {
                if (tower.Target == null)
                {
                    tower.GetClosestEnemy(enemies);
                }

                tower.Update(gameTime);
            }

            oldState = mouseState;
        }