コード例 #1
0
ファイル: Map.cs プロジェクト: NelsonSalvador/Projeto-3-LP1
        /// <summary>
        /// Generates new map and instanciates objects
        /// </summary>
        /// <param name="rows"></param>
        /// <param name="columns"></param>
        /// <param name="player"></param>
        /// <param name="level"></param>
        public void Generate(int rows, int columns, Player player, int level)
        {
            //Fill the map with available tiles
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    layout.Add(new Coords(i, j), Objects.None);
                }
            }

            //Define Random spawn of the player
            Coords spawn = new Coords(Random.Next(rows), 0);

            layout[spawn] = Objects.Player;
            player.Coords = spawn;

            //Define Random spawn of the exit
            Coords Victory = new Coords(Random.Next(rows), columns - 1);

            layout[Victory] = Objects.Victory;

            //Calculates de number os walls
            int numberofwalls = (Math.Min(rows, columns)) - 1;

            //Defines the placement of walls
            while (numberofwalls != 0)
            {
                Coords wall = new Coords(Random.Next(rows),
                                         Random.Next(columns));

                if (layout[wall] == Objects.None)
                {
                    layout[wall] = Objects.Wall;
                    numberofwalls--;
                }
            }

            // Defines number os max enemies
            int maxNumberOfEnemies = 2 * level + 1;

            if (maxNumberOfEnemies > (rows * columns) / 2)
            {
                maxNumberOfEnemies = (rows * columns) / 2;
            }
            int numberOfEnemies = Random.Next(1, maxNumberOfEnemies);

            //Spawn enemies while the number of enemys to spawn
            // is not equal to 0
            while (numberOfEnemies != 0)
            {
                // chance of spawning a boss
                int percentage = Random.Next(101);

                // Random coords for the enemy
                Coords enemies = new Coords(Random.Next(rows),
                                            Random.Next(columns));

                //Instantiate a enemy
                Enemy enemy;

                //Checks if enemy can spawn in that position
                if (layout[enemies] == Objects.None)
                {
                    //Checks if the enemy to spawn is a boss
                    if (percentage >= 100 - (5 * level))
                    {
                        //spawns a boss
                        enemy           = new Enemy(enemies, Objects.Boss);
                        layout[enemies] = Objects.Boss;
                    }
                    else
                    {
                        //spawns a minion
                        enemy           = new Enemy(enemies, Objects.Minion);
                        layout[enemies] = Objects.Minion;
                    }
                    //Number of enemies to spawn decreases
                    numberOfEnemies--;

                    //Add enemy to the list
                    EnemyList.Add(enemy);
                }
            }

            //Defines the max number of PowerUps
            int NumberOfPowerUps = -level + 11;

            //If NumberOfPowerUps is less or equal to 0~
            //force to spawn 1 power up
            if (NumberOfPowerUps <= 0)
            {
                NumberOfPowerUps = 1;
            }

            //Spawn power ups while the number of power ups
            // is not equal to 0
            while (NumberOfPowerUps != 0)
            {
                //Change for the powerups
                int percentage = Random.Next(101);

                //Random coords for the powerups
                Coords Powerups = new Coords(Random.Next(rows),
                                             Random.Next(columns));

                //Instantiate a power up
                PowerUp powerUp;

                //Check if can spawn in that position
                if (layout[Powerups] == Objects.None)
                {
                    //if percentage is less than 50 spawn
                    // a small power up
                    if (percentage <= 50)
                    {
                        powerUp          = new PowerUp(Powerups);
                        layout[Powerups] = Objects.SmallPowerups;
                    }
                    //if percentage is in between 50 and 85 spawn
                    // a medium power up
                    else if (percentage > 50 && percentage <= 85)
                    {
                        powerUp          = new PowerUp(Powerups);
                        layout[Powerups] = Objects.MediumPowerups;
                    }
                    //if percentage is above 85 spawn
                    // a medium power up
                    else
                    {
                        powerUp          = new PowerUp(Powerups);
                        layout[Powerups] = Objects.LargePowerups;
                    }
                    //decrease the number of power ups to spawn
                    NumberOfPowerUps--;
                }
            }
        }
コード例 #2
0
ファイル: PowerUpManager.cs プロジェクト: Stran6/TankGame
 public void InitializePowerUps(Vector2 location)
 {
     Health = new PowerUp(game, location, "Images/HealthPackTexture");
     HeavyShot = new PowerUp(game, location, "Images/AmmoPackTexture");
     ScatterShot = new PowerUp(game, location, "Images/ScatterShotAmmo");
     ExtraMovement = new PowerUp(game, location, "Images/MovementPowerUp");
     ShieldPower = new PowerUp(game, location, "Images/ShieldPowerUp");
     shieldHealthTexture = Game.Content.Load<Texture2D>(@"Images/ShieldBar");
 }
コード例 #3
0
ファイル: PowerUpManager.cs プロジェクト: Stran6/TankGame
 public void updateShield(Vector2 tankLocation)
 {
     //Add Shield
     shieldHealthRect = new Rectangle((int)tankLocation.X, (int)tankLocation.Y, 200, 20);
     ShieldLayer = new PowerUp(game, tankLocation, "Images/Shield");
     powerList.Add(ShieldLayer);
     shieldActive = true;
 }
コード例 #4
0
ファイル: PowerUpManager.cs プロジェクト: Stran6/TankGame
        private void shieldLogic(Tank tank, Tank otherTank, PowerUp powerUp)
        {
            shieldHealthRect.X = (int)tank.getTankPos().X - 20;
            shieldHealthRect.Y = (int)tank.getTankPos().Y - 40;
            ShieldLayer.powerUpPosition = tank.getTankPos() - new Vector2(8, 20);
            if (powerUp.collisionRect.Intersects(otherTank.bullet.collisionRect))
            {
                otherTank.bullet.outOfBounds = true;
                if (otherTank.bullet.type == BulletType.TeleportShot)
                    otherTank.bullet.speed.X = -(otherTank.bullet.speed.X);

                shieldHealth -= otherTank.bullet.damage / 10;
                shieldHealthRect.Width = shieldHealth;
                game.soundManager.shieldHit.Play();

                if (shieldHealth <= 100)
                    ShieldLayer.powerUpPic = Game.Content.Load<Texture2D>(@"Images/BrokenShield");

                if (shieldHealth <= 0)
                {
                    game.soundManager.shieldBreaking.Play();
                    powerList.Remove(powerUp);
                    shieldActive = false;
                    play1HasShield = false;
                    play2HasShield = false;
                }
            }
        }
コード例 #5
0
ファイル: PowerUpManager.cs プロジェクト: Stran6/TankGame
 public void PowerUpEffect(PowerUp powerUp, Tank tank)
 {
     if (powerUp == Health)
     {
         game.uiManager.floatingPowerUpText("+100 Health", tank.getTankPos());
         tank.healTank(100);
     }
     if (powerUp == HeavyShot)
     {
         game.uiManager.floatingPowerUpText("Heavy Shot +1", tank.getTankPos());
         tank.inventory.incrementShot(BulletType.HeavyShot);
     }
     if (powerUp == ScatterShot)
     {
         game.uiManager.floatingPowerUpText("ScatterShot +1", tank.getTankPos());
         tank.inventory.incrementShot(BulletType.ScatterShot);
     }
     if (powerUp == ExtraMovement)
     {
         game.uiManager.floatingPowerUpText("Move Limit +3", tank.getTankPos());
         tank.moveLimit += 3;
     }
     if (powerUp == ShieldPower)
     {
         game.uiManager.floatingPowerUpText("Shield", tank.getTankPos());
         updateShield(tank.getTankPos());
     }
 }