public Projectile(Texture2D texture, Tower tower, Creep _aim) { text = texture; speed = 900f; thetower = tower; aim = _aim; boundingBox = new Rectangle(tower.boundingBox.Center.X, tower.boundingBox.Center.Y, 5, 15); destination = new Vector2(aim.boundingBox.Center.X, aim.boundingBox.Center.Y); }
private void Attack(Creep item) { if (!inCooldown) { projectiles.Add(new Projectile(Game1.missileText, this, item)); inCooldown = true; Cooldown = DateTime.Now.AddMilliseconds(speed); } else if(DateTime.Now >= Cooldown) { inCooldown = false; } }
public static double DetectCreep(Creep creep, Tower tower) { //a^2+b^2=c^2 //c = SQRT(a^2+b^2) List<Point> corners = new List<Point>(); corners.Add(creep.boundingBox.Location); corners.Add(new Point(creep.boundingBox.Right, creep.boundingBox.Top)); corners.Add(new Point(creep.boundingBox.Left, creep.boundingBox.Bottom)); corners.Add(new Point(creep.boundingBox.Right, creep.boundingBox.Bottom)); double smallest = double.MaxValue; foreach (var item in corners) { int deltaX = tower.boundingBox.Center.X - item.X; int deltaY = tower.boundingBox.Center.Y - item.Y; var dist = Math.Sqrt(deltaX * deltaX + deltaY * deltaY); if (dist < smallest) { smallest = dist; } } return smallest; }