예제 #1
0
 public virtual void Move(MoveEventArgs e)
 {
     if (e.distance == 0)
     {
         return;
     }
     lock (privateLock)
     {
         if (!this._movable)
         {
             return;
         }
         if ((DateTime.Now - lastMoveTime).TotalSeconds < 1 / _frameRate)
         {
             return;
         }
         MoveStart?.Invoke(this);
         XYPosition previousPosition = _position;
         _position = _position + new XYPosition(e.distance * Math.Cos(e.angle), e.distance * Math.Sin(e.angle));
         Debug(this, "Move from " + previousPosition.ToString() + " angle : " + e.angle + " distance : " + e.distance + " aim : " + _position.ToString());
         OnMove?.Invoke(this, e, previousPosition);
         Debug(this, "Move result poition : " + this._position.ToString());
         MoveComplete?.Invoke(this);
     }
 }
예제 #2
0
        public void Update(object sender, OnTickEventArgs eventArgs)
        {
            if (!Waypoints.Any())
            {
                return;
            }

            float speed = LocationModel.Parent.UnitModel.Speed;

            if (DistanceCalculator.DiagonalDistance(Waypoints.Peek(), LocationModel.FloatCoords) < speed)
            {
                // Arrived near destination
                LocationModel.FloatCoords = Waypoints.Dequeue();

                if (!Waypoints.Any())
                {
                    MoveComplete?.Invoke(this, new EventArgsWithPayload <FloatCoords>(LocationModel.FloatCoords));
                }

                return;
            }

            float xDifference = (float)DistanceCalculator.CalcDistance(LocationModel.FloatCoords.x, Waypoints.Peek().x);
            float yDifference = (float)DistanceCalculator.CalcDistance(LocationModel.FloatCoords.y, Waypoints.Peek().y);

            // calculate new coords
            float diagonalDifference = (float)DistanceCalculator.Pythagoras(xDifference, yDifference);
            float v = diagonalDifference / speed;

            FloatCoords difference = new FloatCoords
            {
                x = xDifference / v,
                y = yDifference / v
            };

            difference.x = Waypoints.Peek().x < LocationModel.FloatCoords.x ? -difference.x : difference.x;

            difference.y = Waypoints.Peek().y < LocationModel.FloatCoords.y ? -difference.y : difference.y;

            LocationModel.FloatCoords = new FloatCoords()
            {
                x = LocationModel.FloatCoords.x + difference.x,
                y = LocationModel.FloatCoords.y + difference.y
            };
        }
예제 #3
0
 private void CompleteMoveHandler()
 {
     IsMoving = false;
     MoveComplete?.Invoke();
 }
예제 #4
0
 public void MoveToPosition(IntVector2 position)
 {
     MoveStart?.Invoke();
     MoveComplete?.Invoke();
 }