Ejemplo n.º 1
0
 public void LoadContent(ContentManager content)
 {
     myShip = xmlEngine.PlayerShips[0].ShallowCopy();
     texture = myShip.ShipTexture;
     myShip.Position = new Vector2(Game1.ViewPortWidth / 2 - texture.Width / 2, Game1.ViewPortHeight / 2 - texture.Height / 2);
     screenSize = new Vector2(Game1.ViewPortWidth, Game1.ViewPortHeight);
 }
Ejemplo n.º 2
0
 public void AddEnemy(Random random, Ship ship)
 {
     Enemy enemy = new Enemy(ship);
     Vector2 position = new Vector2(Game1.ViewPortWidth + enemy.myShip.ShipTexture.Width / 2, random.Next(100, (int)Game1.ViewPortHeight - 100));
     enemy.LoadContent(position);
     Enemies.Add(enemy);
 }
Ejemplo n.º 3
0
 private void DamageShip(int damageDealt, Ship ship)
 {
     float damage = damageDealt - ship.Shield;
     ship.Shield -= damageDealt;
     if (damage > 0)
     {
         ship.Health -= (int)damage;
     }
 }
Ejemplo n.º 4
0
 public Projectile(Texture2D projectileTexture, string projectileType, float projectileSpeed, int projectileDamage, Vector2 projectilePostition, Ship ship, bool enemyProjectile = false)
 {
     ProjectileTexture = projectileTexture;
     ProjectileType = projectileType;
     ProjectileSpeed = projectileSpeed;
     ProjectileDamage = projectileDamage;
     Position = projectilePostition;
     ShooterShip = ship;
     EnemyProjectile = enemyProjectile;
     TextureData = new Color[ProjectileTexture.Width * ProjectileTexture.Height];
     ProjectileTexture.GetData(TextureData);
 }
Ejemplo n.º 5
0
 public void fire(GameTime gameTime, ProjectileManager projectileManager, Vector2 postition, bool isplayer, Ship ship)
 {
     if (gameTime.TotalGameTime - this.PreviousFireTime > FireTime)
     {
         float projectileSpeed;
         if (isplayer)
             projectileSpeed = ProjectileSpeed;
         else
             projectileSpeed = -ProjectileSpeed;
         Projectile myProjectile = new Projectile(ProjectileTexture, ProjectileType, projectileSpeed, ProjectileDamage, postition, ship, !isplayer);
         myProjectile.Position.X += OffsetX;
         myProjectile.Position.Y += OffsetY;
         this.PreviousFireTime = gameTime.TotalGameTime;
         projectileManager.AddProjectile(myProjectile);
         fired++;
     }
 }
Ejemplo n.º 6
0
 public Enemy(Ship ship)
 {
     myShip = ship.ShallowCopy();
 }
Ejemplo n.º 7
0
        private void LoadShips(string fileName)
        {
            // Load the XML Document
            XmlReader reader = XmlReader.Create(fileName);

            string Name = null, Texture = null, ShipType = null, AI = null;
            int Health = 0, Hardpoints = 0, WeaponClass = 0, Armour = 0, Cost = 0, Level = 0, Points = 0;
            float Shield = 0f, Speed = 0f;
            List<Weapon>ShipWeapons = new List<Weapon>();
            bool Correct_File = false, isPlayer = false;

            while (reader.Read())
            {
                if ((reader.NodeType == XmlNodeType.Element) && reader.Name == "Ship")
                {
                    if (reader.GetAttribute(0) == "true")
                        isPlayer = true;
                    Correct_File = true;
                }

                if (Correct_File)
                {
                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        reader.Read();
                        while (reader.NodeType != XmlNodeType.EndElement)
                        {
                            // General Stuff
                            Name = ReadElement(reader, "Name");

                            Health = Convert.ToInt32(ReadElement(reader, "Health"));

                            Shield = (float)Convert.ToDouble(ReadElement(reader, "Shield"));

                            Speed = (float)Convert.ToDouble(ReadElement(reader, "Speed"));

                            Hardpoints = Convert.ToInt32(ReadElement(reader, "Hardpoints"));

                            // Weapon loading
                            WeaponClass = Convert.ToInt32(ReadElement(reader, "WeaponClass"));

                            string weaponName = ReadElement(reader, "Weapon1");
                                if (Hardpoints > 0)
                                {
                                foreach (Weapon weapon in Weapons)
                                {
                                    if (weapon.WeaponName == weaponName)
                                        ShipWeapons.Add(weapon);
                                }

                                if (Hardpoints > 1)
                                {
                                    weaponName = ReadElement(reader, "Weapon2");
                                    foreach (Weapon weapon in Weapons)
                                    {
                                        if (weapon.WeaponName == weaponName)
                                            ShipWeapons.Add(weapon);
                                    }
                                    if (Hardpoints > 2)
                                    {
                                        weaponName = ReadElement(reader, "Weapon3");
                                        foreach (Weapon weapon in Weapons)
                                        {
                                            if (weapon.WeaponName == weaponName)
                                                ShipWeapons.Add(weapon);
                                        }
                                    }
                                }
                            }

                            Armour = Convert.ToInt32(ReadElement(reader, "Armour"));

                            Texture = ReadElement(reader, "Texture");

                            // Player Stuff
                            if (isPlayer)
                            {
                                Cost = Convert.ToInt32(ReadElement(reader, "Cost"));

                                ShipType = ReadElement(reader, "Type");
                            }

                            // Enemy Stuff
                            else
                            {
                                Level = Convert.ToInt32(ReadElement(reader, "Level"));

                                Points = Convert.ToInt32(ReadElement(reader, "Points"));

                                AI = ReadElement(reader, "AI");
                            }
                            reader.Read();
                        }
                    }
                    if (isPlayer)
                    {
                        Ship playerShip = new Ship(Name, Health, Shield, Speed, WeaponClass, Armour, @"Sprites\Ships\" + Texture, Cost, ShipType, Hardpoints);
                        int weaponPoint = 0;
                        foreach (Weapon weapon in ShipWeapons)
                        {
                            playerShip.MountWeapon(weaponPoint, weapon);
                            weaponPoint++;
                        }
                        PlayerShips.Add(playerShip);
                    }
                    else
                    {
                        Ship enemyShip = new Ship(Name, Health, Shield, Speed, WeaponClass, Armour, @"Sprites\Ships\" + Texture, Level, Points, AI, Hardpoints);
                        int weaponPoint = 0;
                        foreach (Weapon weapon in ShipWeapons)
                        {
                            enemyShip.MountWeapon(weaponPoint, weapon);
                            weaponPoint++;
                        }
                        EnemyShips.Add(enemyShip);
                    }
                }
            }
            reader.Close();

            if (Correct_File == false)
            {
                // Error code here
            }
        }