Example #1
0
    void idle()
    {
        if (CONTROLS_IS_ON && (curForm == 1 || actionPointsLeft + 1 > 0))
        {
            resetPointer();

            RaycastHit hit;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100, layerMask))
            {
                Vector3 hitPoint = hit.point;

                //the direction of the destination according to the player(used for showing the pointer)
                Vector3 heading = hitPoint - spawnedForms[curForm].transform.position;
                float distance = heading.magnitude;
                Vector3 direction = heading / distance;

                RaycastHit hitt;
                if (Physics.Raycast(spawnedForms[curForm].transform.position, heading, out hitt, distance))
                {
                    if (hitt.transform.gameObject.layer != LayerMask.NameToLayer("Walkable"))
                    {
                        //hitPoint = hitt.point;
                        //Debug.Log("hitpoint changed!!");
                    }
                }

                //end point of line shown (also destination of the player movement)
                lineEndPos = hitPoint;

                //distance from point to player

                pointerDistance = Mathf.FloorToInt(Vector3.Distance(spawnedForms[curForm].transform.position, hitPoint) / moveSpeed);

                if (curForm != 1)
                {
                    if (pointerDistance > actionPointsLeft) //don't move more than action points left
                    {
                        pointerDistance = actionPointsLeft;
                        lineEndPos = spawnedForms[curForm].transform.position + (direction * ((pointerDistance + 1) * moveSpeed));
                    }
                }
                //show actionpoints used if desiding to move
                //pointerAPIndic.text = "" + (pointerDistance + 1);

                //Debug.Log("yyy:" + ((pointerDistance + 1) / (float)(maxActionPoints + 1)));
                pointerAPLeftIndic.fillAmount = ((actionPointsLeft + 1) / (float)(maxActionPoints + 1));

                pointerAPIndic.fillAmount = ((pointerDistance + 1) / (float)(maxActionPoints + 1));

                //pointerAPIndic.fillAmount = (((actionPointsLeft + 1) / (float)(maxActionPoints + 1)) - ((pointerDistance-1) / (float)(actionPointsLeft + 1)));
                //pointerText.transform.LookAt(Camera.main.transform.position);
                //

                //added by pablo

                elapsed += Time.deltaTime;
                if (elapsed > 0.01f)
                {
                    elapsed = 0f ;
                    NavMesh.CalculatePath(spawnedForms[curForm].transform.position, lineEndPos, NavMesh.AllAreas, path);

                    //resize line renderer
                    pointerLine.SetVertexCount(path.corners.Length);

                    for (int i = 0; i < path.corners.Length ; i++)
                    {

                        pointerLine.SetPosition(i , path.corners[i]);

                    }

                }

                    //Debug.DrawLine(path.corners[i], path.corners[i + 1], Color.red);

                //set pointer line end pos
                //Debug.Log(path.corners.Length);
                //if (path.corners.Length > 1)
                //{
                //    //pointerLine.SetPosition(path.corners.Length - 1, lineEndPos);
                //}

                //set position of "pointer"

                //fix bug of super trip

                pointerDistance = Mathf.FloorToInt( PathLength(path) / moveSpeed);

                if (curForm != 1)
                {
                    if (pointerDistance > actionPointsLeft) //don't move more than action points left
                    {
                        pointerAPIndic.fillAmount = 0;
                        //pointerText.text = "";
                        pointerLine.SetVertexCount(0);
                        pointerDistance = 0;
                        lineEndPos = spawnedForms[curForm].transform.position;
                    }
                }

                pointer.position = spawnedForms[curForm].transform.position + (direction * (pointerDistance * moveSpeed));

                //pointer.rotation = hit.transform.rotation;

                if (path.corners.Length - 1 > 0)
                {
                    pointer.position = path.corners[path.corners.Length - 1];

                    if (!pointerRenderer.enabled)
                    {
                        pointerRenderer.enabled = true;
                    }
                    if (!pointerAPIndic.enabled)
                    {
                        pointerAPIndic.enabled = true;

                    }
                    if (!pointerAPLeftIndic.enabled)
                    {
                        pointerAPLeftIndic.enabled = true;

                    }
                }
                else
                {
                    if (pointerRenderer.enabled)
                    {
                        pointerRenderer.enabled = false;
                    }
                    if (pointerAPIndic.enabled)
                    {
                        pointerAPIndic.enabled = false;
                    }
                    if (pointerAPLeftIndic.enabled)
                    {
                        pointerAPLeftIndic.enabled = false;

                    }
                }

            }
            if(blockMovement1Frame){

                blockMovement1Frame = false;

            }

            else if (Input.GetMouseButtonUp(0) && Vector3.Distance(spawnedForms[curForm].transform.position, lineEndPos) > 2 && path.corners.Length > 0)
            {
                //Debug.Log("click to move");
                AudioManager.PlayClip(playerWalkSound);
                curAgent.Resume();
                curAgent.SetDestination(lineEndPos);
                curAnimator.SetBool("move", true);
                pointerLine.gameObject.SetActive(false);
                pointerAPIndic.gameObject.SetActive(false);
                pointerAPLeftIndic.gameObject.SetActive(false);
                pointer.gameObject.SetActive(false);

                if (curForm != 1)
                {
                    actionPointsLeft -= pointerDistance + 1;
                }

                pointerDistance = 0;
                state = formState.move;

                camFocus.TargetToFollow = spawnedForms[curForm].transform;
            }
        }
        else {
            if (CONTROLS_IS_ON)
            {
                //Debug.Log("no more points left");
                gamemaster.endTurnBtnClicked();
            }
            else
            {
                resetPointer();
            }
        }
    }
Example #2
0
    void move()
    {
        if (!CONTROLS_IS_ON)
        {
            actionPointsLeft += (Mathf.FloorToInt(curAgent.remainingDistance) / moveSpeed) + 1;

            curAgent.SetDestination(curAgent.transform.position);
            curAgent.Stop();
            curAnimator.SetBool("move", false);
            camFocus.TargetToFollow = null;
            resetPointer();
            state = formState.idle;
        }
        else
        {
            if (curAgent.remainingDistance < 0.1F)
            {
                curAgent.SetDestination(curAgent.transform.position);
                curAgent.Stop();
                curAnimator.SetBool("move", false);
                camFocus.TargetToFollow = null;
                resetPointer();
                state = formState.idle;
            }

            if (Vector3.Distance(curFormLoc, spawnedForms[curForm].transform.position) < 1)
            {
                if (curUnstuckWait <= 0)
                {
                    curUnstuckWait = unstuckWait;
                    curAgent.SetDestination(curAgent.transform.position);
                    curAgent.Stop();
                    curAnimator.SetBool("move", false);
                    camFocus.TargetToFollow = null;
                    resetPointer();
                    state = formState.idle;
                }
                else
                {
                    curUnstuckWait--;
                }
            }
            else
            {
                if (curUnstuckWait != unstuckWait)
                {
                    curUnstuckWait = unstuckWait;
                }
                curFormLoc = spawnedForms[curForm].transform.position;
            }
        }
    }
Example #3
0
    void formBtnClicked(int formID)
    {
        if (state != formState.move)
        {
            blockMovement1Frame = true;
            //Debug.Log("UI BUTTON CLICKED");
            if (gamemaster.curTurn == GameMaster.turns.player)
            {
                state = formState.idle;

                if (spawnedForms.Length > formID && spawnedForms[formID] != null)
                {
                    curForm = formID;
                    curAgent = spawnedForms[curForm].GetComponent<NavMeshAgent>();
                    curAnimator = spawnedForms[curForm].GetComponent<Animator>();
                    pointerLine.SetPosition(0, spawnedForms[curForm].transform.position);

                    AudioManager.PlayClip(AudioManager.Instance.mouseclick);
                    if (formID == 0)
                    {
                        pointerLine.GetComponent<LineRenderer>().material.color = physLineColor;
                        camFocus.GoTo("PhysicalForm");
                        //Debug.Log("show real world*******************************************************");
                        gamemaster.ui.Flash.FlashIt(Color.white);
                        //textureHiderManager.ShowPhysicalWorld();
                        Camera.main.GetComponent<CameraShaderManager>().RemoveDigital();
                    }

                    if (formID == 1)
                    {
                        pointerLine.GetComponent<LineRenderer>().material.color = digiLineColor;
                        camFocus.GoTo("DigitalForm(Clone)");
                        //Debug.Log("show internet world*****************************************************");
                        gamemaster.ui.Flash.FlashIt(Color.blue);
                        Camera.main.GetComponent<CameraShaderManager>().SetDigital();

                        //textureHiderManager.HidePhysicalWorld();
                    }

                }
                else if (!isSplitted)
                {
                    if (formID == 1)
                    {
                        TryToSpawnDigital();
                    }
                }
            }
            AudioManager.HandleBackgroundMusic();
        }
    }