Esempio n. 1
0
 internal void HandleInput(InputHandler inputHandler)
 {
     if (inputHandler.SelectionContext == SelectionContext.PlacingTower && inputHandler.SelectionInGameBounds())
     {
         Tower t = inputHandler.SelectedObject as Tower;
         if (GameStats.Gold >= t.Cost)
         {
             GameStats.Gold = GameStats.Gold - t.Cost;
             towerlist.Add(t);
             t.Position = inputHandler.Position;
             inputHandler.CancelSelection();
             ResourceManager.WallSound.Play();
         }
         else
         {
             MessageLog.NotEnoughGold();
         }
     }
     else
     {
         towerlist.ForEach(t =>
         {
             if (t.BoundingBox().Contains(inputHandler.Position))
             {
                 inputHandler.CancelSelection();
                 inputHandler.SelectionContext = SelectionContext.TowerSelected;
                 t.Selected = true;
                 inputHandler.SelectedObject = t;
             }
         });
     }
 }
Esempio n. 2
0
        internal void StartLevel(List <Node> bestPath)
        {
            GameStats.AttackPhase = true;
            GameStats.Level++;
            MessageLog.Level(GameStats.Level);
            Random random = new Random();

            double num = random.NextDouble();

            if (num < .3)
            {
                for (int i = 0; i < (30 + GameStats.Level * 2); i++)
                {
                    delayedActions.Add(new DelayedAction(() => enemylist.Add(new Enemy(GameStats.Level * 4, 4, ResourceManager.Enemy, new List <Node>(bestPath), "Malaria")), i * 400));
                }
            }
            else if (num < .6)
            {
                for (int i = 0; i < (20 + GameStats.Level * 1.5); i++)
                {
                    delayedActions.Add(new DelayedAction(() => enemylist.Add(new Enemy(GameStats.Level * 8, 2, ResourceManager.Enemy, new List <Node>(bestPath), "Tuberculosis")), i * 400));
                }
            }
            else
            {
                for (int i = 0; i < (20 + GameStats.Level); i++)
                {
                    delayedActions.Add(new DelayedAction(() => enemylist.Add(new Enemy(GameStats.Level * 16, 1, ResourceManager.Enemy, new List <Node>(bestPath), "AIDS")), i * 1000));
                }
            }
        }
Esempio n. 3
0
        internal void Update(GameTime gameTime, InputHandler inputHandler)
        {
            delayedActions.RemoveAll(d => d.Update(gameTime));
            if (GameStats.AttackPhase)
            {
                enemylist.RemoveAll(e => e.Update(gameTime, inputHandler));
                towerlist.ForEach(t =>
                {
                    projectilelist = t.Attack(enemylist, projectilelist, gameTime.TotalGameTime.TotalSeconds, (d, p) =>
                    {
                        floatingTextList.Add(new FloatingText(p, ResourceManager.GameFont, d.ToString()));
                    });
                });
                projectilelist.RemoveAll(p => p.Move());

                if (enemylist.Count == 0 && delayedActions.Count == 0)
                {
                    GameStats.AttackPhase = false;
                    projectilelist.Clear();
                    MessageLog.LevelComplete(GameStats.Level * 2 + (int)(GameStats.Gold * .05f), GameStats.Level);
                    GameStats.Gold = GameStats.Gold + (GameStats.Level * 2 + (int)(GameStats.Gold * .05f));
                }
            }

            floatingTextList.RemoveAll(f => f.Update(gameTime));
            towerlist.RemoveAll(t => t.Update(gameTime, inputHandler));
            if (inputHandler.SelectionOccurring && !inputHandler.SelectionHandled)
            {
                HandleInput(inputHandler);
            }
        }
Esempio n. 4
0
        internal void Draw(SpriteBatch batch)
        {
            startButton.Draw(batch);
            constructionCard.Draw(batch);
            actionCard.Draw(batch);

            batch.DrawString(ResourceManager.GameFont, "GOLD - " + GameStats.Gold + " $", new Vector2(Constants.GameSize.X * .8f, Constants.GameSize.Y * .1f), Color.Black, 0, new Vector2(0, 0), 1.0f, SpriteEffects.None, 0.5f);
            MessageLog.Draw(batch, ResourceManager.GameFont);
        }
Esempio n. 5
0
        public override bool Update(GameTime gameTime, InputHandler inputHandler)
        {
            if (HP <= 0)
            {
                color.R -= 15;
                color.G -= 15;
                color.B -= 15;
                return(color == Color.Black);
            }

            if (Position != currentDest)
            {
                Point diff = currentDest - Position;

                // Prefer vertical movement, eliminate diagonal movement
                Position += new Point(diff.Y == 0 ? speed * Math.Sign(diff.X) : 0, speed * Math.Sign(diff.Y));
                anim      = diff.Y == 0 ? diff.X < 0 ? VampireAnim.Left : VampireAnim.Right : diff.Y < 0 ? VampireAnim.Up : VampireAnim.Down;
            }
            else
            {
                if (bestPath.Count > 1)
                {
                    Node CurrentNode = bestPath[0];
                    bestPath.Remove(CurrentNode);
                    if (CurrentNode.portal && CurrentNode.portalsTo != null)
                    {
                        Position = CurrentNode.portalsTo.actualPos;
                        ResourceManager.PortalSound.Play();
                    }
                    CurrentNode = bestPath[0];
                    currentDest = CurrentNode.actualPos;
                }
                else
                {
                    GameStats.PlayerLoses = true;
                    MessageLog.GameOver();

                    //TODO not this
                    currentDest = new Point(400, 736);
                }
            }

            return(base.Update(gameTime, inputHandler));
        }
Esempio n. 6
0
        public void HandleInput(InputHandler inputHandler)
        {
            switch (ButtonType)
            {
            case ButtonType.GenericTowerButton:
            case ButtonType.CannonTowerButton:
            case ButtonType.BatteryTowerButton:
            case ButtonType.BlastTowerButton:
                inputHandler.CancelSelection();
                inputHandler.SelectionContext = SelectionContext.PlacingTower;
                inputHandler.SelectedObject   = CreateTowerInstance();
                break;

            case ButtonType.WallButton:
                inputHandler.CancelSelection();
                inputHandler.SelectionContext = SelectionContext.PlacingWall;
                break;

            case ButtonType.PortalButton:
                inputHandler.CancelSelection();
                inputHandler.SelectionContext = SelectionContext.PlacingPortalEntrance;
                break;

            case ButtonType.CheeseButton:
                inputHandler.CancelSelection();
                inputHandler.SelectionContext = SelectionContext.PlacingCheese;
                break;

            case ButtonType.SellButton:
            {
                if (inputHandler.SelectionContext == SelectionContext.TowerSelected)
                {
                    Tower t = inputHandler.SelectedObject as Tower;
                    t.Sell();
                    inputHandler.CancelSelection();
                }
                if (inputHandler.SelectionContext == SelectionContext.NodeSelected)
                {
                    Node n = inputHandler.SelectedObject as Node;
                    n.Sell();
                    inputHandler.CancelSelection();
                }
            }
            break;

            case ButtonType.UpgradeButton:
            {
                Tower t = inputHandler.SelectedObject as Tower;
                if (GameStats.Gold >= t.Cost)
                {
                    GameStats.Gold = GameStats.Gold - t.Cost;
                    t.upgrade();
                }
                else
                {
                    MessageLog.NotEnoughGold();
                }
            }
            break;

            case ButtonType.CancelButton:
                inputHandler.CancelSelection();
                break;
            }
        }
Esempio n. 7
0
 private void HandleInput(InputHandler inputHandler, Node n)
 {
     if (!GameStats.AttackPhase)
     {
         if (!n.IsEmpty && inputHandler.SelectionContext == SelectionContext.None)
         {
             inputHandler.SelectionContext = SelectionContext.NodeSelected;
             inputHandler.SelectedObject   = n;
             n.Selected = true;
             return;
         }
         if (!n.IsEmpty)
         {
             return;
         }
         if (inputHandler.SelectionContext == SelectionContext.PlacingWall)
         {
             if (!CheckForPath(n.simplePos.X, n.simplePos.Y, inputHandler, CheckForPathType.TogglingWall))
             {
                 MessageLog.IllegalPosition();
             }
             else if (GameStats.Gold >= 1)
             {
                 n.wall = true;
                 n.UpdateTex(ResourceManager.Wall);
                 GameStats.Gold = GameStats.Gold - 1;
                 ResourceManager.WallSound.Play();
                 inputHandler.SelectionHandled = true;
             }
             else
             {
                 MessageLog.NotEnoughGold();
             }
         }
         else if (inputHandler.SelectionContext == SelectionContext.PlacingPortalEntrance)
         {
             n.portal = true;
             n.UpdateTex(ResourceManager.Portal);
             inputHandler.PortalEntrance   = n;
             inputHandler.SelectionContext = SelectionContext.PlacingPortalExit;
         }
         else if (inputHandler.SelectionContext == SelectionContext.PlacingPortalExit)
         {
             Node portalExit     = n;
             Node portalEntrance = inputHandler.PortalEntrance;
             if (!CheckForPath(portalExit.simplePos.X, portalExit.simplePos.Y, inputHandler, CheckForPathType.AddingPortal))
             {
                 MessageLog.IllegalPosition();
             }
             else if (GameStats.Gold >= 20)
             {
                 portalExit.portal = true;
                 portalExit.UpdateTex(ResourceManager.Portal);
                 portalExit.portalsTo          = portalEntrance;
                 portalEntrance.portalsTo      = portalExit;
                 inputHandler.SelectionContext = SelectionContext.PlacingPortalEntrance;
                 GameStats.Gold = GameStats.Gold - 20;
             }
             else
             {
                 MessageLog.NotEnoughGold();
             }
         }
         else if (inputHandler.SelectionContext == SelectionContext.PlacingCheese)
         {
             if (!CheckForPath(n.simplePos.X, n.simplePos.Y, inputHandler, CheckForPathType.TogglingCheese))
             {
                 MessageLog.IllegalPosition();
             }
             else if (GameStats.Gold >= 20)
             {
                 n.cheese = true;
                 n.UpdateTex(ResourceManager.Cheese);
                 GameStats.Gold = GameStats.Gold - 20;
                 ResourceManager.WallSound.Play();
             }
             else
             {
                 MessageLog.NotEnoughGold();
             }
         }
     }
 }