Ejemplo n.º 1
0
 public Projectile(Texture2D texture, Tower tower, Creep _aim)
 {
     text = texture;
     speed = 900f;
     thetower = tower;
     aim = _aim;
     boundingBox = new Rectangle(tower.boundingBox.Center.X, tower.boundingBox.Center.Y, 5, 15);
     destination = new Vector2(aim.boundingBox.Center.X, aim.boundingBox.Center.Y);
 }
Ejemplo n.º 2
0
 private void ClipTowersToCell(bool click)
 {
     foreach (var item in Map.map)
     {
         if (item.spacePos.Contains(mouse.fakePos))
         {
             if (item.type == Cell.CellTypes.Turret)
             {
                 if (click && item.contains == null)
                 {
                     Tower buf = new Tower(item.spacePos.Location, Tower.Types.type1, towersText[0]);
                     item.contains = buf;
                 }
                 clippedToMouse = new Tower(item.spacePos.Location, Tower.Types.type1, towersText[0]);
                 break;
             }
             else
             {
                 clippedToMouse = null;
             }
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            mainMenuButtons = new Texture2D[3];
            Map.map = Map.Parse("1.txt");
            debugFont = Content.Load<SpriteFont>("SpriteFont1");
            cam = new Camera();
            mainMenuButtons[0] = Content.Load<Texture2D>("PlayButton");
            mainMenuButtons[1] = Content.Load<Texture2D>("OptsButton");

            cellT = Content.Load<Texture2D>("Cell");

            font = Content.Load<SpriteFont>("SpriteFont1");

            towersText = new Texture2D[10];
            towersText[0] = Content.Load<Texture2D>("Tower");

            uiTextures = new Texture2D[10];
            uiTextures[0] = Content.Load<Texture2D>("planUI");

            clippedToMouse = new Tower(Point.Zero, Tower.Types.type1, towersText[0]);

            currentMenu = new Menus.MainMenu();
            gameUi = new InGameUI(uiTextures);
            ingamemenu = new Menus.InGameMenu(ref cam, "1.txt");
        }
Ejemplo n.º 4
0
 public Cell(CellTypes _type, Rectangle _spacePos)
 {
     type     = _type;
     contains = null;
     spacePos = _spacePos;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            mainMenuButtons = new Texture2D[3];
            map = Cell.Parse("1.txt");
            cam = new Camera(map);
            mainMenuButtons[0] = Content.Load<Texture2D>("PlayButton");
            mainMenuButtons[1] = Content.Load<Texture2D>("OptsButton");

            cellT = Content.Load<Texture2D>("Cell");

            font = Content.Load<SpriteFont>("SpriteFont1");

            towersText = new Texture2D[10];
            towersText[0] = Content.Load<Texture2D>("Tower");

            uiTextures = new Texture2D[10];
            uiTextures[0] = Content.Load<Texture2D>("planUI");
            mainMenu = new IMenu(GameState.MainMenu);
            mainMenu.AddButton("Play", font, mainMenuButtons[0], GameState.LoadingMenu);
            mainMenu.AddButton("Options", font, mainMenuButtons[1], GameState.Options);
            mainMenu.AddButton("Quit", font, mainMenuButtons[0], GameState.Quit, Color.Yellow);

            inGameMenu = new IMenu(GameState.InGameMenu);
            inGameMenu.AddButton("Play", font, mainMenuButtons[0], GameState.InGame);
            inGameMenu.AddButton("Main Menu", font, mainMenuButtons[1], GameState.MainMenu);

            clippedToMouse = new Tower(Point.Zero, Tower.Types.type1, towersText[0]);

            currentMenu = mainMenu;
            gameUi = new InGameUI(uiTextures);
        }
Ejemplo n.º 6
0
 private void Hover()
 {
     switch (inGameState)
     {
         case InGameState.Play:
             if (clippedToMouse != null)
             {
                 clippedToMouse = null;
             }
             break;
         case InGameState.Add:
             ClipTowersToCell(false);
             break;
         default:
             break;
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //Check if the window is active
            if (IsActive)
            {
                keyboard.Update();
                mouse.Update(cam, currentMenu);

                //If the current menu = null  we are in game
                if (currentMenu == null)
                {
                    if (!gameUi.textBounds[0].Contains(mouse.position))
                    {
                        if (mouse.LeftClickState == ClickState.Clicked)
                        {
                            LeftClick();
                        }
                        else if (mouse.LeftClickState == ClickState.Released)
                        {
                            Hover();
                        }
                        if (mouse.RightClickState == ClickState.Clicked)
                        {
                            RightClick();
                        }
                    }
                    else
                    {
                        if (clippedToMouse != null)
                        {
                            clippedToMouse = null;
                        }
                    }

                    gameUi.Update(mouse, keyboard);

                    if (keyboard.pressedKeysList.Contains(Keys.Escape))
                    {
                        currentMenu = ingamemenu;
                    }
                    wave.Update(gameTime, cellsWithTower);
                    for (int i = 0; i < cellsWithTower.Count; i++)
                    {
                        cellsWithTower[i].contains.Update(gameTime);
                    }

                    cam.Update(mouse, gameTime, gameUi);
                    if (playerLife == 0)
                    {
                        currentMenu = gameOverMenu;
                    }
                }

                else
                {
                    var oldMenuState = currentMenu.gameState;
                    var newMenu      = IMenu.UpdateMenu(mouse, currentMenu, keyboard);
                    if (newMenu != currentMenu)
                    {
                        currentMenu = newMenu;
                        if (currentMenu != null)
                        {
                            currentMenu.senderMenuState = oldMenuState;
                        }
                    }
                }
            }

            base.Update(gameTime);
        }
Ejemplo n.º 8
0
        private bool ClipTowersToCell(bool click)
        {
            var pos = mouse.fakePos;
            foreach (var item in Map.map)
            {
                if (item.spacePos.Contains(pos) && gold >= Tower.getAddCostByType(Tower.Types.type1))
                {
                    if (item.type == Cell.CellTypes.Turret && item.contains == null)
                    {
                        if (click && item.contains == null && gold >= Tower.getAddCostByType(Tower.Types.type1))
                        {
                            gold -= (int)(Tower.getAddCostByType(Tower.Types.type1));
                            Tower buf = new Tower(item.spacePos.Location, Tower.Types.type1, towersText[0], 100, false);
                            item.contains = buf;
                            cellsWithTower.Add(item);
                        }
                        if (clippedToMouse == null)
                        {
                            clippedToMouse = new Tower(item.spacePos.Location, Tower.Types.type1, towersText[0], 100, true);
                        }
                        else if (clippedToMouse.boundingBox != item.spacePos)
                        {
                            clippedToMouse.boundingBox = item.spacePos;
                        }
                        return true;
                    }

                    else
                    {
                        clippedToMouse = null;
                    }
                }
            }
            return false;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //Check if the window is active
            if (IsActive)
            {
                keyboard.Update();
                mouse.Update(cam, currentMenu);

                //If the current menu = null  we are in game
                if (currentMenu == null)
                {
                    if (!gameUi.textBounds[0].Contains(mouse.position))
                    {
                        if (mouse.LeftClickState == ClickState.Clicked)
                            LeftClick();
                        else if (mouse.LeftClickState == ClickState.Released)
                            Hover();
                        if (mouse.RightClickState == ClickState.Clicked)
                            RightClick();
                    }
                    else
                    {
                        if (clippedToMouse != null)
                        {
                            clippedToMouse = null;
                        }
                    }

                    gameUi.Update(mouse, keyboard);

                    if (keyboard.pressedKeysList.Contains(Keys.Escape))
                        currentMenu = ingamemenu;
                    wave.Update(gameTime, cellsWithTower);
                    for (int i = 0; i < cellsWithTower.Count; i++)
                    {
                        cellsWithTower[i].contains.Update(gameTime);
                    }

                    cam.Update(mouse, gameTime, gameUi);
                    if (playerLife == 0)
                        currentMenu = gameOverMenu;
                }

                else
                {
                    var oldMenuState = currentMenu.gameState;
                    var newMenu = IMenu.UpdateMenu(mouse, currentMenu, keyboard);
                    if (newMenu != currentMenu)
                    {
                        currentMenu = newMenu;
                        if (currentMenu != null)
                        {
                            currentMenu.senderMenuState = oldMenuState;
                        }
                    }
                }
            }

            base.Update(gameTime);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            Map.map = Map.Parse(currentMap);
            cellsWithTower = new List<Cell>();
            spriteBatch = new SpriteBatch(GraphicsDevice);
            mainMenuButtons = new Texture2D[3];
            towersText = new Texture2D[10];
            uiTextures = new Texture2D[10];

            cam = new Camera();
            cam.position = new Vector2(0, Map.initialPathLocation.Y - GraphicsDeviceManager.DefaultBackBufferHeight / 2);

            debugFont = Content.Load<SpriteFont>("SpriteFont1");
            font = Content.Load<SpriteFont>("SpriteFont1");

            creepText = Content.Load<Texture2D>("Creep");

            wave = new CreepWave(30);

            towerRange = Content.Load<Texture2D>("range");

            missileText = Content.Load<Texture2D>("Missile");

            mainMenuButtons[0] = Content.Load<Texture2D>("PlayButton");
            mainMenuButtons[1] = Content.Load<Texture2D>("OptsButton");

            cellT = Content.Load<Texture2D>("Cell");

            towersText[0] = Content.Load<Texture2D>("Tower");

            uiTextures[0] = Content.Load<Texture2D>("UIParts/UI_Bottom");
            uiTextures[1] = Content.Load<Texture2D>("Icons/deleteIcon");
            uiTextures[2] = Content.Load<Texture2D>("Icons/addIcon");
            uiTextures[3] = Content.Load<Texture2D>("Icons/upgradeIcon");

            currentMenu = new Menus.MainMenu();
            options = new Menus.Options(graphics);
            gameUi = new InGameUI(uiTextures, ref cellsWithTower);
            ingamemenu = new Menus.InGameMenu(ref cam, ref cellsWithTower, currentMap);
            gameOverMenu = new Menus.GameOverMenu(ref cam, ref cellsWithTower, currentMap);

            clippedToMouse = new Tower(Point.Zero, Tower.Types.type1, towersText[0], 100, false);
        }
Ejemplo n.º 11
0
 public void getDamage(Tower attackingTower)
 {
     life -= attackingTower.damage;
     if (life < 0)
     {
         life = 0;
         Game1.gold += 20;
     }
 }
Ejemplo n.º 12
0
        public static double DetectCreep(Creep creep, Tower tower)
        {
            //a^2+b^2=c^2
            //c = SQRT(a^2+b^2)
            List<Point> corners = new List<Point>();
            corners.Add(creep.boundingBox.Location);
            corners.Add(new Point(creep.boundingBox.Right, creep.boundingBox.Top));
            corners.Add(new Point(creep.boundingBox.Left, creep.boundingBox.Bottom));
            corners.Add(new Point(creep.boundingBox.Right, creep.boundingBox.Bottom));
            double smallest = double.MaxValue;
            foreach (var item in corners)
            {
                int deltaX = tower.boundingBox.Center.X - item.X;
                int deltaY = tower.boundingBox.Center.Y - item.Y;
                var dist = Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
                if (dist < smallest)
                {
                    smallest = dist;
                }
            }

            return smallest;
        }