예제 #1
0
        public void Update(GameTime gameTime, ref PathView path)
        {
            this.enemies = waveHandler.GetCurrentWave().enemies;
            mouse.Update();

            // Finding out what cell in the array the mouse pointer is
            cellX = (int)(mouse.currentMouseState.X / 32);
            cellY = (int)((mouse.currentMouseState.Y - 24) / 32);

            // Only enter if you are releasing Left mouse and you are inside the array of the map
            if (mouse.ReleaseLeftClick && (map.Height - 1) >= cellY && (map.Width - 1) >= cellX && cellX >= 0 && cellY >= 0)
            {
                // Only enter if you have selected a tower you want to place and the round has not started
                if (newTowerType != 0 && !waveHandler.WaveStarted())
                {
                    // set the tower you want to upgrade to null
                    selectedTower = null;

                    // Only enter if there is something in the map array placed on the position you  have clicked
                    // and the newtowertype is 3(Which is the delete)
                    if (map.GetIndex(cellX, cellY) != 0 && towers[cellX, cellY] != null && newTowerType == 3)
                    {
                        // getting the type of tower you want to sell
                        int sellType = map.GetIndex(cellX, cellY);

                        // If tower is type one, which is a not an attacking tower you will get all you money back
                        // if not then 50% back
                        if (sellType == 1)
                        {
                            gold += Tower.GetCost(sellType);
                        }
                        else
                        {
                            gold += (int)(Tower.GetCost(sellType) * 0.5f);
                        }

                        // Add 0 to the position where the tower used to be.
                        map.AddToMap(cellX, cellY, 0);
                        // Remove the tower object by setting it to null
                        towers[cellX, cellY] = null;
                        // Sending the edited map in to the pathfinder again to get new path
                        Pathfinder p = new Pathfinder(map);
                        List<Vector2> newPath = p.FindPath(new Point(0, 0), new Point(map.Width - 1, map.Height - 1));
                        // send new path to the Pathview class to show new path
                        path.Path = newPath;
                        // send new path to the units so they know the new path when they start walking
                        Unit.Path = newPath;
                    }
                    // Only enter if there is nothing on that position of the map and you have the
                    // not pressed the delete tower button
                    else if (map.GetIndex(cellX, cellY) == 0 && newTowerType != 3)
                    {
                        // only enter if you have enough gold
                        if (gold >= Tower.GetCost(newTowerType))
                        {
                            gold -= Tower.GetCost(newTowerType);
                            // Add tower to the map
                            map.AddToMap(cellX, cellY, newTowerType);
                            Pathfinder p = new Pathfinder(map);
                            List<Vector2> t = p.FindPath(new Point(0, 0), new Point(map.Width - 1, map.Height - 1));

                            // After checking new path. if count == 0 the path is blocked off and there is no way
                            // for the creeps to go. So remove the point added to the map refund money and tell the
                            // player
                            if (t.Count == 0)
                            {
                                map.AddToMap(cellX, cellY, 0);
                                toast.AddMessage("ಠ_ಠ Du är for dårlig at bygga tårn.");
                                gold += Tower.GetCost(newTowerType);
                            }
                            else
                            {
                                // Add new path to pathview and the units
                                path.Path = t;
                                Unit.Path = t;
                                // add new tower object to the array
                                towers[cellX, cellY] = new Tower(newTowerType, cellX, cellY);
                            }
                        }
                        else
                        {
                            // Player does not have enough gold tell them
                            toast.AddMessage("(╯°□°)╯︵ ʎǝuoɯ ǝɹoɯ ou");
                        }
                    }
                }else if (towers[cellX, cellY] != null && newTowerType == 0 && towers[cellX, cellY].Type != 1)
                {
                    // Select tower you want to upgrade
                    selectedTower = towers[cellX, cellY];
                }
            }
            if (mouse.ReleaseRightClick)
            {
                // Deselect towers you want to upgrade or build.
                newTowerType = 0;
                selectedTower = null;
            }
            // Go through the array of the tower objects to tell them the new position of the enemies
            for (int y = 0; y < towers.GetLength(1); y++)
            {
                for (int x = 0; x < towers.GetLength(0); x++)
                {
                    if (towers[x, y] != null)
                    {
                        towers[x, y].Update(ref enemies, gameTime);
                    }
                }
            }
        }
예제 #2
0
파일: Player.cs 프로젝트: Fumler/Immunity
        public void Update(GameTime gameTime, ref PathView path)
        {
            this.enemies = waveHandler.GetCurrentWave().enemies;
            mouse.Update();

            // Finding out what cell in the array the mouse pointer is
            cellX = (int)(mouse.currentMouseState.X / 32);
            cellY = (int)((mouse.currentMouseState.Y - 24) / 32);

            // Only enter if you are releasing Left mouse and you are inside the array of the map
            if (mouse.ReleaseLeftClick && (map.Height - 1) >= cellY && (map.Width - 1) >= cellX && cellX >= 0 && cellY >= 0)
            {
                // Only enter if you have selected a tower you want to place and the round has not started
                if (newTowerType != 0 && !waveHandler.WaveStarted())
                {
                    // set the tower you want to upgrade to null
                    selectedTower = null;

                    // Only enter if there is something in the map array placed on the position you  have clicked
                    // and the newtowertype is 3(Which is the delete)
                    if (map.GetIndex(cellX, cellY) != 0 && towers[cellX, cellY] != null && newTowerType == 3)
                    {
                        // getting the type of tower you want to sell
                        int sellType = map.GetIndex(cellX, cellY);

                        // If tower is type one, which is a not an attacking tower you will get all you money back
                        // if not then 50% back
                        if (sellType == 1)
                        {
                            gold += Tower.GetCost(sellType);
                        }
                        else
                        {
                            gold += (int)(Tower.GetCost(sellType) * 0.5f);
                        }

                        // Add 0 to the position where the tower used to be.
                        map.AddToMap(cellX, cellY, 0);
                        // Remove the tower object by setting it to null
                        towers[cellX, cellY] = null;
                        // Sending the edited map in to the pathfinder again to get new path
                        Pathfinder     p       = new Pathfinder(map);
                        List <Vector2> newPath = p.FindPath(new Point(0, 0), new Point(map.Width - 1, map.Height - 1));
                        // send new path to the Pathview class to show new path
                        path.Path = newPath;
                        // send new path to the units so they know the new path when they start walking
                        Unit.Path = newPath;
                    }
                    // Only enter if there is nothing on that position of the map and you have the
                    // not pressed the delete tower button
                    else if (map.GetIndex(cellX, cellY) == 0 && newTowerType != 3)
                    {
                        // only enter if you have enough gold
                        if (gold >= Tower.GetCost(newTowerType))
                        {
                            gold -= Tower.GetCost(newTowerType);
                            // Add tower to the map
                            map.AddToMap(cellX, cellY, newTowerType);
                            Pathfinder     p = new Pathfinder(map);
                            List <Vector2> t = p.FindPath(new Point(0, 0), new Point(map.Width - 1, map.Height - 1));

                            // After checking new path. if count == 0 the path is blocked off and there is no way
                            // for the creeps to go. So remove the point added to the map refund money and tell the
                            // player
                            if (t.Count == 0)
                            {
                                map.AddToMap(cellX, cellY, 0);
                                toast.AddMessage("ಠ_ಠ Du är for dårlig at bygga tårn.");
                                gold += Tower.GetCost(newTowerType);
                            }
                            else
                            {
                                // Add new path to pathview and the units
                                path.Path = t;
                                Unit.Path = t;
                                // add new tower object to the array
                                towers[cellX, cellY] = new Tower(newTowerType, cellX, cellY);
                            }
                        }
                        else
                        {
                            // Player does not have enough gold tell them
                            toast.AddMessage("(╯°□°)╯︵ ʎǝuoɯ ǝɹoɯ ou");
                        }
                    }
                }
                else if (towers[cellX, cellY] != null && newTowerType == 0 && towers[cellX, cellY].Type != 1)
                {
                    // Select tower you want to upgrade
                    selectedTower = towers[cellX, cellY];
                }
            }
            if (mouse.ReleaseRightClick)
            {
                // Deselect towers you want to upgrade or build.
                newTowerType  = 0;
                selectedTower = null;
            }
            // Go through the array of the tower objects to tell them the new position of the enemies
            for (int y = 0; y < towers.GetLength(1); y++)
            {
                for (int x = 0; x < towers.GetLength(0); x++)
                {
                    if (towers[x, y] != null)
                    {
                        towers[x, y].Update(ref enemies, gameTime);
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            gameState       = GameState.Menu;
            gameStateNumber = true;

            input           = new Input();
            toast           = new MessageHandler(width, height);
            networkMessages = new MessageHandler(width, height);
            userName        = new TextInput(new Rectangle((width / 2) - 100, (height / 2) - 10, 200, 20));
            lobbyName       = new TextInput(new Rectangle(100, 200, 200, 20));
            chatBox         = new TextInput(new Rectangle(100, height - 40, 600, 20));
            network         = new Network();
            chatlog         = new List <string>();
            lobbyList       = new List <Gui>();

            // Action bar objects
            actionButtons = new List <Button>();
            actionButtons.Add(new Button(new Rectangle(5, height - ACTIONBUTTONOFFSET_X, 60, 60), "10", "Basic ranged tower, medium damage, medium firing speed, medium ammunition speed, single target. 100 gold - 50% return", Keys.D1, 1));
            actionButtons.Add(new Button(new Rectangle(5 + ACTIONBUTTONOFFSET_X, height - ACTIONBUTTONOFFSET_X, 60, 60), "20", "Fast ranged tower, low damage, high firing speed, fast ammunition speed, single target. 200 gold - 50% return", Keys.D2, 3));
            actionButtons.Add(new Button(new Rectangle(width - (ACTIONBUTTONOFFSET_X * 2), height - ACTIONBUTTONOFFSET_X, 60, 60), "3", "Deletes a tower, 50% gold return for normal towers, 100% for walls.", Keys.D, 5));
            actionButtons.Add(new Button(new Rectangle(width - ACTIONBUTTONOFFSET_X, height - ACTIONBUTTONOFFSET_X, 60, 60), "0", "Starts a new wave.", Keys.N, 6));
            actionButtons.Add(new Button(new Rectangle(width - (ACTIONBUTTONOFFSET_X * 3), height - ACTIONBUTTONOFFSET_X, 60, 60), "1", "Place a blocking tower. 5 gold - 100% return.", Keys.D3, 15));

            // Upgrade tower button
            upgradeTowerButton = new Button(new Rectangle(0, 0, 60, 60), "upgradetower", "Upgrade the tower?", Keys.D9, 15);

            Gui.SetScreenSize(width, height);
            topbar            = new Gui(new Rectangle(0, 0, width, 24));
            actionbar         = new Gui(new Rectangle(0, (height - 70), width, 70));
            Button.GameHeight = height;
            Button.GameWidth  = width;

            // Menu objects
            menuButtons = new List <Button>();
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X, 400, 70), "13", "Start a new game.", Keys.D1, 7));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + 75, 400, 70), "14", "Multiplayer.", Keys.D2, 8));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + (75 * 2), 400, 70), "15", "Check the game controls.", Keys.D3, 9));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + (75 * 3), 400, 70), "17", "Save the game.", Keys.D4, 13));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + (75 * 4), 400, 70), "16", "Exit the game.", Keys.D5, 10));

            // Multiplayer buttons
            multiplayerButtons = new List <Button>();
            multiplayerButtons.Add(new Button(new Rectangle(300, 200, 20, 20), "createlobby;", "Create lobby.", Keys.D1, 14));

            // join lobby buttons
            joinLobbyButtons = new List <Button>();

            // Map object
            map        = new Map();
            pathfinder = new Pathfinder(map);
            pathview   = new PathView();

            // Enemy objects
            Unit.SetPathfinder(pathfinder, map);
            Unit.LoadPath();
            waveHandler   = new WaveHandler(enemies);
            pathview.Path = Unit.Path;

            ContentHolder.Initialize();

            // Player object
            player      = new Player(5, 1000, ref map, ref toast, ref waveHandler);
            player.Wave = waveHandler.WaveNumber;

            storageHandler = new StorageHandler();

            base.Initialize();
        }
예제 #4
0
파일: Game1.cs 프로젝트: ProfChaos/Immunity
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            gameState = GameState.Menu;
            gameStateNumber = true;

            input = new Input();
            toast = new MessageHandler(width, height);
            networkMessages = new MessageHandler(width, height);
            userName = new TextInput(new Rectangle((width / 2) - 100, (height / 2) - 10, 200, 20));
            lobbyName = new TextInput(new Rectangle(100, 200, 200, 20));
            chatBox = new TextInput(new Rectangle(100, height - 40, 600, 20));
            network = new Network();
            chatlog = new List<string>();
            lobbyList = new List<Gui>();

            // Action bar objects
            actionButtons = new List<Button>();
            actionButtons.Add(new Button(new Rectangle(5, height - ACTIONBUTTONOFFSET_X, 60, 60), "10", "Basic ranged tower, medium damage, medium firing speed, medium ammunition speed, single target. 100 gold - 50% return", Keys.D1, 1));
            actionButtons.Add(new Button(new Rectangle(5 + ACTIONBUTTONOFFSET_X, height - ACTIONBUTTONOFFSET_X, 60, 60), "20", "Fast ranged tower, low damage, high firing speed, fast ammunition speed, single target. 200 gold - 50% return", Keys.D2, 3));
            actionButtons.Add(new Button(new Rectangle(width - (ACTIONBUTTONOFFSET_X * 2), height - ACTIONBUTTONOFFSET_X, 60, 60), "3", "Deletes a tower, 50% gold return for normal towers, 100% for walls.", Keys.D, 5));
            actionButtons.Add(new Button(new Rectangle(width - ACTIONBUTTONOFFSET_X, height - ACTIONBUTTONOFFSET_X, 60, 60), "0", "Starts a new wave.", Keys.N, 6));
            actionButtons.Add(new Button(new Rectangle(width - (ACTIONBUTTONOFFSET_X * 3), height - ACTIONBUTTONOFFSET_X, 60, 60), "1", "Place a blocking tower. 5 gold - 100% return.", Keys.D3, 15));

            // Upgrade tower button
            upgradeTowerButton = new Button(new Rectangle(0, 0, 60, 60), "upgradetower", "Upgrade the tower?", Keys.D9, 15);

            Gui.SetScreenSize(width, height);
            topbar = new Gui(new Rectangle(0, 0, width, 24));
            actionbar = new Gui(new Rectangle(0, (height - 70), width, 70));
            Button.GameHeight = height;
            Button.GameWidth = width;

            // Menu objects
            menuButtons = new List<Button>();
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X, 400, 70), "13", "Start a new game.", Keys.D1, 7));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + 75, 400, 70), "14", "Multiplayer.", Keys.D2, 8));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + (75 * 2), 400, 70), "15", "Check the game controls.", Keys.D3, 9));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + (75 * 3), 400, 70), "17", "Save the game.", Keys.D4, 13));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + (75 * 4), 400, 70), "16", "Exit the game.", Keys.D5, 10));

            // Multiplayer buttons
            multiplayerButtons = new List<Button>();
            multiplayerButtons.Add(new Button(new Rectangle(300, 200, 20, 20), "createlobby;", "Create lobby.", Keys.D1, 14));

            // join lobby buttons
            joinLobbyButtons = new List<Button>();

            // Map object
            map = new Map();
            pathfinder = new Pathfinder(map);
            pathview = new PathView();

            // Enemy objects
            Unit.SetPathfinder(pathfinder, map);
            Unit.LoadPath();
            waveHandler = new WaveHandler(enemies);
            pathview.Path = Unit.Path;

            ContentHolder.Initialize();

            // Player object
            player = new Player(5, 1000, ref map, ref toast, ref waveHandler);
            player.Wave = waveHandler.WaveNumber;

            storageHandler = new StorageHandler();

            base.Initialize();
        }