示例#1
0
 public void NPCmove(MoveScripts.Direction _direction)
 {
     /*
      * centerPosition = new Vector3(transform.position.x + 0.5f, transform.position.y - 0.5f, transform.position.z);
      * SetFacingDirectionLogic(_direction);
      * input = MoveScripts.GetVector2FromDirection(_direction);
      * checkPoint = new Vector2(centerPosition.x+input.x, centerPosition.y+input.y);
      * hit = Physics2D.OverlapArea(checkPoint,checkPoint);
      * moveDetection.StartDetection(hits, lookDirection);
      *
      * Debug.Log("Got Here!");
      * //MoveScripts.CheckForTag(this.gameObject, hit, "Player")
      * if (moveDetection.CanPhysicallyMove())
      * {
      *  Debug.Log("Got Here! 2");
      *
      * }
      */
     SetFacingDirectionLogic(_direction);
     input = MoveScripts.GetVector2FromDirection(_direction);
     if (CanMoveInDirection(_direction))
     {
         moveSpeedCurrent = moveSpeed / 2;
         SetFacingDirection(input);
         StartCoroutine(move(transform));
     }
 }
示例#2
0
    private void TrainerScan()
    {
        if (!defeated && !engaged)
        {
            Vector2 checkVector;
            Vector2 size2;
            Vector2 directionVector;
            bool    foundWall = false;
            int     maxRange  = maxSeeDistance;
            if (limitRange)
            {
                maxRange = rangeLimit + 1;
            }
            int foundRange = -1;
            while (!foundWall && foundRange < maxRange)
            {
                foundRange++;
                checkVector = MoveScripts.GetFrontVector2(move, (float)foundRange, true);
                Collider2D[] hit = Physics2D.OverlapAreaAll(checkVector, checkVector);
                //foundWall = MoveScripts.CheckForTag(this.gameObject,hit,TrainerLookStop);
                foundWall = !MoveBegin(hit);

                /*
                 * if (foundRange < maxRange)
                 * {
                 *  foundPlayer = MoveScripts.CheckForTag(this.gameObject,hit,"Player");
                 *  if (foundPlayer && !sr.saveSystemObject.isLoading && !sr.battleSetup.playerDead && !engaged) sr.battleSetup.StartCutscene(new PackedCutscene(GetComponent<Cutscene>()));
                 * }
                 */
                if (foundTrainer)
                {
                    Debug.Log("Found Trainer! FoundWall = " + foundWall);
                }
                if (foundTrainer && !foundWall)
                {
                    if (!sr.saveSystemObject.isLoading && !sr.battleSetup.playerDead && !engaged)
                    {
                        engaged = true;
                        sr.battleSetup.StartCutscene(new PackedCutscene(GetComponent <Cutscene>()));
                    }
                }
            }

            foundRange--;
            checkVector     = MoveScripts.GetFrontVector2(move, (float)foundRange / 2, true);
            size2           = MoveScripts.GetVector2FromDirection(move.lookDirection) * foundRange;
            directionVector = MoveScripts.GetVector2FromDirection(move.lookDirection) * 0.5f;
            if (size2.x == 0)
            {
                size2.x = 1;
            }
            if (size2.y == 0)
            {
                size2.y = 1;
            }
            Size          = new Vector3(size2.x, size2.y, 1);
            StartPosition = new Vector3(checkVector.x + directionVector.x, checkVector.y + directionVector.y, -1);
        }
    }
示例#3
0
 // Update is called once per frame
 void Update()
 {
     if (sr.battleSetup.PlayerCanMove() && !move.isMoving)
     {
         if (Input.GetButtonDown("Submit"))
         {
             Vector2      faceDirection = MoveScripts.GetVector2FromDirection(MoveScripts.GetOppositeDirection(move.lookDirection));
             Vector2      checkPoint    = MoveScripts.GetFrontVector2(move, 1, true);
             Collider2D[] hit           = Physics2D.OverlapAreaAll(checkPoint, checkPoint);
             InteractBegin(hit);
         }
     }
 }
示例#4
0
    private void OnDrawGizmos()
    {
        if (doorSize.x < 1)
        {
            doorSize.x = 1;
        }
        if (doorSize.y < 1)
        {
            doorSize.y = 1;
        }
        Vector3 center = transform.position + new Vector3(0.5f + (doorSize.x - 1) / 2, -0.5f - (doorSize.y - 1) / 2);

        Gizmos.color = new Color(1, 0, 1, 0.8f);
        Gizmos.DrawCube(center, doorSize);
        DrawArrow.ForGizmo(center, MoveScripts.GetVector2FromDirection(exitDirection), new Color(1, 1, 1, 1f), 0.5f, 20f);
        GetComponent <BoxCollider2D>().offset = center - transform.position;
        GetComponent <BoxCollider2D>().size   = doorSize;
    }
示例#5
0
    public bool CanMoveInDirection(MoveScripts.Direction _direction)
    {
        Vector2 _input = MoveScripts.GetVector2FromDirection(_direction);

        checkPoint = new Vector2(centerPosition.x + _input.x, centerPosition.y + _input.y);
        hits       = Physics2D.OverlapAreaAll(checkPoint, checkPoint);
        moveDetection.StartDetection(hits, _direction);
        moveDetection.DEBUG_PrintColliders();
        if (moveDetection.CanPhysicallyMove())
        {
            Debug.Log("Successful Move Opportunity");
            return(true);
        }
        else
        {
            Debug.Log("Blocked Opportunity");
            return(false);
        }
    }
示例#6
0
    public void PreparePlayer()
    {
        GameObject newPlayer = Instantiate(database.Player);

        newPlayer.transform.position = sr.battleSetup.loadPosition;
        Vector2 input      = MoveScripts.GetVector2FromDirection(sr.battleSetup.loadDirection);
        Move    playerMove = newPlayer.GetComponent <Move>();

        playerMove.SetFacingDirection(input);
        playerMove.lookDirection = sr.battleSetup.loadDirection;
        if (sr.battleSetup.loadAnimTime != 0f)
        {
            playerMove.animTime = sr.battleSetup.loadAnimTime;
            playerMove.ContinueWalkAnimation();
        }

        if (sr.battleSetup.loadMoving)
        {
            StartCoroutine(playerMove.move(playerMove.transform));
        }
        playerMove.SetWalkAnimation();
    }
示例#7
0
 public void SetFacingDirectionLogic(MoveScripts.Direction newDirection)
 {
     lookDirection = newDirection;
     SetFacingDirection(MoveScripts.GetVector2FromDirection(lookDirection));
 }
示例#8
0
    public void Update()
    {
        centerPosition = new Vector3(transform.position.x + 0.5f, transform.position.y - 0.5f, transform.position.z);
        switch (logicType)
        {
        default: break;

        case LogicType.Player:
            if (!isMoving)
            {
                if (playerInputAccepted)
                {
                    thisDirectInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
                    input           = MoveScripts.DigitizeInput(thisDirectInput, lastDirectInput, input);
                    lastDirectInput = thisDirectInput;
                }

                animMoving = false;

                if (input != Vector2.zero && ableToMove)
                {
                    factor = 1f;
                    last   = input;
                    Vector3 checkPoint1 = new Vector2(centerPosition.x + input.x + 0.25f, centerPosition.y + input.y + 0.25f);
                    Vector3 checkPoint2 = new Vector2(centerPosition.x + input.x - 0.25f, centerPosition.y + input.y - 0.25f);
                    lookDirection = MoveScripts.GetDirectionFromVector2(input);
                    hits          = Physics2D.OverlapAreaAll(checkPoint1, checkPoint2);

                    moveDetection.StartDetection(hits, lookDirection);

                    if (moveDetection.CanPhysicallyMove())
                    {
                        bool cancelMove = false;
                        if (moveDetection.inCutscene)
                        {
                            sr.battleSetup.StartCutscene(new PackedCutscene(moveDetection.cutsceneObject.GetComponent <Cutscene>()));
                        }
                        if (moveDetection.inDoor)
                        {
                            if (moveDetection.doorObject.GetComponent <DoorToLocation>().GetTargetScene() != null)
                            {
                                if (moveDetection.doorObject.GetComponent <DoorToLocation>().fadeOutOnTransition)
                                {
                                    sr.canvasCollection.OpenState(CanvasCollection.UIState.SceneSwitch);
                                }
                            }
                            else
                            {
                                cancelMove = true;
                            }
                        }
                        SetFacingDirection(input);

                        if (!cancelMove)
                        {
                            if (sr.battleSetup.runButtonHeld)
                            {
                                moveSpeedCurrent = moveSpeed * moveSpeedModifier;
                            }
                            else
                            {
                                moveSpeedCurrent = moveSpeed;
                            }
                            StartCoroutine(move(transform));
                        }
                    }
                }
                SetWalkAnimation();
            }
            break;

        case LogicType.Trainer:
            if (!isMoving)
            {
                input = MoveScripts.GetVector2FromDirection(lookDirection);

                animMoving = false;
                last       = input;

                if (input != Vector2.zero && ableToMove)
                {
                    factor = 1f;

                    checkPoint    = new Vector2(centerPosition.x + input.x, centerPosition.y + input.y);
                    lookDirection = MoveScripts.GetDirectionFromVector2(input);
                    hits          = Physics2D.OverlapAreaAll(checkPoint, checkPoint);
                    moveDetection.StartDetection(hits, lookDirection);

                    if (moveDetection.CanPhysicallyMove())
                    {
                        SetFacingDirection(input);
                        StartCoroutine(move(transform));
                    }
                    else
                    {
                        npcMove = false;
                        tLogic.sr.battleSetup.AdvanceCutscene();
                    }
                }
                SetWalkAnimation();
            }
            break;

        case LogicType.NPC:
            if (!isMoving)
            {
                input = MoveScripts.GetVector2FromDirection(lookDirection);

                animMoving = false;
                last       = input;
                if (input != Vector2.zero && npcMove)
                {
                    factor = 1f;

                    checkPoint    = new Vector2(centerPosition.x + input.x, centerPosition.y + input.y);
                    lookDirection = MoveScripts.GetDirectionFromVector2(input);
                    hit           = Physics2D.OverlapArea(checkPoint, checkPoint);
                    moveDetection.StartDetection(hits, lookDirection);

                    //MoveScripts.CheckForTag(this.gameObject, hit, "Player")
                    if (moveDetection.CanPhysicallyMove())
                    {
                        SetFacingDirection(input);
                        StartCoroutine(move(transform));
                    }
                }
                SetWalkAnimation();
            }
            break;
        }
    }