Beispiel #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="player">The player - allows us to give player the array of tiles</param>
        /// <param name="terrainSheet">The spriteSheet that tiles will load their texture from</param>
        /// <param name="_armies">An array of armies participating in the battle</param>
        public Battle(Game1 g, Scenario loadedScenario)
        {
            endTurn = false;
            turn = 0;
            players = new Player[loadedScenario.ArmyAmount];
            pauseMenu = new PauseMenu(3, Game1.GameHeight / 2 - 25, 192);

            terrainSheet = Game1.GameContent.Load<Texture2D>("Spritesheet");
            playerSheet = Game1.GameContent.Load<Texture2D>("selector");
            unitSheet = Game1.GameContent.Load<Texture2D>("ArmySpriteSheet");

            testArmy = loadedScenario.Armies[0];
            g.InfoBar.YMod = 110;
            g.InfoBar.Visible = false;

            players[0] = new Human(g.InfoBar,Game1.UpdateBox, playerSheet, loadedScenario.Armies[0]);
            players[0].RectPos = new Rectangle(64, 64, GV.TileSize, GV.TileSize);
            players[0].ActualPosition = new Rectangle(64, 64, GV.TileSize, GV.TileSize);
            for (int i = 1; i < players.Length; i++)
            {
                List<Army> allies = new List<Army>();
                List<Army> enemies = new List<Army>();
                for (int j = 0; j < loadedScenario.ArmyAmount; j++)
                {
                    if (j != i)
                    {
                        if (loadedScenario.Armies[j].Team == loadedScenario.Armies[i].Team)
                        {
                            allies.Add(loadedScenario.Armies[j]);
                        }
                        else
                        {
                            enemies.Add(loadedScenario.Armies[j]);
                        }
                    }
                }
                players[i] = new AI(allies, enemies, loadedScenario.Armies[i]);
            }
            g.Camera.Focus = players[0];

            DirectoryInfo d = new DirectoryInfo(Environment.CurrentDirectory);
            while (d.ToString() != "dynasty")
                d = d.Parent;
            string path = d.FullName + @"\GameData\Maps\";

            XmlReader mapReader = XmlReader.Create(path + loadedScenario.MapFile);
            int currentRow = 0;
            int currentCol = 0;

            mapReader.ReadToFollowing("map"); //read to the first map element available

            players[0].Position2 = new Point(160, 160); //place the player at a default point for now

            mapSize = Convert.ToInt32(mapReader.GetAttribute("size")); //get the size of the map (both the length and width of the map are the same, so we use "size")
            tiles = new Tile[mapSize, mapSize]; //Create a 2D array that holds the required amount of tiles
            int lastPlaced = 0;
            currentRow = 0;
            currentCol = 0;
            mapReader.ReadToFollowing("tile"); //Read to the first tile elements of the map so we can begin creating tiles
            do
            {
                int length = Convert.ToInt32(mapReader.GetAttribute("length")); //Get the rectangle size of the tile
                //string[] bound = bounds.Split(','); //Split the values provided into an array
                //int startX = int.Parse(bound[0]); //our starting x location for creating tiles
                //int startY = int.Parse(bound[1]);  //our starting y location for creating tiles
                //int endX = int.Parse(bound[2]);  //our ending x location for creating tiles
                //int endY = int.Parse(bound[3]); //our ending y location for creating tiles
                for (int i = 0; i < length; i++)
                {
                    tiles[currentRow, currentCol] = new Tile(mapReader.GetAttribute("terrain"), terrainSheet, currentRow, currentCol);
                    currentRow++;
                    if (currentRow >= mapSize)
                    {
                        currentRow = 0;
                        currentCol++;
                    }
                    if ((currentCol == mapSize) && (currentRow == mapSize))
                        break;
                }
            } while (mapReader.ReadToNextSibling("tile"));

            mapReader.ReadToNextSibling("spawns");
            //spawns = new List<Tile>();
            mapReader.ReadToFollowing("tile");
            do
            {
                string bounds = mapReader.GetAttribute("location");
                string[] bound = bounds.Split(',');
                int startX = int.Parse(bound[0]);
                int startY = int.Parse(bound[1]);
                int endX = int.Parse(bound[2]);
                int endY = int.Parse(bound[3]);

                for (int i = startX; i < endX; i++)
                {
                    for (int j = startY; j < endY; j++)
                    {
                        //_tiles[i, j].Spawn = true;
                        //spawns.Add(_tiles[i, j]);
                    }
                }
            } while (mapReader.ReadToNextSibling("tile")); //head to the next tile element if one exists, otherwise we exit this loop

            mapReader.Close();

            foreach (Player p in players)
            {
                p.SetTiles(tiles);
                foreach (Unit u in p.OwnArmy.Units)
                {
                        tiles[u.UnitBox.X / GV.TileSize, u.UnitBox.Y / GV.TileSize].Unit = u;
                        u.UnitSprite = unitSheet;
                        u.UnitPic = unitSheet;
                }
            }
        }
Beispiel #2
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)
        {
            // VOLUME CONTROL (with plus and minus keys next to backspace)
            if (InputManager.KeyReady(Keys.OemPlus) && creditsSongInstance.Volume < 1)
            {
                if (creditsSongInstance.Volume + .1f < 1)
                    creditsSongInstance.Volume += .1f;
                else creditsSongInstance.Volume = 1f;
                if (battleSongInstance.Volume + .1f < 1)
                    battleSongInstance.Volume += .1f;
                else battleSongInstance.Volume = 1f;
            }
            if (InputManager.KeyReady(Keys.OemMinus) && creditsSongInstance.Volume > 0)
            {
                if (creditsSongInstance.Volume - .1f > 0)
                    creditsSongInstance.Volume -= .1f;
                else creditsSongInstance.Volume = 0f;
                if (battleSongInstance.Volume - .1f > 0)
                    battleSongInstance.Volume -= .1f;
                else battleSongInstance.Volume = 0f;
            }

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            if (menus.Count > 0) // if there's a menu
            {
                currMenu = menus.Peek();
                if (currMenu is ScenarioMenu)
                {
                    selectedScenario = (currMenu as ScenarioMenu).Update(this);
                    if (selectedScenario != null)
                    {
                        battle = new Battle(this, selectedScenario);
                        if (!Components.Contains(camera))
                            Components.Add(camera); // Add camera to the components to be updated when base.update is called
                        camera.ResetPosition();
                    }
                }
                else
                {
                    currMenu.Update();
                }

                if (battleSongInstance.State == SoundState.Playing)
                    battleSongInstance.Stop();
            }
            else
            {
                ///  Toggle battle music on/off with the "M" key!!!!
                if (battleSongInstance.State == SoundState.Playing)
                {
                    if (InputManager.KeyReady(Keys.M))
                    {
                        battleSongInstance.Pause();
                    }
                }
                else if (battleSongInstance.State == SoundState.Paused)
                {
                    if (InputManager.KeyReady(Keys.M))
                    {
                        battleSongInstance.Resume();
                    }
                }
                else if (battleSongInstance.State == SoundState.Stopped)
                {
                    if (InputManager.KeyReady(Keys.M))
                    {
                        battleSongInstance.Play();
                    }
                }

                battle.Update(this);
                //if (Components.Contains(camera)) Components.Remove(camera);
                infoBar.Update();
                updateBox.Update(gameTime, ref battle);
            }
            InputManager.Update(gameTime);

            if (exiting == true)
            {
                Exit();
            }

            base.Update(gameTime);
        }