예제 #1
0
        public override void Act()
        {
            //Calculates the direction based on the angle (with a 40 degree shift for better effect)
            Direction = SpaceDirection.GetFromAngle(TargetRotationStrategy.CurrentAngleDegrees + RotationDirection * 40);

            //Always rotates
            TargetRotationStrategy.TargetAngleRadians = TargetRotationStrategy.CurrentRelativeAngleRadians + RotationDirection;

            //Initializing Speed
            Speed = RealSpeed;

            //Does not work as expected, but after a bit of tweaking, could be used to do small bursts of speed
            //if (WaveghostThrust.IsTurnedOn)
            //{
            //	Speed = RealSpeed / 3;
            //}
            //else
            //{
            //	Speed = RealSpeed;
            //}

            //Reducing speed if the direction is towards the outside of the Game Field
            //Reduction of X and Y stacks towards the final Speed
            if
            (
                Direction.Horizontal.Equals(SpaceDirection.HorizontalDirection.LEFT)
                &&
                X < Field.Size.Width / 4
                ||
                Direction.Horizontal.Equals(SpaceDirection.HorizontalDirection.RIGHT)
                &&
                X > 3 * Field.Size.Width / 4
            )
            {
                Speed /= 2;
            }
            if
            (
                Direction.Vertical.Equals(SpaceDirection.VerticalDirection.UP)
                &&
                Y < Field.Size.Height / 4
                ||
                Direction.Vertical.Equals(SpaceDirection.VerticalDirection.DOWN)
                &&
                Y > 3 * Field.Size.Height / 4
            )
            {
                Speed /= 2;
            }

            //Implicit Act, uses the real Speed for rest of calculations
            base.Act();
        }
예제 #2
0
 public void Act()
 {
     if (Target != null)
     {
         //Starts the movement towards the target
         Owner.Direction = SpaceDirection.Get(HorizontalDirectionToTarget(), VerticalDirectionToTarget());
     }
     else
     //Target is lost from the world
     {
         Owner.Direction = SpaceDirection.None;
     }
 }
예제 #3
0
        /// <summary>
        /// Event of Player dying.
        /// Field needs to be notified.
        /// </summary>
        public override void OnDeath()
        {
            //If there is still the way to lose, player loses
            if (Field.GameRunning)
            {
                //Display a message and stop the game-flow
                Field.MessageBroadcastText = "Game Over,\nYou've lost!";
                Field.GameOver();

                //Falls out of the universe in shame
                Direction = SpaceDirection.Get(SpaceDirection.HorizontalDirection.NONE, SpaceDirection.VerticalDirection.DOWN);
            }
        }
예제 #4
0
 private void moveY(float y)
 {
     if (Direction.Vertical.Equals(SpaceDirection.VerticalDirection.UP) && y < TopMax)
     {
         Direction = SpaceDirection.Get(Direction.Horizontal, SpaceDirection.VerticalDirection.DOWN);
     }
     else if (Direction.Vertical.Equals(SpaceDirection.VerticalDirection.DOWN) && y > BottomMax)
     {
         Direction = SpaceDirection.Get(Direction.Horizontal, SpaceDirection.VerticalDirection.UP);
     }
     else
     {
         Background.Y = y;
     }
 }
예제 #5
0
 private void moveX(float x)
 {
     if (Direction.Horizontal.Equals(SpaceDirection.HorizontalDirection.LEFT) && x < LeftMax)
     {
         Direction = SpaceDirection.Get(SpaceDirection.HorizontalDirection.RIGHT, Direction.Vertical);
     }
     else if (Direction.Horizontal.Equals(SpaceDirection.HorizontalDirection.RIGHT) && x > RightMax)
     {
         Direction = SpaceDirection.Get(SpaceDirection.HorizontalDirection.LEFT, Direction.Vertical);
     }
     else
     {
         Background.X = x;
     }
 }
예제 #6
0
    protected List<BoardSpace> GetAvailableInDirection(SpaceDirection direction)
    {
        List<BoardSpace> availableSpaces = new List<BoardSpace>();

        BoardSpace nextSpace = GameManager.currentInstance.Board.getAdjacentSpace(currentSpace, direction, PieceColor, true);

        while (GameManager.currentInstance.Board.checkSpace(nextSpace) != null)
        {
            availableSpaces.Add(nextSpace);
            if (nextSpace.spaceState == SpaceState.Contested)
            {
                break;
            }
            nextSpace = GameManager.currentInstance.Board.getAdjacentSpace(nextSpace, direction, PieceColor, true);
        }

        return availableSpaces;
    }
예제 #7
0
 public SpaceAttribute(float size = 10.0f, SpaceDirection direction = SpaceDirection.Horizontal)
 {
     Direction = direction;
     Size      = size;
 }
예제 #8
0
    /// <summary>
    /// Takes a space and direction and returns the nearest checking piece from the specified direction (returns null if there is no checking piece.)
    /// </summary>
    /// <param name="space"></param>
    /// <param name="direction"></param>
    private ChessPiece checkedFromDirection(BoardSpace space, SpaceDirection direction, TeamColor teamColor)
    {
        BoardSpace tempSpace;
        if ((direction == SpaceDirection.Front) || (direction == SpaceDirection.Back) || (direction == SpaceDirection.Left) || (direction == SpaceDirection.Right))
        {
            tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(space, direction, teamColor, false);
            while ((tempSpace != null) && ((tempSpace.OccupyingPiece == null) || ((tempSpace.OccupyingPiece.PieceColor == teamColor) && (tempSpace.OccupyingPiece.GetType() == typeof(King)))))
            {
                tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, direction, teamColor, false); //search for piece on forward column
            }

            if (tempSpace != null)  //piece found; not the end of Board
            {
                if ((tempSpace.OccupyingPiece != null) && (tempSpace.OccupyingPiece.PieceColor != teamColor))  //piece is an enemy piece
                {
                    switch ((tempSpace.OccupyingPiece.GetType().ToString()))  //is the piece one that can capture along the column?
                    {
                        case ("Rook"):
                            return tempSpace.OccupyingPiece;
                        case ("Queen"):
                            return tempSpace.OccupyingPiece;
                        case ("King"):
                            if (tempSpace == GameManager.currentInstance.Board.getAdjacentSpace(space, direction, teamColor, false))
                            {
                                return tempSpace.OccupyingPiece;
                            }
                            break;
                        default:
                            Debug.Log("Returning null...");
                            return null;
                    }
                }
            }
        }
        else if ((direction == SpaceDirection.FrontLeft) || (direction == SpaceDirection.FrontRight) || (direction == SpaceDirection.BackLeft) || (direction == SpaceDirection.BackRight))
        {
            tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(space, direction, teamColor, false);
            while ((tempSpace != null) &&(tempSpace.OccupyingPiece == null))
            {
                tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, direction, teamColor, false); //search for piece on forward column
            }
            if (tempSpace != null)  //piece found; not the end of Board
            {
                if ((tempSpace.OccupyingPiece != null) && (tempSpace.OccupyingPiece.PieceColor != teamColor))  //piece is an enemy piece
                {

                    switch ((tempSpace.OccupyingPiece.GetType().ToString()))  //is the piece one that can capture along the diagonal?
                    {
                        case ("Bishop"):
                            return tempSpace.OccupyingPiece;
                        case ("Queen"):
                            return tempSpace.OccupyingPiece;
                        case ("King"):
                            if (tempSpace == GameManager.currentInstance.Board.getAdjacentSpace(space, direction, teamColor, false))
                            {
                                return tempSpace.OccupyingPiece;
                            }
                            break;
                        case ("Pawn"):
                            if (tempSpace == GameManager.currentInstance.Board.getAdjacentSpace(space, direction, teamColor, false))
                            {
                                return tempSpace.OccupyingPiece;
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        return null;
    }
예제 #9
0
    ///// <summary>
    ///// Returns true if the adjacent space in the specified direction of the current space for the specified team color.
    ///// </summary>
    ///// <param name="currentSpace"></param>
    ///// <param name="direction"></param>
    ///// <param name="PieceColor"></param>
    ///// <returns></returns>
    //public bool isSpaceAvailable(BoardSpace spaceToCheck, TeamColor pieceColor)
    //{
    //    int[] indexArray = getIndex(spaceToCheck);
    //    if (spaceToCheck.OccupyingPiece != null)
    //    {
    //        if (spaceToCheck.OccupyingPiece.PieceColor == pieceColor)
    //        {
    //            spaceToCheck.spaceState = SpaceState.Blocked;
    //            return false;
    //        }
    //        else
    //        {
    //            spaceToCheck.spaceState = SpaceState.Contested;
    //            return true;
    //        }
    //    }
    //    else
    //    {
    //        spaceToCheck.spaceState = SpaceState.Open;
    //    }
    //    return true;
    //}
    /// <summary>
    /// Returns the space directly next to currentSpace in the specified direction. Retunrns null if the space does not exist.
    /// If validate is true, the function will return the board space only if the space is a valid move for currentSpace's occupying piece and will return null otherwise.
    /// </summary>
    /// <param name="currentSpace"></param>
    /// <param name="direction"></param>
    /// <param name="pieceColor"></param>
    /// <param name="Validate"></param>
    /// <returns></returns>
    public BoardSpace getAdjacentSpace(BoardSpace currentSpace, SpaceDirection direction, TeamColor pieceColor, bool Validate)
    {
        if (currentSpace != null)
        {
            int[] indexArray = getIndex(currentSpace);
            ChessPiece activePiece = GameManager.currentInstance.activePiece;

            //Determine newSpaceRow and newSpaceColumn by checking arguments
            switch (direction)
            {
                case (SpaceDirection.FrontLeft):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[0] += 1; //Column
                        indexArray[1] -= 1; //Row
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[0] -= 1; //Column
                        indexArray[1] += 1; //Row
                    }
                    break;

                case (SpaceDirection.Front):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[1] -= 1; //Row
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[1] += 1; //Row
                    }
                    break;

                case (SpaceDirection.FrontRight):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[0] -= 1; //Column
                        indexArray[1] -= 1; //Row
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[0] += 1; //Column
                        indexArray[1] += 1; //Row
                    }
                    break;

                case (SpaceDirection.Left):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[0] += 1; //Column
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[0] -= 1; //Column
                    }
                    break;

                case (SpaceDirection.Right):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[0] -= 1; //Column
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[0] += 1; //Column
                    }
                    break;

                case (SpaceDirection.BackLeft):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[0] += 1; //Column
                        indexArray[1] += 1; //Row
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[0] -= 1; //Column
                        indexArray[1] -= 1; //Row
                    }
                    break;

                case (SpaceDirection.Back):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[1] += 1; //Row
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[1] -= 1; //Row
                    }
                    break;

                case (SpaceDirection.BackRight):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[0] -= 1; //Column
                        indexArray[1] += 1; //Row
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[0] += 1; //Column
                        indexArray[1] -= 1; //Row
                    }
                    break;

                default:
                    break;
            }
            if ((indexArray[0] < 0) || (indexArray[1] < 0) || (indexArray[0] > 7) || (indexArray[1] > 7)) //space is outside of the board
            {
                return null;
            }
            BoardSpace newSpace = spaces[indexArray[0], indexArray[1]];
            if (Validate)
            {
                    return checkSpace(newSpace);

            }
            return newSpace;

        }
        return null;
    }
예제 #10
0
 protected AbstractCollectable(string name) : base(name)
 {
     Direction = SpaceDirection.Get(SpaceDirection.HorizontalDirection.NONE, SpaceDirection.VerticalDirection.DOWN);
 }