public IEnumerator CapsuleDestroyedByBullet() { var capsule = BulletCapsule.Create(0, Player.Create()); var bullet = Bullet.Create(0); capsule.gameObject.SetActive(true); bullet.gameObject.SetActive(true); yield return(new WaitUntil( () => Spawnable.Pool <BulletCapsule> .Instance.Count > 0 )); Assert.AreSame(capsule, Spawnable.Pool <BulletCapsule> .Instance.RequestObject()); }
public IEnumerator CapsuleGivesBullets() { //Set up Test Player player = Player.Create(); BulletCapsule capsule = BulletCapsule.Create(0, player); yield return(new WaitForSecondsRealtime(5f)); //Perform Test capsule.Destroy(); //Assert Assert.Greater(player.Ammo, 0); }
public IEnumerator SpawnerFetchesFromPool() { Spawner spawner = Spawner.Create( objectToSpawn: typeof(BulletCapsule), spawnLimit: 1, initialDelay: 0, spawnRate: 1, maxDistanceToSpawn: 50, minDistanceToSpawn: 20 ); Spawnable.Pool <BulletCapsule> .Instance.Populate( BulletCapsule.Create(0, Player.Create()) ); spawner.StartSpawning(); yield return(new WaitWhile(() => spawner.IsSpawning)); Assert.Less(Spawnable.Pool <BulletCapsule> .Instance.Count, Spawnable.GLOBAL_SPAWN_LIMIT, "Pool population is not diminishing."); }
public IEnumerator UseLastShotToHitCapsuleAndTakeBullets() { GameState gameState = GameState.Create(0); Camera camera = new GameObject().AddComponent <Camera>(); Player player = Player.Create( health: Player.MAXIMUM_HEALTH, camera: camera, ammo: 1, gameState: gameState); string[] data = new string[] { "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "", "<spawnerconfiguration>", "\t<level>", "\t\t<spawnable type=\"Crasher\">", "\t\t\t<pattern>", "\t\t\t\t<limit>1</limit>", "\t\t\t\t<rate>0</rate>", "\t\t\t\t<delay>0</delay>", "\t\t\t\t<maxDistance>5000</maxDistance>", "\t\t\t\t<minDistance>5000</minDistance>", "\t\t\t</pattern>", "\t\t</spawnable>", "\t\t<spawnable type=\"BulletCapsule\">", "\t\t\t<pattern>", "\t\t\t\t<limit>1</limit>", "\t\t\t\t<rate>0</rate>", "\t\t\t\t<delay>0</delay>", "\t\t\t\t<maxDistance>20</maxDistance>", "\t\t\t\t<minDistance>10</minDistance>", "\t\t\t</pattern>", "\t\t</spawnable>", "\t</level>", "</spawnerconfiguration>" }; File.WriteAllLines(file, data); GameManager.Create(player, gameState); yield return(new WaitForFixedUpdate()); player.Ammo = 1; yield return(new WaitUntil(() => gameState.RoundStarted)); Spawner capsuleSpawner = null; do { var ss = Object.FindObjectsOfType <Spawner>(); foreach (var s in ss) { if (s.ObjectToSpawn == typeof(BulletCapsule)) { capsuleSpawner = s; break; } } yield return(new WaitForFixedUpdate()); } while (capsuleSpawner is null); yield return(new WaitUntil(() => capsuleSpawner.SpawnCount > 0)); BulletCapsule capsule = Object.FindObjectOfType <BulletCapsule>(); capsule.StopMoving(); capsule.transform.Translate(new Vector3(10f, 10f, 10f)); camera.transform.LookAt(capsule.transform); Assert.NotZero(Spawnable.Pool <Bullet> .Instance.Count); Assert.IsNotNull(player.Shoot()); yield return(new WaitWhile(() => capsule.isActiveAndEnabled)); yield return(new WaitForFixedUpdate()); Assert.NotZero(player.Ammo, "Player should have bullets at the end."); Assert.False(gameState.GameOver, "The game must not end if restocked on bullets."); }