예제 #1
0
파일: Navigator.cs 프로젝트: Kwing95/kabel
    // Update is called once per frame
    void Update()
    {
        CheckJobs();
        // If destination has been set recently, generate a new path
        // destinationQueued is true when "destination" is outdated and a new path must be generated
        if (destinationQueued)
        {
            Vector2 position = mover.GetDiscretePosition();
            path = Grapher.FindPath(position, destination, maxPathLength);

            if (path.Count > 0 && waypointEnabled)
            {
                Destroy(waypoint);
                waypoint = Instantiate(Globals.WAYPOINT, destination, Quaternion.identity);
            }

            if (path.Count > 1)
            {
                pathProgress = Grapher.ManhattanDistance(path[0], transform.position) == 1 ? 0 : 1;
            }
            destinationQueued = false;

            // If path does not exist, stop trying to navigate there
            if (path.Count == 0)
            {
                if (waypointEnabled)
                {
                    Destroy(waypoint);
                }
                Pause(true);
            }
        }

        if (mover.GetCanTurn() && !pausePathFinding && ActionManager.GetState() == ActionManager.State.Moving)
        {
            // Move along path
            if (path.Count > 1)
            {
                if (pathProgress < path.Count)
                {
                    Vector2 direction = path[pathProgress] - (Vector2)transform.position;

                    //if(pathProgress > 0 && (Vector2)transform.position != path[pathProgress - 1])
                    //    Debug.Log("WARNING: Expected position " + transform.position + " to be " + path[pathProgress - 1]);
                    mover.ChangeDirection(direction, running);
                    pathProgress += 1;

                    GameObject tempNoise = Instantiate(Globals.NOISE, transform.position, Quaternion.identity);
                    tempNoise.GetComponent <Noise>().Initialize(CompareTag("Player"), running ? Globals.RUN_VOLUME : Globals.WALK_VOLUME, Noise.Source.Footsteps); // bad
                }
                else
                {
                    // Upon losing sight of player or reaching waypoint
                    SetIdle(true);
                }
            }
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        float horizontalInput = Input.GetAxis("Horizontal");
        float verticalInput   = Input.GetAxis("Vertical");
        bool  isRunning       = Input.GetButton("Cancel");

        if (CanMove() && mover.GetCanTurn())
        {
            if (Mathf.Abs(horizontalInput) > 0.5f || Mathf.Abs(verticalInput) > 0.5f)
            {
                nav.SetDestination(transform.position + new Vector3(Mathf.Ceil(horizontalInput), Mathf.Ceil(verticalInput)), isRunning);
            }
        }

        if (Input.GetButton("Confirm"))
        {
            if (ActionManager.GetState() == ActionManager.State.Moving && Sidebar.GetCanAttack())
            {
                Sidebar.instance.GetComponent <MenuNavigator>().ShowMenu(1);
                Sidebar.instance.ActionPause(true);
                Sidebar.instance.SetState("ActionPause");
            }
        }

        if (Input.GetButton("Cancel"))
        {
            if (ActionManager.GetState() == ActionManager.State.ActionPause)
            {
            }
        }

        /*
         * if (Time.timeScale == 0)
         *  return;
         *
         * // If raycast is clear, construct a basic path. If not, smart path with maximum distance
         * if (Input.GetMouseButton(0) && initialClick && !ClickHandler.MouseOverUI())
         * {
         *  initialClick = false;
         *
         *  _OnClick(GetMousePosition());
         * }
         *
         * if (!Input.GetMouseButton(0))
         *  initialClick = true;
         */
    }
예제 #3
0
    // Update is called once per frame
    void LateUpdate()
    {
        bool playerIsMoving = subject.GetCanTurn();
        bool isCloseEnough  = Vector2.Distance(transform.position, subject.transform.position + offset) <= closeEnough;
        bool inMoveState    = ActionManager.GetState() == ActionManager.State.Moving;

        if ((playerIsMoving && isCloseEnough) || !inMoveState)
        {
            paused = true;
        }

        if (paused && !playerIsMoving && inMoveState)
        {
            paused = false;
        }

        if (!paused)
        {
            Lerp();
        }
    }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        // If it sees player, run from player
        if (CanSeePoint(PlayerMover.instance.transform.position) && !stuck)
        {
            lastSawPlayer = Grapher.RoundedVector(PlayerMover.instance.transform.position);
            GetHidingPlace(PlayerMover.instance.transform.position);
            //navigator.Hide(PlayerMover.instance.transform.position);
            lookTowardPlayer = true;
            timeAlone        = 0;
        }
        else if (mover.GetCanTurn())
        {
            timeAlone += Time.deltaTime;

            if (timeAlone > flareDelay && !hasFiredFlare)
            {
                Flare();
            }

            if (glanceTimer > 0)
            {
                glanceTimer -= Time.deltaTime;
            }
            else
            {
                if (lookTowardPlayer)
                {
                    rotator.FacePoint(lastSawPlayer);
                }
                else
                {
                    rotator.Rotate(Random.Range(0, 360));
                }

                lookTowardPlayer = !lookTowardPlayer;
                glanceTimer      = glanceLength;
            }
        }
    }
예제 #5
0
    // Update is called once per frame
    void Update()
    {
        if (stunCounter > 0)
        {
            stunCounter -= Time.deltaTime;
            return;
        }
        else if (confusedStun || courtesyStun)
        {
            if (confusedStun)
            {
                destination = savedDestination;
            }
            if (courtesyStun)
            {
                SetChasing(true);
            }
            confusedStun = false;
            courtesyStun = false;
        }

        float distanceToPlayer = Vector2.Distance(transform.position, player.GetDiscretePosition());

        if (TouchingPlayer())
        {
            SetChasing(true);
            SetDestination(player.transform.position, true);

            if (!player.gameObject.GetComponent <Flasher>().IsFlashing())
            {
                //player.gameObject.GetComponent<ParticleSystem>().Play();
                Camera.main.GetComponent <Jerk>().Shake(1);
                source.PlayOneShot(punch);
                player.gameObject.GetComponent <Flasher>().Flash(1);
                player.gameObject.GetComponent <Health>().TakeDamage();
            }
        }

        if (!chasing)
        {
            destination = route[routeProgress % route.Count];
            if (Vector2.Distance(transform.position, destination) == 0)
            {
                ++routeProgress;
                if (route.Count == 1 && !chasing)
                {
                    GetComponent <Rotator>().Rotate(startAngle);
                }
            }
        }

        if (mover.GetCanTurn() && (distanceToPlayer > 1 || !chasing))
        {
            graph = MakeGraph(transform.position);
            List <int> path = FindPath(VectorToIndex(destination));
            if (path.Count > 1)
            {
                int     nextTileIndex = path[1];
                Vector2 nextTile      = graph[nextTileIndex];
                Vector2 hereToThere   = nextTile - (Vector2)transform.position;
                mover.ChangeDirection(hereToThere);
            }
            else
            {
                if (chasing)
                {
                    crossInstance.GetComponent <SpriteRenderer>().enabled = false;
                    ConfuseStun(2);
                }
                SetChasing(false);
                destination = route[routeProgress % route.Count];
            }
        }
    }