/// <summary> /// <para> /// Calculates the linear distance between your creature and another using /// various API's defined by the Vector class. /// </para> /// </summary> /// <param name="organismState"> /// The OrganismState object for the creature to /// use when computing linear distance from you're creature. /// </param> /// <returns> /// A System.Double representing the linear distance between your creature and another. /// </returns> public double DistanceTo(OrganismState organismState) { if (organismState == null) { throw new ArgumentNullException("organismState", "The argument 'organismState' cannot be null"); } return(Vector.Subtract(Position, organismState.Position).Magnitude); }
/// <summary> /// Determines the facing of the creature based on the movement /// vector and update the creature's actual direction as a result. /// </summary> private void SetBitmapDirection() { if (IsImmutable) { throw new GameEngineException("Object is immutable."); } if (CurrentMoveToAction != null) { var direction = Vector.Subtract(CurrentMoveToAction.MovementVector.Destination, currentPosition); var unitVector = direction.GetUnitVector(); var angle = Math.Acos(unitVector.X); if (unitVector.Y < 0) { angle = 6.2831853 - angle; } // convert radians to degrees ActualDirection = (int)((angle / 6.283185) * 360); } }