Пример #1
0
 protected void GenerateWeapons()
 {
     for (int i = 0; i < weapons.Length; i++)
     {
         weapons[i] = new Weapon(projectileTexture, 5, 20, 0, this);
     }
 }
Пример #2
0
 public void Prepare(int _totalPlayers, int[] _playerLives, int[] _playerScores, Weapon[][] _playerWeapons)
 {
     totalPlayers = _totalPlayers;
     playerLives = _playerLives;
     playerScores = _playerScores;
     playerWeapons = _playerWeapons;
     NextLevel();
 }
Пример #3
0
 public Missile(int projectileNumber, Weapon firingWeapon, Vessel origin, float gravity, float _deceleration, Vector2 _accelerationLimits, bool _destroyable, bool _collidable, int _power, int energy, int timer, int points, Texture2D textureSheet, float width, float height, int spriteLine, float frameRate, int _frameCount, bool isLooping)
     : base(firingWeapon, origin, gravity, _deceleration, _accelerationLimits, _destroyable, _collidable, _power, energy, timer, points, textureSheet, width, height, spriteLine, frameRate, _frameCount, isLooping)
 {
     rotateway = -90.0f;
     if (Helper.OddEvenChoice(projectileNumber) == 1 && projectileNumber>0)
         rotateway = 90.0f;
     rotation = origin.rotation;
     SetTrajectory(rotation);
 }
Пример #4
0
 public Projectile(Weapon _firingWeapon, Vessel origin, float weight, float _deceleration, Vector2 _accelerationLimits, bool _destroyable, bool _collidable, int _power, int energy, int timer, int points, Texture2D textureSheet, float width, float height, int spriteLine, float frameRate, int _frameCount, bool isLooping)
     : base(weight, _deceleration, _accelerationLimits, _destroyable, _collidable, _power, energy, timer, points, textureSheet, width, height, spriteLine, frameRate, _frameCount, isLooping)
 {
     firingWeapon = _firingWeapon;
     originiator = origin;
     position = origin.position;
     safePosition = position;
     collided = false;
     lastSideCollided = -1;
     totalLife = 0;
 }
Пример #5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public GameplayScreen(int _levelNumber, int _totalPlayers, int[] _playerLives, int[] _playerScores, Weapon[][] _playerWeapons)
        {
            TransitionOnTime = TimeSpan.FromSeconds(1.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.1);
            levelNumber = _levelNumber;

            totalPlayers = _totalPlayers;
            playerLives = _playerLives;
            playerScores = _playerScores;
            playerWeapons = _playerWeapons;
        }
Пример #6
0
        private void LoadLevel(int levelID, int totalPlayers)
        {
            if (!File.Exists(Path.Combine(StorageContainer.TitleLocation, "Content\\Maps\\level_" + levelID + ".xml")))
            {
                WinGame();
                return;
            }
            levelsXml.Load(Path.Combine(StorageContainer.TitleLocation, "Content\\Maps\\level_" + levelID + ".xml"));
            map = new Map(gameArea);
            XmlNode levelData = levelsXml.DocumentElement.SelectSingleNode("/levels/level[@id='" + levelID + "']");
            //If there is no level data then the game must have been completed
            if (levelData == null)
            {
                WinGame();
                return;
            }
            //Load Map Data
            XmlNode mapData = levelData.SelectSingleNode("map");
            Texture2D tileTextures = content.Load<Texture2D>(levelData.SelectSingleNode("map/@texture_path").InnerText);

            XmlNodeList enemyTexturesNodes = levelData.SelectNodes("enemyTextures/texture");
            Texture2D[] enemyTextures = new Texture2D[enemyTexturesNodes.Count];

            for (int t = 0; t < enemyTexturesNodes.Count; t++)
                enemyTextures[t] = content.Load<Texture2D>(enemyTexturesNodes[t].SelectSingleNode("@path").InnerText);

            enemies = new EnemySpawner(enemyTextures);
            projectiles = new ProjectileManager();

            Point scrollSpeed = new Point(Convert.ToInt32(levelData.SelectSingleNode("map/@scroll_x").InnerText), Convert.ToInt32(levelData.SelectSingleNode("map/@scroll_y").InnerText));
            XmlNodeList tileColumns = mapData.SelectNodes("column");

            map.tiles = new Tile[tileColumns.Count][];
            int tileWidth = 0;
            int tileHeight = 0;
            for (int x = 0; x < tileColumns.Count; x++)
            {
                XmlNodeList tileRows = tileColumns[x].SelectNodes("tile");
                map.tiles[x] = new Tile[tileRows.Count];
                for (int y = 0; y < tileRows.Count; y++)
                {
                    XmlNode tileCell = tileRows[y];
                    //get all graphic types
                    XmlNodeList graphics = tileCell.SelectNodes("graphics/graphic");
                    Vector4[] types = new Vector4[graphics.Count];
                    for (int g = 0; g < graphics.Count; g++)
                    {
                        XmlNode graphic = graphics[g];
                        types[g] = new Vector4(Convert.ToInt32(graphic.SelectSingleNode("@sprite_x").InnerText), Convert.ToInt32(graphic.SelectSingleNode("@sprite_y").InnerText), (float)Convert.ToDouble(graphic.SelectSingleNode("@rotation").InnerText), Convert.ToInt32(graphic.SelectSingleNode("@flip").InnerText));
                    }

                    int power = Convert.ToInt32(tileCell.SelectSingleNode("@power").InnerText);
                    int energy = Convert.ToInt32(tileCell.SelectSingleNode("@energy").InnerText);
                    int timer = 2;
                    int worth = Convert.ToInt32(tileCell.SelectSingleNode("@worth").InnerText);
                    bool destroyable = System.Convert.ToBoolean(tileCell.SelectSingleNode("@destroyable").InnerText);
                    bool collidable = System.Convert.ToBoolean(tileCell.SelectSingleNode("@collidable").InnerText);

                    tileWidth = Convert.ToInt32(tileCell.SelectSingleNode("dimensions/@width").InnerText);
                    tileHeight = Convert.ToInt32(tileCell.SelectSingleNode("dimensions/@height").InnerText);

                    //digest enemy spawn points
                    XmlNodeList enemiesToSpawn = tileCell.SelectNodes("enemies/enemy");
                    List<int> enemySpawns = new List<int>();
                    for (int e = 0; e < enemiesToSpawn.Count; e++)
                    {
                        XmlNode enemy = enemiesToSpawn[e];
                        int enemyToAdd=Convert.ToInt32(enemy.SelectSingleNode("@type").InnerText);
                        enemySpawns.Add(enemyToAdd);
                        endOfLevel += enemies.AddLevelEnders(enemyToAdd);
                    }

                    map.tiles[x][y] = new Tile(enemySpawns, 0.0f, new Point(x, y), types,
                                            destroyable, collidable, power, energy, timer, worth, tileTextures,
                                            tileWidth, tileHeight);
                    map.tiles[x][y].alive = true;
                }
            }
            map.scrollSpeed = scrollSpeed;
            map.tileSize = new Point(tileWidth, tileHeight);

            //Load Player Data
            XmlNodeList playerNodes = levelData.SelectNodes("players/player");

            players = new Player[totalPlayers];
            playerHuds = new PlayerHud[totalPlayers];
            SpriteFont playerhudFont = content.Load<SpriteFont>("Fonts/hudfont");
            Texture2D pixelDot = content.Load<Texture2D>("Sprites/pixel");

            PlayerIndex[] playerIndexes = new PlayerIndex[] { PlayerIndex.One, PlayerIndex.Two, PlayerIndex.Three, PlayerIndex.Four };
            Color[] playerColors = new Color[] { Color.Red, Color.Green };
            for (int p = 0; p < totalPlayers; p++)
            {
                XmlNodeList weapons = playerNodes[p].SelectNodes("weapons/weapon");
                Texture2D projectileTexture = content.Load<Texture2D>(playerNodes[p].SelectSingleNode("@projectile_path").InnerText);
                Texture2D playerTexture = content.Load<Texture2D>(playerNodes[p].SelectSingleNode("@texture_path").InnerText);
                float pWeight = (float) Convert.ToDouble(playerNodes[p].SelectSingleNode("@weight").InnerText);
                int pPower = Convert.ToInt32(playerNodes[p].SelectSingleNode("@power").InnerText);
                //energy and shield is reset to full every map load
                int pEnergy = Convert.ToInt32(playerNodes[p].SelectSingleNode("@energy").InnerText);
                int pShield = Convert.ToInt32(playerNodes[p].SelectSingleNode("@shield").InnerText);
                int pWorth = Convert.ToInt32(playerNodes[p].SelectSingleNode("@worth").InnerText);

                //lives are set to current
                int pLives = Convert.ToInt32(playerNodes[p].SelectSingleNode("@lives").InnerText);
                if (playerLives[p] > -1)
                    pLives = playerLives[p];

                int pWidth = Convert.ToInt32(playerNodes[p].SelectSingleNode("dimensions/@width").InnerText);
                int pHeight = Convert.ToInt32(playerNodes[p].SelectSingleNode("dimensions/@height").InnerText);
                int pTileX = Convert.ToInt32(playerNodes[p].SelectSingleNode("tile_start/@x").InnerText);
                int pTileY = Convert.ToInt32(playerNodes[p].SelectSingleNode("tile_start/@y").InnerText);

                float xpos = ((pTileX * tileWidth)) + gameArea.X;
                float ypos = ((pTileY * tileHeight)) + gameArea.Y;

                players[p] = new Player(new Vector2(xpos, ypos), pShield, playerIndexes[p], projectileTexture, weapons.Count, pLives, pWeight, 0.01f, new Vector2(-4.0f, 5.0f), true, true, pPower, pEnergy, 18, pWorth, playerTexture, pWidth, pHeight, 1, 0.025f, 1, false);
                //set the player score to the current level score held by the player
                players[p].score = playerScores[p];
                players[p].Prepare(players[p].startPosition);

                //set player huds
                playerHuds[p] = new PlayerHud(pixelDot, playerhudFont, players[p], playerColors[p], new Vector2(60 + (600 * p), gameArea.Top + 60), 0.4f);

                //set weapons
                //If there are no set weapons then use default weapons
                if (playerWeapons[p]==null)
                {
                    playerWeapons[p] = new Weapon[weapons.Count];
                    for (int w = 0; w < weapons.Count; w++)
                    {
                        int wProjectiles = Convert.ToInt32(weapons[w].SelectSingleNode("@max_projectiles").InnerText);
                        int wRate = Convert.ToInt32(weapons[w].SelectSingleNode("@fire_rate").InnerText);
                        int wType = Convert.ToInt32(weapons[w].SelectSingleNode("@projectile_type").InnerText);
                        players[p].ChangeWeapon(w, wProjectiles, wRate, wType);
                    }
                }
                else
                {
                    for (int w = 0; w < playerWeapons[p].Length; w++)
                    {
                        Weapon tmpWep = playerWeapons[p][w];
                        players[p].ChangeWeapon(w, tmpWep.maxProjectiles, tmpWep.fireRate, tmpWep.ammoType);
                    }
                }
            }
        }
Пример #7
0
        void RunGame(PlayerIndexEventArgs e, int totalPlayers)
        {
            int[] playerLives = new int[totalPlayers];
            for (int i = 0; i < totalPlayers; i++)
                playerLives[i] = -1;
            int[] playerScores = new int[totalPlayers];
            for (int i = 0; i < totalPlayers; i++)
                playerScores[i] = 0;
            Sprite_Elements.Weapon[][] playerWeapons = new Sprite_Elements.Weapon[totalPlayers][];

            LoadingScreen.Load(ScreenManager, true, e.PlayerIndex, new GameplayScreen(3, totalPlayers, playerLives, playerScores, playerWeapons));
        }