public double distance_sq(GameEntity other) { float xdiff = other.Position.X - Position.X; float ydiff = other.Position.Y - Position.Y; return xdiff * xdiff + ydiff * ydiff; }
// Returns true if the other entity is within the specified range public bool inRange(GameEntity other, int range) { return distance(other) <= range; }
// Calculates the euclidean distance between the entities public double distance(GameEntity other) { if (other == null) return 0.0; return (other.Position - Position).Length(); }