Ejemplo n.º 1
0
		public void WithFightingDragonTowerHasExtendedRange()
		{
			var tower = new Tower(TowerType.Fire, Vector3D.Zero);
			var towerProperties = ContentLoader.Load<TowerPropertiesXml>(Xml.TowerProperties.ToString());
			var defaultRange = towerProperties.Get(TowerType.Fire).Range;
			Assert.AreEqual(defaultRange * 1.25f, tower.GetStatValue("Range"));
		}
Ejemplo n.º 2
0
		public void WithFlyingPenguinTowerHasFasterAttacks()
		{
			var tower = new Tower(TowerType.Fire, Vector3D.Zero);
			var towerProperties = ContentLoader.Load<TowerPropertiesXml>(Xml.TowerProperties.ToString());
			var defaultAttackFrequency = towerProperties.Get(TowerType.Fire).AttackFrequency;
			Assert.AreEqual(defaultAttackFrequency * 1.3333f, tower.GetStatValue("AttackFrequency"));
		}
Ejemplo n.º 3
0
		public void InitializingTowerCreatesTowerModel()
		{
			var tower = new Tower(TowerType.Water, Vector3D.Zero);
			tower.RenderModel();
			Assert.AreEqual(1, EntitiesRunner.Current.GetEntitiesOfType<Model>().Count);
			Assert.AreEqual(1, EntitiesRunner.Current.GetEntitiesOfType<Tower>().Count);
		}
Ejemplo n.º 4
0
		private static void DoRadiusAttack(Tower tower, List<Creep> creepsWithinRange)
		{
			var type = tower.Type;
			var power = tower.GetStatValue("Power");
			foreach (var creep in creepsWithinRange)
				creep.ReceiveAttack(type, power, RadiusAttackModifier);
		}
Ejemplo n.º 5
0
		public void SetUp()
		{
			new Player();
			tower = new Tower(TowerType.Fire, Vector3D.Zero);
			creep = new Creep(CreepType.Cloth, Vector3D.Zero);
			adjustment = new StatAdjustment("TestAdjustment");
		}
Ejemplo n.º 6
0
		public void TowerDoesNotAttackInactiveCreep()
		{
			var tower = new Tower(TowerType.Water, Vector2D.Zero);
			var creep = CreateCreepOfType(CreepType.Cloth, Vector3D.UnitY);
			creep.IsActive = false;
			AdvanceTimeTillTowerAttacks(tower);
			Assert.AreEqual(1, creep.GetStatPercentage("Hp"));
		}
Ejemplo n.º 7
0
		public void TowerDoesNotAttackIfTooFarFromCreep()
		{
			var tower = new Tower(TowerType.Water, Vector2D.Zero);
			var creep = CreateCreepOfType(CreepType.Cloth, 2.0f * Vector3D.UnitY);
			creep.Position = new Vector3D(100, 100, 0);
			AdvanceTimeTillTowerAttacks(tower);
			Assert.IsFalse(tower.IsOnCooldown);
			Assert.AreEqual(1, creep.GetStatPercentage("Hp"));
		}
Ejemplo n.º 8
0
		public void TowerDoesNotAttackIfStillInCooldown()
		{
			var tower = new Tower(TowerType.Water, Vector2D.Zero);
			var creep = CreateCreepOfType(CreepType.Cloth, 2.0f * Vector3D.UnitY);
			tower.RenderModel();
			AdvanceToJustBeforeTowerAttack(tower);
			Assert.IsTrue(tower.IsOnCooldown);
			Assert.AreEqual(1, creep.GetStatPercentage("Hp"));
		}
Ejemplo n.º 9
0
		public void WithoutFlyingPenguinTowerHasDefaultAttackFrequency()
		{
			player.UnlockAvatar(CreepyTowers.Content.Avatars.Dragon);
			player.ChangeAvatar(CreepyTowers.Content.Avatars.Dragon);
			var tower = new Tower(TowerType.Fire, Vector3D.Zero);
			var towerProperties = ContentLoader.Load<TowerPropertiesXml>(Xml.TowerProperties.ToString());
			var defaultAttackFrequency = towerProperties.Get(TowerType.Fire).AttackFrequency;
			Assert.AreEqual(defaultAttackFrequency, tower.GetStatValue("AttackFrequency"));
		}
Ejemplo n.º 10
0
		public void WithoutFightingDragonTowerHasDefaultRange()
		{
			player.UnlockAvatar(CreepyTowers.Content.Avatars.PiggyBank);
			player.ChangeAvatar(CreepyTowers.Content.Avatars.PiggyBank);
			var tower = new Tower(TowerType.Fire, Vector3D.Zero);
			var towerProperties = ContentLoader.Load<TowerPropertiesXml>(Xml.TowerProperties.ToString());
			var defaultRange = towerProperties.Get(TowerType.Fire).Range;
			Assert.AreEqual(defaultRange, tower.GetStatValue("Range"));
		}
Ejemplo n.º 11
0
		private static void DamageCreepAndSurroundingCreeps(Tower tower, Creep target, 
			List<Creep> creepsWithinRange)
		{
			if (tower.AttackType == AttackType.Circle)
				DoRadiusAttack(tower, creepsWithinRange);
			else if (tower.AttackType == AttackType.Cone)
				DoConeAttack(tower, target, creepsWithinRange);
			//else if (tower.AttackType == AttackType.DirectShot)
			//	target.ReceiveAttack(tower.Type, tower.Power);
		}
Ejemplo n.º 12
0
		private static List<Creep> FindAllCreepsWithinRangeOfTower(Tower tower, List<Creep> creeps)
		{
			float range = tower.GetStatValue("Range");
			float rangeSquared = range * range;
			var targets = new List<Creep>();
			foreach (Creep creep in creeps)
			{
				var distance = (creep.Position - tower.Position).LengthSquared;
				if (distance <= rangeSquared)
					targets.Add(creep);
			}
			return targets;
		}
Ejemplo n.º 13
0
		private static void DoConeAttack(Tower tower, Creep target, List<Creep> creepsWithinRange)
		{
			Vector2D towerPosition = tower.Position.GetVector2D();
			Vector2D creepPosition = target.Position.GetVector2D();
			Vector2D aim = Vector2D.Normalize(creepPosition - towerPosition);
			float edgeDotProduct = GetEdgeDotProduct(creepPosition, towerPosition, aim);
			var power = tower.GetStatValue("Power");
			foreach (Creep creep in creepsWithinRange)
			{
				var position = creep.Position.GetVector2D();
				if (aim.DotProduct(Vector2D.Normalize(position - towerPosition)) >= edgeDotProduct)
					creep.ReceiveAttack(tower.Type, power, ConeAttackModifier);
			}
		}
Ejemplo n.º 14
0
		public static void SpawnTowerInGame(this GameLevel level, TowerType type,
			Vector2D gridPosition, float rotation = 0.0f)
		{
			var properties = ContentLoader.Load<TowerPropertiesXml>(Xml.TowerProperties.ToString());
			if (IsCreepInTile(gridPosition) || Player.Current.Gold < properties.Get(type).Cost)
				return;
			var index = level.GetIndexForMapData(gridPosition);
			if (level.MapData[index] != LevelTileType.Placeable)
				return;
			level.SetUnreacheableTile(gridPosition, type);
			if (!level.IsPossibleAddTower(gridPosition))
				return;
			var towerPosInWorldSpace = level.GetWorldCoordinates(gridPosition);
			var tower = new Tower(type, towerPosInWorldSpace, rotation);
			tower.RenderModel();
			level.EarnGold(-properties.Get(type).Cost);
		}
Ejemplo n.º 15
0
		public void DisplayAndDisposeTower()
		{
			var tower = new Tower(TowerType.Water, Vector3D.Zero, 170.0f);
			tower.RenderModel();
			tower.Dispose();
			Assert.AreEqual(0, EntitiesRunner.Current.GetEntitiesOfType<Tower>().Count);
		}
Ejemplo n.º 16
0
		public void DisplaySliceTower()
		{
			var tower = new Tower(TowerType.Slice, Vector3D.Zero, 120.0f);
			tower.RenderModel();
		}
Ejemplo n.º 17
0
		public void DisplayImpactTower()
		{
			var tower = new Tower(TowerType.Impact, Vector3D.Zero, 120.0f);
			tower.RenderModel();
		}
Ejemplo n.º 18
0
		public void DisposingTowerRemovesTowerEntity()
		{
			var tower = new Tower(TowerType.Water, Vector3D.Zero);
			tower.Dispose();
			Assert.IsFalse(tower.IsActive);
		}
Ejemplo n.º 19
0
		public void DisplayWaterTower()
		{
			var tower = new Tower(TowerType.Water, Vector3D.Zero, 170.0f);
			tower.RenderModel();
		}
Ejemplo n.º 20
0
		private void AdvanceTimeTillTowerAttacks(Tower tower)
		{
			var towerCooldown = 1 / tower.GetStatValue("AttackFrequency");
			AdvanceTimeAndUpdateEntities(towerCooldown + 0.1f);
		}
Ejemplo n.º 21
0
		public void ShowWaterTowerWithSunlightEnabled()
		{
			new Player();
			var camera = Camera.Use<LookAtCamera>();
			camera.Position = new Vector3D(0.0f, -4.0f, 2.0f);
			var tower = new Tower(TowerType.Water, Vector3D.Zero);
			tower.RenderModel();
		}
Ejemplo n.º 22
0
		private void AdvanceToJustBeforeTowerAttack(Tower tower)
		{
			var towerCooldown = 1 / tower.GetStatValue("AttackFrequency");
			AdvanceTimeAndUpdateEntities(towerCooldown - 0.1f);
		}
Ejemplo n.º 23
0
		public void ShowTowerFiringAtAMovingCreep()
		{
			camera.ZoomLevel = 1 / 20.0f;
			var tower = new Tower(TowerType.Water, new Vector2D(0, 0));
			var creep = new Creep(CreepType.Cloth, new Vector2D(1, 3));
			creep.Path = new List<Vector2D> { (new Vector2D(1, -10)) };
			tower.RenderModel();
			creep.RenderModel();
			new TowerTargetFinder();
		}
Ejemplo n.º 24
0
		public void CheckForCreepUnderAttack()
		{
			var tower = new Tower(TowerType.Slice, new Vector2D(0, 0));
			tower.RenderModel();
			var creep = new Creep(CreepType.Cloth, new Vector2D(1, 0));
			new TowerTargetFinder();
			AdvanceTimeAndUpdateEntities(2.1f);
			Assert.Less(creep.GetStatPercentage("Hp"), 1);
		}
Ejemplo n.º 25
0
		public void ShowTowerFiringAtCreepAtRegularIntervals()
		{
			camera.ZoomLevel = 1 / 20.0f;
			var tower = new Tower(TowerType.Water, new Vector2D(0, 0));
			var creep = new Creep(CreepType.Cloth, new Vector2D(2, 0));
			tower.RenderModel();
			creep.RenderModel();
			new TowerTargetFinder();
		}
Ejemplo n.º 26
0
		public void DisplayAcidTower()
		{
			var tower = new Tower(TowerType.Acid, Vector3D.Zero, 120.0f);
			tower.RenderModel();
		}
Ejemplo n.º 27
0
		public void InAbsenceOfCreepsTheTowerDoesNotFire()
		{
			var tower = new Tower(TowerType.Fire, Vector2D.Zero);
			AdvanceTimeTillTowerAttacks(tower);
			Assert.IsFalse(tower.IsOnCooldown);
		}
Ejemplo n.º 28
0
		public void DisplayFireTower()
		{
			var tower = new Tower(TowerType.Fire, Vector3D.Zero, 150.0f);
			tower.RenderModel();
		}
Ejemplo n.º 29
0
		public void ShowAllTowerTypesAndEffects()
		{
			var tower = new Tower(TowerType.Acid, Vector3D.Zero);
			tower.RenderModel();
			var creep = new Creep(CreepType.Cloth, new Vector2D(2, 8));
			new Command(() => { tower.FireAtCreep(creep); }).Add(new KeyTrigger(Key.Space));
			new Command(() => { tower.RotationZ += 2; }).Add(new KeyTrigger(Key.A, State.Pressed));
			new Command(() => { tower.RotationZ -= 2; }).Add(new KeyTrigger(Key.D, State.Pressed));
			new Command(() =>
			{ //ncrunch: no coverage start
				tower.Dispose();
				tower = new Tower(CycleTypeUpwards(tower.Type), Vector3D.Zero);
				tower.RenderModel(); //ncrunch: no coverage end
			}).Add(new KeyTrigger(Key.W));
			new Command(() =>
			{ //ncrunch: no coverage start
				tower.Dispose();
				tower = new Tower(CycleTypeDownwards(tower.Type), Vector3D.Zero);
				tower.RenderModel(); //ncrunch: no coverage end
			}).Add(new KeyTrigger(Key.S));
		}
Ejemplo n.º 30
0
		public void DirectShotTowerFiresAtNearestCreep()
		{
			var tower = new Tower(TowerType.Water, Vector2D.Zero);
			var creep = CreateCreepOfType(CreepType.Cloth, Vector3D.UnitY);
			tower.RenderModel();
			var furtherCreep = CreateCreepOfType(CreepType.Cloth, new Vector2D(2.75f, 2.75f));
			AdvanceTimeTillTowerAttacks(tower);
			AdvanceTimeAndUpdateEntities(1.0f);
			Assert.IsTrue(tower.IsOnCooldown);
			Assert.LessOrEqual(0, EntitiesRunner.Current.GetEntitiesOfType<ParticleEmitter>().Count);
			Assert.Less(creep.GetStatPercentage("Hp"), 1);
			Assert.AreEqual(1, furtherCreep.GetStatPercentage("Hp"));
		}