예제 #1
0
        public Projectile(Tower parent, Enemy target, float speed, int index, string name = "")
        {
            if (name != "")
                Name = name;

            Parent = parent;
            Target = target;
            Speed = speed;

            Position = parent.Position;

            //TEST
            SpriteIndex = index;

            Enabled = true;

            if (parent.Name == "Glaive Tower")
            {
                HitEnemies = new List<Enemy>();
                isGlaive = true;
            }

            curRotation += 90;
        }
예제 #2
0
        public override void Update(GameTime gameTime)
        {
            if (GarrettTowerDefense.loadingScene)
                return;

            #region GUI and Input
            // Check if the game has to pause
            if(KeyboardHandler.KeyPress(Keys.Space))
            {
                PlayerPaused = !PlayerPaused;

                if (PlayerPaused)
                {
                    ClearMouseAction();
                    AudioManager.SetVolume(.25f);
                }
                else
                {
                    AudioManager.SetVolume(1f);
                }
            }

            // Check for mouse input and handle it accordingly
            HandleMouseInput(gameTime);

            if (MouseHandler.MouseOverMap() && CurrentMap[MouseHandler.MapY, MouseHandler.MapX].ContainsTower)
            {
                selectedTower = Towers.Find(x => x.MapPosition.X == MouseHandler.MapX && x.MapPosition.Y == MouseHandler.MapY);
            }
            else if(selectedTower != null)
            {
                selectedTower = null;
            }

            GUI.Update(gameTime);

            //Check for GUI input
            if (!PlayerPaused)
            {
                switch (GUI.currentInput)
                {
                    case GUIInput.BuildBarricade:
                        CurrentMouseAction = MouseAction.BuildBarricade;
                        LoadedPrice = Barricade.Cost;
                        break;
                    case GUIInput.BuildArrowTower:
                        CurrentMouseAction = MouseAction.BuildArrowTower;
                        LoadedPrice = ArrowTower.Cost;
                        break;
                    case GUIInput.BuildToxicTower:
                        CurrentMouseAction = MouseAction.BuildToxicTower;
                        LoadedPrice = ToxicTower.Cost;
                        break;
                    case GUIInput.BuildFlameTower:
                        CurrentMouseAction = MouseAction.BuildFlameTower;
                        LoadedPrice = FlameTower.Cost;
                        break;
                    case GUIInput.BuildTeslaTower:
                        CurrentMouseAction = MouseAction.BuildTeslaTower;
                        LoadedPrice = TeslaTower.Cost;
                        break;
                    case GUIInput.BuildIceTower:
                        CurrentMouseAction = MouseAction.BuildIceTower;
                        LoadedPrice = IceTower.Cost;
                        break;
                    case GUIInput.BuildGlaiveTower:
                        CurrentMouseAction = MouseAction.BuildGlaiveTower;
                        LoadedPrice = GlaiveTower.Cost;
                        break;
                    case GUIInput.BuildObservatory:
                        CurrentMouseAction = MouseAction.BuildObservatory;
                        LoadedPrice = Observatory.Cost;
                        break;
                    case GUIInput.BuildGoldMine:
                        CurrentMouseAction = MouseAction.BuildGoldMine;
                        LoadedPrice = GoldMine.Cost;
                        break;
                    default:
                        break;
                }
            }

            #endregion

            //Update each tower in turn
            if (!Paused && !PlayerPaused)
            {
                foreach (Tower t in Towers)
                {
                    t.Update(gameTime);
                }

                foreach (Enemy e in Enemies)
                {
                    if (e.Alive)
                        e.Update(gameTime);
                }

                for (int i = 0; i < Towers.Count; i++)
                {
                    if (Towers[i].Destroyed)
                    {
                        Towers.RemoveAt(i);
                    }
                }

                for (int i = 0; i < Enemies.Count; i++)
                {
                    if (!Enemies[i].Alive)
                        Enemies.RemoveAt(i);
                }
                //Should add an upgrade button and make this require MouseAction.Updrade instead of MouseAction.None.  Otherwise it's dumb.
                if (CurrentMouseAction == MouseAction.None && MouseHandler.MouseOverMap() && MouseHandler.RightClick())
                {
                    Vector2 mousepos = new Vector2(MouseHandler.CurrentMouseState.X, MouseHandler.CurrentMouseState.Y);
                    Point clickedtile = TileEngine.ScreenSpaceToMapSpace(mousepos);

                    Tower t = GameScene.Towers.Find(x => x.MapPosition == clickedtile);
                    if (t != null)
                    {
                        t.Upgrade();
                    }
                }

                //Update the wave manager.
                waveManager.Update(gameTime);
            }

            if (tooltip != null)
                tooltip.Update(gameTime);

            if (messageWindow != null)
                messageWindow.Update(gameTime);
        }
예제 #3
0
 public Projectile(Tower parent, Enemy target, float speed)
     : this(parent, target, speed, 13)
 {
 }
        public void OrbHit(Tower target)
        {
            AudioManager.PlaySoundEffect(16, .5f);

            orbAnimation = null;

            List<Tower> affectedTowers = GameScene.Towers.FindAll(x => x.Name == target.Name);
            foreach (Tower t in affectedTowers)
            {
                t.Stun(stunDuration);
            }

            nextOrbTime = (float)currentGameTime.TotalGameTime.TotalSeconds + orbCooldown;
        }
        public void FireOrb()
        {
            AudioManager.PlaySoundEffect(15, .5f);
            List<Tower> viableTargets = GameScene.Towers.FindAll(x => Vector2.Distance(x.Position, Position) <= orbRange);
            if (viableTargets.Count <= 0)
            {

                nextOrbTime = (float)currentGameTime.TotalGameTime.TotalSeconds + 4f;
                return;
            }

            Random rand = new Random();

            // Create the orb
            orbAnimation = new Animation(new int[] { 45 }, 0);
            orbPosition = Position;
            orbTarget = viableTargets[rand.Next(0, viableTargets.Count)];
        }
        public void FireBeam()
        {
            AudioManager.PlaySoundEffect(13, .5f);
            List<Tower> validTargets = GameScene.Towers.FindAll(x => Vector2.Distance(Position, x.Position) <= beamRange);
            if (validTargets.Count <= 0)
                return;

            Random rand = new Random();

            beamTarget = validTargets[rand.Next(0, validTargets.Count)];
            beamAnimation = new Animation(new int[] { 42, 43, 44 });
        }
 public void DestroyTowers(Tower[] towers)
 {
     foreach (Tower t in towers)
     {
         t.Sell(.5f);
         builtTowers.Remove(t);
     }
 }
        public void BeamHit(Tower target)
        {
            //KABLAMMO!

            target.LevelDown();
            if (target.Level <= 0)
            {
                target.Destroy();
            }
        }