// Spawn the enemies private void CreateEnemies() { Sprite2D shieldSprite = ResourceCache.GetSprite2D("shield.png"); for (int i = 0; i < enemyCount; ++i) { CharacterEnemy enemy = new CharacterEnemy(enemyClasses.GetRandomElement(), 5); Vector2 spawn = enemySpawns.GetRandomElement(); enemySpawns.Remove(spawn); enemy.CreateNode(scene, enemy.PlayerSpriteAttack, shieldSprite, spawn); Characters.Add(enemy); } }
// This method loads the enemy characters // Recieves a line of serialized character data private void LoadEnemies(string line) { InvokeOnMain(() => { // Load each enemy string[] enemiesSplit = line.Split(';'); foreach (var enemy in enemiesSplit.Take(enemiesSplit.Length - 1)) { // Create variables to store character properties. // Order of serialized is: // Class,HeldWeapon,Armor,Health,MaxHealth,Score,X,Y,Z string[] props = enemy.Split(','); var enemyClass = props[0]; var enemyWeapon = props[1]; var enemyArmor = props[2]; var enemyHealth = props[3]; var enemyMaxHealth = props[4]; var enemyScore = props[5]; string[] position = props.Skip(6).Take(3).ToArray(); float x = float.Parse(position[0], CultureInfo.InvariantCulture.NumberFormat); float y = float.Parse(position[1], CultureInfo.InvariantCulture.NumberFormat); float z = float.Parse(position[2], CultureInfo.InvariantCulture.NumberFormat); // Determine CharacterClass CharacterClass charClass = CharacterClass.Gunner; switch (enemyClass) { case "Gunner": charClass = CharacterClass.Gunner; break; case "Support": charClass = CharacterClass.Support; break; case "Tank": charClass = CharacterClass.Tank; break; } // Determine HeldWeapon Weapon heldWeapon = new WeaponKnife(); switch (enemyWeapon) { case "Royale_Platformer.Model.WeaponKnife": heldWeapon = new WeaponKnife(); break; case "Royale_Platformer.Model.WeaponPistol": heldWeapon = new WeaponPistol(); break; case "Royale_Platformer.Model.WeaponPistolShield": heldWeapon = new WeaponPistolShield(); break; case "Royale_Platformer.Model.WeaponShotgun": heldWeapon = new WeaponShotgun(); break; case "Royale_Platformer.Model.WeaponAdvancedShotgun": heldWeapon = new WeaponAdvancedShotgun(); break; case "Royale_Platformer.Model.WeaponAR": heldWeapon = new WeaponAR(); break; } // Create new Character CharacterEnemy enemyPlayer = new CharacterEnemy( charClass, Convert.ToInt32(enemyMaxHealth), new Vector3(x, y, z) ); enemyPlayer.Health = Convert.ToInt32(enemyHealth); enemyPlayer.HeldWeapon = heldWeapon; enemyPlayer.Armor = enemyArmor == "True" ? true : false; enemyPlayer.Score = Convert.ToInt32(enemyScore); Sprite2D shieldSprite = ResourceCache.GetSprite2D("shield.png"); // Load Enemy //AnimationSet2D sprite = ResourceCache.GetAnimationSet2D(enemyPlayer.GetSprite()); Sprite2D sprite = ResourceCache.GetSprite2D(enemyPlayer.GetSprite()); if (sprite == null) { throw new Exception("Enemy sprite not found"); } enemyPlayer.CreateNode(scene, sprite, shieldSprite, new Vector2(enemyPlayer.Position.X, enemyPlayer.Position.Y)); Characters.Add(enemyPlayer); } }); }