コード例 #1
0
ファイル: Vessel.cs プロジェクト: thestonefox/Project-Xna
        protected int MoveObjects(Map map, Player[] players, List<Enemy> enemies)
        {
            int score = 0;
            foreach (Weapon weapon in weapons)
            {
                weapon.Update();
            }
            Vector2 collisionCheck = new Vector2(-1, -1);

            //check if vessel has hit any bounding tiles
            Tile[,] tileSet = map.GetSurroundingTiles(map.SpriteOverTile(this), GetBoundaryCheck(map.tileSize)+1);
            for(int x=0; x<tileSet.GetLength(0); x++)
            {
                for (int y = 0; y < tileSet.GetLength(1); y++)
                {
                    if (tileSet[x, y] != null)
                    {
                        Tile tile = tileSet[x, y];
                        //had the vessel hit the collidable tile?
                        if (BoundingCollision(tile))
                        {
                                ResolveBounding(tile);
                                //bounce off tile
                                acceleration = ReflectVector((acceleration));
                                setEnergy(tile);
                                CheckEnergy(explosionCount);
                                score += tile.CheckEnergy();
                                //If you've died on a tile then stop the movement
                                if (currentEnergy == 0) acceleration = 0.0f;

                                if (this.GetType().Name.Equals("Player"))
                                    rumbleTimer = 40;
                        }
                    }
                }
            }

            //If type is player then
            //check if vessel has hit any alive enemies
            if (this.GetType().Name.Equals("Player"))
            {
                foreach (Enemy enemy in enemies)
                {
                    if (BoundingCollision(enemy))
                    {
                        if (TextureCollision(enemy))
                        {
                            rumbleTimer = 20;
                            setEnergy(enemy);
                            CheckEnergy();
                            score += enemy.CheckEnergy();
                            //check to see if the collision has any effects on the player, like powerup
                            enemy.CollisionEffects(this);
                        }
                    }
                }
            }
            UpdatePosition();
            return score;
        }
コード例 #2
0
ファイル: PlayerHud.cs プロジェクト: thestonefox/Project-Xna
        public PlayerHud(Texture2D _texture, SpriteFont _font, Player _player, Color _color, Vector2 _position, float _transparency)
        {
            player = _player;
            color = new Color(_color, _transparency);
            position = _position;
            font = _font;
            bar = new Sprite(10, _texture);
            bar.Prepare(Vector2.Zero);
            bar.alpha = _transparency;

            tw = new TextWriter(font);
        }
コード例 #3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public GameOverScreen(Player[] _players)
 {
     players = _players;
     TransitionOnTime = TimeSpan.FromSeconds(1.5);
     TransitionOffTime = TimeSpan.FromSeconds(0.5);
 }
コード例 #4
0
ファイル: Player.cs プロジェクト: thestonefox/Project-Xna
        public void Update(Map map, Player[] players, List<Enemy> enemies, ProjectileManager pm)
        {
            if (currentEnergy > 0)
                CaptureMovement(pm);

            bool newLife = true;
            //if energy goes too high then give some more life
            if (energySaver > initialEnergySaver)
            {
                energySaver = initialEnergySaver;
                currentEnergy += 50;
                newLife = false;
            }
            //if health goes too high then get new life
            if (currentEnergy > initialEnergy)
            {
                bool iWantToGiveNewLife = false;
                if (newLife && iWantToGiveNewLife)
                    lives += 1;
                currentEnergy = initialEnergy;
            }

            if (dieTimerCurrent==2)
            {
                //decrease lives and reset energy
                lives -= 1;
                dieTimerCurrent = 0;
                //if there are still more lives then reset player position
                if (lives > 0)
                {
                    currentEnergy = initialEnergy;
                    energySaver = initialEnergySaver;
                    safetyTimer = 100;
                    //reset all weapon bays
                    ChangeWeapon(0, 4, 15, 1);
                    for (int w = 1; w < weapons.Length; w++)
                    {
                        ChangeWeapon(w, 0, 10, 1);
                    }
                    Prepare(startPosition);
                }
                else
                {
                    alive = false;
                }
            }

            if (safetyTimer > 0)
            {
                alpha = 0.6f;
                collidable = false;
            }
            else
            {
                alpha = 1.0f;
                collidable = true;
            }
            score += MoveObjects(map, players, enemies);

            if (rumbleTimer > 0)
            {
                rumbleTimer -= 1;
                if(energySaverOn)
                    input.DoRumble(playerIndex, out actualPlayerIndex, 0.15f, 0.15f);
                else
                    input.DoRumble(playerIndex, out actualPlayerIndex, 0.3f, 0.5f);
            }
            else
            {
                rumbleTimer = 0;
                input.DoRumble(playerIndex, out actualPlayerIndex, 0.0f, 0.0f);
            }

            if (position.X < map.drawArea.Left + (GetBounds().Width/2)) position.X = map.drawArea.Left + (GetBounds().Width/2);
            if (position.X > map.drawArea.Right - (GetBounds().Width/2)) position.X = map.drawArea.Right - (GetBounds().Width/2);
            if (position.Y < map.drawArea.Top + (GetBounds().Height )) position.Y = map.drawArea.Top + (GetBounds().Height );
            if (position.Y > map.drawArea.Bottom - (GetBounds().Height )) position.Y = map.drawArea.Bottom - (GetBounds().Height );
            Decelerate();
        }
コード例 #5
0
ファイル: Level.cs プロジェクト: thestonefox/Project-Xna
        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);
                    }
                }
            }
        }
コード例 #6
0
        public int UpdateEnemies(Map map, Player[] players, List<Enemy> enemies, ProjectileManager pm)
        {
            int returnVal=0;
            List<Enemy> deletedIndex = new List<Enemy>();
            List<Enemy> addIndex = new List<Enemy>();
            foreach (Enemy enemy in liveEnemies)
            {
                //expand draw area to check to see if enemy has left area
                map.drawArea.Inflate(map.tileSize.X+(int)enemy.width, map.tileSize.Y+(int)enemy.height);
                if (!map.drawArea.Contains(enemy.GetBounds()))
                    enemy.alive = false;
                //return map to original size
                map.drawArea.Inflate(-(map.tileSize.X + (int)enemy.width), -(map.tileSize.Y + (int)enemy.height));

                enemy.Update(map, players, enemies, pm);

                if (enemy.currentEnergy == 0 && !enemy.spawned)
                {
                    enemy.spawned = true;
                    addIndex.Add(enemy);
                }

                //if the enemy is not alive then remove it from the list
                if (!enemy.alive)
                    deletedIndex.Add(enemy);
            }

            foreach (Enemy addEnemy in addIndex)
            {
                //respawn another enemy
                foreach (Point respawns in addEnemy.respawn)
                {
                    for (int i = 0; i < respawns.Y; i++)
                        SpawnEnemy(respawns.X, addEnemy.position);
                }
            }

            //Remove enemies tagged for deletion
            foreach (Enemy deleteEnemy in deletedIndex)
            {
                if (deleteEnemy.levelEnder)
                    returnVal += 1;
                liveEnemies.Remove(deleteEnemy);
            }
            return returnVal;
        }
コード例 #7
0
ファイル: Enemy.cs プロジェクト: thestonefox/Project-Xna
 public void Update(Map map, Player[] players, List<Enemy> enemies, ProjectileManager pm)
 {
     CalculateNextVector();
     MoveObjects(map, players, enemies);
     FireWeapon(pm);
 }
コード例 #8
0
        public int Update(Map map, Player[] players, List<Enemy> enemies)
        {
            List<Projectile> deleted = new List<Projectile>();
            int score = 0;
            //loop through projectiles but then i need to access the checkcollision routine, how?!
            //calculate the current vector of the projectile
            foreach (Projectile projectile in liveProjectiles)
            {
                if (projectile.alive)
                {
                    Vessel orignalFirer = (Vessel)projectile.originiator;
                    //Check to see if the projectile has hit any bounding tiles
                    Tile[,] tileSet = map.GetSurroundingTiles(map.SpriteOverTile(projectile), 2);

                    //check each tile in set to see if it has collided
                    Vector2 resetPoint = new Vector2(-1,-1);
                    for (int x = 0; x < tileSet.GetLength(0); x++)
                    {
                        for (int y = 0; y < tileSet.GetLength(1); y++)
                        {
                            if (tileSet[x, y] != null)
                            {
                                Tile tile = tileSet[x, y];
                                if (tile.collidable && projectile.BoundingCollision(tile))
                                {
                                    projectile.lastSideCollided = FindLastSideTouched(map, projectile, tile.coordinates, -1, ref resetPoint);
                                    if (projectile.lastSideCollided > -1)
                                    {
                                        orignalFirer.score += CheckProjectileCollisions(tile, projectile);
                                        if (projectile.collided)
                                        {
                                            projectile.collided = false;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if(resetPoint.X>-1)
                    {
                        projectile.position = resetPoint - projectile.velocity;
                        projectile.safePosition = resetPoint - projectile.velocity;
                    }

                    //Check to see if the projectile has hit any enemies
                    //Only check enemy hit if the projectile has come from a player
                    if (projectile.originiator.GetType().Name.Equals("Player"))
                    {
                        //check projectiles for hitting enemies
                        foreach (Enemy enemy in enemies)
                        {
                            orignalFirer.score += CheckProjectileCollisions(enemy, projectile);
                        }
                    }

                    //Check to see if the projectile has hit any players
                    foreach (Player player in players)
                    {
                        //can players shoot each other?
                        // if no then use  ! projectile.originiator.GetType().Name.Equals("Player")
                        // if yes then use  player != orignalFirer
                        if (! projectile.originiator.GetType().Name.Equals("Player"))
                        {
                            int checkScore = CheckProjectileCollisions(player, projectile);
                            orignalFirer.score += checkScore;
                        }
                    }

                    //expand draw area to check to see if enemy has left area
                    map.drawArea.Inflate(map.tileSize.X, map.tileSize.Y);
                    if (!map.drawArea.Contains(projectile.GetBounds()))
                        projectile.alive = false;
                    //return map to original size
                    map.drawArea.Inflate(-map.tileSize.X, -map.tileSize.Y);

                    projectile.CalculateNextVector();
                    projectile.UpdatePosition();
                }

                if (!projectile.alive)
                    deleted.Add(projectile);
            }

            //remove dead projectiles
            foreach (Projectile projectile in deleted)
                liveProjectiles.Remove(projectile);

            return score;
        }