public override void updateComponents(SceneManager sceneManager) { float deltaTime = clock.Restart().AsSeconds(); player.update(deltaTime); for (int i = 0; i < enemyList.Count; i++) { enemyList[i] = (Enemy)enemyList[i].update(deltaTime); } EnemySpawner.Instance.update(deltaTime); Background.Instance().update(deltaTime); ParticleSystem.Instance().update(deltaTime); // Sprawdzenie kolizji pocisków z przeciwnikami List <IDamageable> dmgList = toDamageableList(enemyList); for (int i = 0; i < projectileList.Count; i++) { projectileList[i] = (Projectile)projectileList[i].checkCollision(dmgList); if (projectileList[i] != null) { projectileList[i] = (Projectile)projectileList[i].update(deltaTime); } } // Sprawdzenie kolizji pocisków z graczem for (int i = 0; i < enemyProjectileList.Count; i++) { enemyProjectileList[i] = (Projectile)enemyProjectileList[i].checkCollision(player); if (enemyProjectileList[i] != null) { enemyProjectileList[i] = (Projectile)enemyProjectileList[i].update(deltaTime); } } List <Projectile> p = player.fire(); if (p != null) { projectileList.AddRange(p); } p = player.useLaser(); if (p != null) { (p[0] as LaserBeam).fix(); projectileList.AddRange(p); } p = player.useMissile(); if (p != null) { (p[0] as Missile).setTarget(enemyList); projectileList.AddRange(p); } p = player.useBomb(); if (p != null) { projectileList.AddRange(p); } p = player.useWave(); if (p != null) { (p[0] as IonWave).fix(); p[0].animation.animationSprite.Position = new Vector2f(player.animation.animationSprite.Position.X + player.animation.animationSprite.Scale.X * player.animation.animationSprite.Texture.Size.X / 2, p[0].animation.animationSprite.Position.Y); projectileList.AddRange(p); } projectileList.RemoveAll(proj => proj == null); enemyProjectileList.RemoveAll(proj => proj == null); enemyList.RemoveAll(enem => enem == null); // Sprawdzenie warunku porażki if (player.health <= 0) { timeToEnd -= deltaTime; score.Visible = true; score.Active = true; score.Text = "Porazka"; if (timeToEnd < 0) { //EndingMenu.Instance().hasWon = false; SceneManager.Instance().changeScene(PlayerMenu.Instance()); } } // Sprzawdzenie warunku zwycięstwa if (enemyList.Count == 0 && EnemySpawner.Instance.isEmpty) { timeToEnd -= deltaTime; score.Visible = true; score.Active = true; score.Text = "Wygrana"; if (timeToEnd < 0) { //EndingMenu.Instance().hasWon = true; PlayerManager.Instance.missionCompleted(); SceneManager.Instance().changeScene(PlayerMenu.Instance()); } } }
public bool initialize(int lvlNb, ref List <Enemy> _enemyList) { try { isEmpty = false; // Wczytanie pliku xml enemyList = _enemyList; XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(string.Format(ResourcesManager.xmlPath + "level{0}.xml", lvlNb)); // Inicjalizacja pierwszego przeciwnika Randomer.value = Int32.Parse(xmldoc.SelectSingleNode("main").SelectSingleNode("enemy1mon").InnerText); // Trochę na około ale działa Image shotimg = new Image(ResourcesManager.resourcesPath + "enemyBullet.png"); shotimg.FlipHorizontally(); Texture shot = new Texture(shotimg); //Texture shot = new Texture("enemybullet.png"); Randomer.bulletPrefab = new Bullet(ref shot, Int32.Parse(xmldoc.SelectSingleNode("main").SelectSingleNode("enemy1dmg").InnerText), new Vector2f(1f, 1f)); XmlNodeList enemies = xmldoc.SelectSingleNode("main").SelectSingleNode("enemies").SelectNodes("enemy"); enemiesToSpawn = new List <EnemyData>(); foreach (XmlNode enemy in enemies) { // Tworzenie kopii wzoru przeciwnika EnemyData enemyData = new EnemyData(); int tmp; Int32.TryParse(enemy.SelectSingleNode("enemyType").InnerText, out tmp); if (tmp >= enemyPrefabs.Count) { throw new Exception("Błędny numer przeciwnika"); // TODO throwuj błąd nieprawidłowy kod przeciwnika } enemyData.enemy = (Enemy)enemyPrefabs[tmp].Clone(); // Ustalanie pozycji startowej Vector2f tmpVec = new Vector2f(); tmpVec.X = float.Parse(enemy.SelectSingleNode("x").InnerText); tmpVec.Y = float.Parse(enemy.SelectSingleNode("y").InnerText); enemyData.enemy.setColliderPosition(tmpVec); //enemyData.enemy.animation.animationSprite.Position = tmpVec; // Ustalanie spawnu enemyData.timeToSpawn = float.Parse(enemy.SelectSingleNode("spawnTimer").InnerText); tmp = Int32.Parse(enemy.SelectSingleNode("spawnType").InnerText); if (tmp > 1 || tmp < 0) { throw new Exception("Błędny rodzaj tworzenia preciwnika"); } enemyData.spawnType = (EnemyData.SpawnType)tmp; enemiesToSpawn.Add(enemyData); } return(true); } catch (Exception ex) { if (ex.GetType() == typeof(System.IO.FileNotFoundException)) { MessageBox.Show("Następny poziom dostępny w DLC"); } else { MessageBox.Show(ex.Message); } SceneManager.Instance().changeScene(PlayerMenu.Instance()); return(false); } }