Example #1
0
        public new void Move()
        {
            for (int tmpSpeed = Speed; tmpSpeed > 0; tmpSpeed--)
            {
                if (TargetPoint.HasValue || IsInShootState)
                {
                    if (!HasReachedTargetPoint)
                    {
                        SetDirectionToTargetPoint();
                    }

                    Pathfinding pathfinding = new Pathfinding();
                    Point newLocation = ExactLocation;

                    newLocation.X += (int)(ExactXDirection * 20);
                    newLocation.Y += (int)(ExactYDirection * 20);
                    ExactLocation = newLocation;

                    Point gridLocation = pathfinding.GetGridLocation(newLocation);
                    PointReceivedArgs args = new PointReceivedArgs(gridLocation, newLocation);
                    BallWillMove(this, args);
                    if (TargetPoint.HasValue && Location.Equals(TargetPoint.Value))
                    {
                        if (IsInShootState)
                        {
                            HasReachedTargetPoint = true;
                            TargetPoint = null;
                        }
                        else
                        {
                            TargetPoint = null;
                            break;
                        }
                    }
                    if (IsInShootState && HasReachedTargetPoint)
                    {
                        Speed -= 1;
                        if (Speed <= 0)
                        {
                            TargetPoint = null;
                            break;
                        }
                    }
                }
            }
        }
Example #2
0
 /// <summary>
 /// Raises the ReactToBallPosition()-Method with the points, which are saved in the event arguments.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void BallWillMove(object sender, PointReceivedArgs e)
 {
     ReactToBallPosition(e.EventPoint, e.ExactEventPoint);
 }