public bool isCollised(Tower t) { double t1CenterX = ((double)(this.Position.X * 2 + this.Width)) / 2; double t1CenterY = ((double)(this.Position.Y * 2 + this.Height)) / 2; double t2CenterX = ((double)(t.Position.X * 2 + t.Width)) / 2; double t2CenterY = ((double)(t.Position.Y * 2 + t.Height)) / 2; double distance = Distance(new Vector2((float)t1CenterX,(float)t1CenterY), new Vector2((float)t2CenterX,(float)t2CenterY)); if (distance <= this.Width / 2 + t.Width / 2) return true; return false; }
public bool isCollision(Tower t) { //for (int i = 0; i < routePoints.Count - 1; i++) //{ // Vector2 v1 = routePoints.ElementAt(i); // Vector2 v2 = routePoints.ElementAt(i + 1); // float towerCenterX = ((float)(t.Position.X + t.Width)) / 2; // float towerCenterY = ((float)(t.Position.Y + t.Height)) / 2; // Vector2 v3 = new Vector2(towerCenterX, towerCenterY); // // distance of v3 point to v1-v2 line shall be calculated by area of triangular // double line1 = Distance(v1, v2); // double line2 = Distance(v1, v3); // double line3 = Distance(v2, v3); // double halfPerimeter = (line1 + line2 + line3) / 2; // double area = Math.Sqrt(halfPerimeter * (halfPerimeter - line1) * (halfPerimeter - line2) * (halfPerimeter - line3)); // double distance = area / line1; // if (distance < t.Width/2 + 19) // return true; //} return false; }
public virtual Tower CreateTowerWithSamePosition() { Tower t = new Tower(serviceProvider, this.Position); return t; }