Ejemplo n.º 1
0
        /* Returns a player if he will stand in the way of the ball
         * Returns null if no player stands in the way. */
        public Player PlayerInBallWay(Point shotPoint, Point targetPoint)
        {
            Pathfinding pathfinding = new Pathfinding();
            Point tmpBallExactLocation = pathfinding.GetExactLocation(shotPoint);
            Point tmpBallGridLocation = pathfinding.GetGridLocation(tmpBallExactLocation);

            for(int i = 0; i < 3; i++)
            {
                if (!tmpBallGridLocation.Equals(shotPoint))
                {
                    Player playerOnPosition = pathfinding.StandsPlayerOnPosition(tmpBallGridLocation, 1);
                    if (playerOnPosition != null)
                    {
                        return playerOnPosition;
                    }
                }
                double[] direction = pathfinding.GetExactDirection(tmpBallExactLocation, pathfinding.GetExactLocation(targetPoint));
                tmpBallExactLocation.X += (int)(direction[0] * 20);
                tmpBallExactLocation.Y += (int)(direction[1] * 20);
                tmpBallGridLocation = pathfinding.GetGridLocation(tmpBallExactLocation);
            }

            return null;
        }
Ejemplo n.º 2
0
        /*Returns the location where the ball will be in the next round */
        public Point BallNextRoundLocation()
        {
            Point ballTarget;

            if (GameBall.HasPlayerContact && GameBall.LastPlayer != null)
            {
                Pathfinding pathfinding = new Pathfinding();
                ActionType type;
                //sets the balltarget to the point where the player who controls the ball at the moment will go to in the next round. */
                ballTarget = pathfinding.PlayerAtSpecificRound(GameBall.LastPlayer, 1, out type);
            }
            else if (GameBall.TargetPoint.HasValue)
            {
                Pathfinding pathfinding = new Pathfinding();
                Point tmpBallExactLocation = GameBall.ExactLocation;
                Point tmpBallGridLocation = pathfinding.GetGridLocation(tmpBallExactLocation);

                double[] direction = pathfinding.GetExactDirection(tmpBallExactLocation, pathfinding.GetExactLocation(GameBall.TargetPoint.Value));
                for (int i = 0; i < GameBall.Speed; i++)
                {
                    tmpBallExactLocation.X += (int)(direction[0] * 20);
                    tmpBallExactLocation.Y += (int)(direction[1] * 20);
                }
                ballTarget = pathfinding.GetGridLocation(tmpBallExactLocation);
            }
            else
            {
                ballTarget = GameBall.Location;
            }

            return ballTarget;
        }