示例#1
0
    public override Transform SimulateMovement(Vector3 direction, GameObject objectClone, int playerSide)
    {
        Transform pieceCloneTransform           = null;
        bool      isCurrentSimulationInProgress = true;

        while (isCurrentSimulationInProgress)
        {
            bool       possible      = false;
            Quaternion startRotation = objectClone.transform.rotation;

            do
            {
                possible = AiUtils.IsLineGapPossible(objectClone, AiUtils.GetBottomPiecePositions(playerSide, objectClone), playerSide);
                if (possible)
                {
                    if (MovementUtils.IsRotationPossible(objectClone))
                    {
                        MovementGeneratorUtils.SimulateNextRotation(objectClone, true);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }while (objectClone.transform.rotation.eulerAngles.y != startRotation.eulerAngles.y);

            if (possible)
            {
                bool isMovePossible = MovementUtils.IsMovementPossible(direction, objectClone);
                if (isMovePossible)
                {
                    MovementGeneratorUtils.SimulateNextTranslation(objectClone, direction);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(objectClone.transform);
            }
        }

        return(pieceCloneTransform);
    }
示例#2
0
    public override Transform SimulateMovement(Vector3 direction, GameObject objectClone, int playerSide)
    {
        Transform  pieceCloneTransform = null;
        Quaternion startRotation       = objectClone.transform.rotation;
        Vector3    startPosition       = objectClone.transform.position;

        do
        {
            while (true)
            {
                bool isGapPossible = AiUtils.IsLineGapPossible(objectClone, AiUtils.GetBottomPiecePositions(playerSide, objectClone), playerSide);

                if (!isGapPossible)
                {
                    this.UpdateValidPositionCriteriaList(objectClone, playerSide);
                }

                if (!MovementUtils.IsMovementPossible(direction, objectClone))
                {
                    break;
                }
                else
                {
                    MovementGeneratorUtils.SimulateNextTranslation(objectClone, direction);
                }
            }

            objectClone.transform.SetPositionAndRotation(startPosition, objectClone.transform.rotation);

            if (MovementUtils.IsRotationPossible(objectClone))
            {
                MovementGeneratorUtils.SimulateNextRotation(objectClone, true);
                startPosition = objectClone.transform.position;
            }
            else
            {
                break;
            }
        }while (objectClone.transform.rotation.eulerAngles.y != startRotation.eulerAngles.y);

        return(pieceCloneTransform);
    }
示例#3
0
 private bool IsRotateForbiden()
 {
     return(!MovementUtils.IsRotationPossible(this.gameObject));
 }
    // Update is called once per frame
    void FixedUpdate()
    {
        if (IsMoving)
        {
            elapsedTime += Time.deltaTime;
            float verticalMove = -1f;

            Vector3 newGameObjectVelocity = new Vector3();

            Vector3 newPosition = new Vector3();

            if (Input.GetKey(DetectPlayerMovement(DirectionEnum.Direction.RIGHT)))
            {
                if (!this.IsMoveForbiden(KeyCode.RightArrow))
                {
                    newPosition = this.transform.position + Vector3.right;
                    this.MoveObjectToNewPosition(newPosition);
                }
            }
            else if (Input.GetKey(DetectPlayerMovement(DirectionEnum.Direction.LEFT)))
            {
                if (!this.IsMoveForbiden(KeyCode.LeftArrow))
                {
                    newPosition = this.transform.position + Vector3.left;
                    this.MoveObjectToNewPosition(newPosition);
                }
            }

            if (Input.GetKey(DetectPlayerRotation(DirectionEnum.Direction.RIGHT)) && !this.IsRotationLocked)
            {
                bool isClockwise = true;
                if (MovementUtils.IsRotationPossible(this.gameObject))
                {
                    this.RotateObject(isClockwise);
                }

                this.IsRotationLocked = true;
            }
            else if (Input.GetKey(DetectPlayerRotation(DirectionEnum.Direction.LEFT)) && !this.IsRotationLocked)
            {
                bool isClockwise = false;
                if (MovementUtils.IsRotationPossible(this.gameObject))
                {
                    this.RotateObject(isClockwise);
                }

                this.IsRotationLocked = true;
            }

            if ((Input.GetKeyUp(DetectPlayerRotation(DirectionEnum.Direction.LEFT)) || Input.GetKeyUp(DetectPlayerRotation(DirectionEnum.Direction.RIGHT))) && this.IsRotationLocked)
            {
                this.IsRotationLocked = false;
            }

            if (Input.GetKey(DetectPlayerMovement(DirectionEnum.Direction.DOWN)))
            {
                newGameObjectVelocity = new Vector3(gameObJectRigidBody.velocity.x, gameObJectRigidBody.velocity.y, verticalMove * GameUtils.FetchPlayerPieceSpeed(OwnerId));
            }
            else
            {
                newGameObjectVelocity = new Vector3(this.gameObJectRigidBody.velocity.x, this.gameObJectRigidBody.velocity.y, -0.5f * GameUtils.FetchPlayerPieceSpeed(OwnerId));
            }

            this.gameObJectRigidBody.velocity = newGameObjectVelocity;
        }
    }