//damage stuffs public static float DamageCalculator(float Damage, Enemy enemy, Projectile.Type projectile) { float totalDamage = 0f; float resistedDamage; float baseDmg = Damage; Projectile.Type proj = projectile; string enemyType = enemy.EnemyType; Color textColour = Color.Black; string popUpText = ""; resistedDamage = Resist(enemy); if (enemyType == "Soldier") { if (projectile == Projectile.Type.Gun) { textColour = Color.DarkKhaki; totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) * 2; popUpText = PopUpTextManager.Effective + ":" + totalDamage.ToString(); } else if (projectile == Projectile.Type.Tesla) { textColour = Color.DarkKhaki; totalDamage = TotalDamageCrunch(baseDmg, 0, enemy, ref popUpText, ref textColour); popUpText = PopUpTextManager.Neutral + ":" + totalDamage.ToString(); } else { textColour = Color.Yellow; totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) / 2; popUpText = PopUpTextManager.Resist + ":" + totalDamage.ToString(); } } else if (enemyType == "Tank") { if (projectile == Projectile.Type.Rocket) { textColour = Color.DarkKhaki; totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) * 2; popUpText = PopUpTextManager.Effective + ":" + totalDamage.ToString(); } else if (projectile == Projectile.Type.Tesla) { textColour = Color.DarkKhaki; totalDamage = TotalDamageCrunch(baseDmg, 0, enemy, ref popUpText, ref textColour); popUpText = PopUpTextManager.Neutral + ":" + totalDamage.ToString(); } else { textColour = Color.Yellow; totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) / 4; popUpText = PopUpTextManager.Resist + ":" + totalDamage.ToString(); } } else if (enemyType == "Helicopter") { if (projectile == Projectile.Type.SAM) { textColour = Color.DarkKhaki; totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) * 2; popUpText = PopUpTextManager.Effective + ":" + totalDamage.ToString(); } else if (projectile == Projectile.Type.Tesla) { textColour = Color.DarkKhaki; totalDamage = TotalDamageCrunch(baseDmg, 0, enemy, ref popUpText, ref textColour); popUpText = PopUpTextManager.Neutral + ":" + totalDamage.ToString(); } else { textColour = Color.Yellow; totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) / 2; popUpText = PopUpTextManager.Resist + ":" + totalDamage.ToString(); } } else if (enemyType == "Jeep") { if (projectile == Projectile.Type.Rocket) { textColour = Color.DarkKhaki; totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) * 4; popUpText = PopUpTextManager.Effective + ":" + totalDamage.ToString(); } else if (projectile == Projectile.Type.Tesla) { textColour = Color.DarkKhaki; totalDamage = TotalDamageCrunch(baseDmg, 0, enemy, ref popUpText, ref textColour); popUpText = PopUpTextManager.Neutral + ":" + totalDamage.ToString(); } else { textColour = Color.Yellow; totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) / 2; popUpText = PopUpTextManager.Resist + ":" + totalDamage.ToString(); } } else if (enemyType == "Transport") { if (projectile == Projectile.Type.Rocket) { textColour = Color.DarkKhaki; totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) * 3; popUpText = PopUpTextManager.Effective + ":" + totalDamage.ToString(); } else if (projectile == Projectile.Type.Tesla) { textColour = Color.DarkKhaki; totalDamage = TotalDamageCrunch(baseDmg, 0, enemy, ref popUpText, ref textColour); popUpText = PopUpTextManager.Neutral + ":" + totalDamage.ToString(); } else { textColour = Color.Yellow; totalDamage = TotalDamageCrunch(baseDmg, resistedDamage, enemy, ref popUpText, ref textColour) / 3; popUpText = PopUpTextManager.Resist + ":" + totalDamage.ToString(); } } PopUpTextManager.Add(new PopUpText(popUpText, enemy.ScreenPos, textColour)); return(totalDamage); }
public void Shoot(Enemy targetEnemy) { Quaternion aimQuat = Quaternion.CreateFromYawPitchRoll(0, 0, Rotation); Vector2 offset = Vector2.Transform(new Vector2(25, -16), aimQuat); if (TowerType != "Tesla") { Sound.GunShot.Play(GameManager.MASTER_VOL * GameManager.SOUNDFX_VOL * 0.5f, (float)GameManager.rnd.NextDouble(), 0f); } if (GameManager.rnd.Next(1, 50) == 1) // misfire { if (TowerType != "Tesla") { Health -= 2; } else { Health -= 1; } PopUpTextManager.Add(new PopUpText(PopUpTextManager.Misfire, Position, Color.Red)); } else { switch (TypeofTower) { case Type.Gun: // Quaternion FTW. Used to Transform offset so bullets spawn correctly even as tower rotates. // Aesthetically pleasing, but fuuuu... if (Level == 1) { TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); } else if (Level == 2) { TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 16), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); } else if (Level == 3) { TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 16), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 0), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); } else { TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, -8), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 8), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 16), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.Gun, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); } break; case Type.Rocket: if (Level == 1) { TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); } else if (Level == 2) { TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 16), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); } else if (Level == 3) { TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 16), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 0), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); } else { TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, -8), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 8), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 16), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.Rocket, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); } break; case Type.SAM: if (Level == 1) { offset = Vector2.Transform(new Vector2(25, -8), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, -4), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); } else if (Level == 2) { offset = Vector2.Transform(new Vector2(25, -8), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, -4), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 8), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 4), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); } else if (Level == 3) { offset = Vector2.Transform(new Vector2(25, -10), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, -8), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, -2), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 2), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 8), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 10), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); } else { offset = Vector2.Transform(new Vector2(25, -10), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, -8), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, -6), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, -4), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 4), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 6), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 8), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); offset = Vector2.Transform(new Vector2(25, 10), aimQuat); TowerProjectiles.Add(new Projectile(Projectile.Type.SAM, targetEnemy, Position + offset, Rotation.ToVector(), 1f, Damage)); } break; case Type.Tesla: TowerProjectiles.Add(new Projectile(Projectile.Type.Tesla, targetEnemy, Position, Rotation.ToVector(), 1f, Damage)); break; } } }