Exemplo 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;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks whether the game ball in his current state (with his target point) will go through the target rectangle.
        /// Returns the last grid location where the ball will be before it goes into the rectangle.
        /// </summary>
        /// <param name="targetRectangle"></param>
        /// <returns></returns>
        public Point? PointBeforeRectangleEntry(Rectangle targetRectangle)
        {
            if (GameBall.TargetPoint.HasValue || GameBall.IsInShootState)
            {
                Pathfinding pathfinding = new Pathfinding();

                if (targetRectangle.Contains(GameBall.ExactTargetLocation))
                {
                    return pathfinding.GetGridLocation(GameBall.ExactTargetLocation);
                }
                else
                {
                    Point temporaryExactLocation = GameBall.ExactLocation;
                    Point lastGridLocation = pathfinding.GetGridLocation(temporaryExactLocation);

                    while (pathfinding.GetGridLocation(temporaryExactLocation) != pathfinding.GetGridLocation(GameBall.ExactTargetLocation))
                    {
                        lastGridLocation = pathfinding.GetGridLocation(temporaryExactLocation);
                        double[] direction = pathfinding.GetExactDirection(temporaryExactLocation, GameBall.ExactTargetLocation);
                        temporaryExactLocation.X += (int)(direction[0] * 5);
                        temporaryExactLocation.Y += (int)(direction[1] * 5);

                        if (targetRectangle.Contains(pathfinding.GetGridLocation(temporaryExactLocation)))
                        {
                            return lastGridLocation;
                        }
                    }
                }
            }

            return null;
        }
Exemplo n.º 3
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;
        }