Example #1
0
    void checkDirection()
    {
        Vector2 size = GetComponent <BoxCollider2D>().size *transform.lossyScale.x;

        string[]   pathLayers    = { "Path" };
        Collider2D pathCollision = Physics2D.OverlapBox(transform.position, size, 0, LayerMask.GetMask(pathLayers));

        if (pathCollision)
        {
            direction = pathCollision.GetComponent <NPCPath>().direction;
        }

        if (this.GetComponent <Inspector>() == null)
        {
            string[]   actionLayers    = { "Interactable" };
            Collider2D actionCollision = Physics2D.OverlapBox(transform.position, size, 0, LayerMask.GetMask(actionLayers));
            if (actionCollision && actionCollision.GetComponent <SpeechPad>() && actionCollision.GetComponent <SpeechPad>() != currentSpeechPad)
            {
                actionCheckTime = actionTimeNecessary;
                playerSprite.Animate(Vector2.zero);
                int[] validActions = actionCollision.GetComponent <SpeechPad>().validActions;
                speechChoice     = validActions[(int)Random.Range(0, validActions.Length)];
                currentSpeechPad = actionCollision.GetComponent <SpeechPad>();
                GetComponentInChildren <Speech>().Speak(speechChoice);
                if (speechChoice == 0)
                {
                    currentSpeechPad.caller = this.gameObject;
                    currentSpeechPad.Action0();
                }
                if (speechChoice == 1)
                {
                    currentSpeechPad.caller = this.gameObject;
                    currentSpeechPad.Action1();
                }
                if (speechChoice == 2)
                {
                    currentSpeechPad.caller = this.gameObject;
                    currentSpeechPad.Action2();
                }
                if (speechChoice == 3)
                {
                    currentSpeechPad.caller = this.gameObject;
                    currentSpeechPad.Action3();
                }
            }
            //placeholder for gate opener
            else if (actionCollision && actionCollision.name == "GateOpen")
            {
                GameObject.Find("Goal").GetComponent <Goal>().isOpen = true;
            }
        }

        string[]   goalLayers    = { "Goal" };
        Collider2D goalCollision = Physics2D.OverlapBox(transform.position, size, 0, LayerMask.GetMask(goalLayers));

        if (goalCollision && (goalCollision.GetComponent <Goal>().isOpen || hasKey && goalCollision.GetComponent <Goal>().keyDoor))
        {
            goalCollision.gameObject.GetComponent <Goal>().isOpen = false;
            gateObject.GetComponent <Animator>().SetTrigger("gateOpen");
            lockMovement = true;
        }
    }
Example #2
0
    void FixedUpdate()
    {
        if (Input.GetButton("Run"))
        {
            speed = runSpeed;
        }
        else
        {
            speed = walkSpeed;
        }
        if (lockMovement)
        {
            float   moveSpeed = speed * Time.deltaTime;
            Vector3 toMove    = new Vector3(Mathf.Round((moveSpeed * Vector3.up).x), Mathf.Round((moveSpeed * Vector3.up).y));
            gameObject.transform.position += toMove;

            if (!startedFade)
            {
                string[]   despawnLayers    = { "Despawn" };
                Vector2    size             = GetComponent <BoxCollider2D>().size *transform.lossyScale.x;
                Collider2D despawnCollision = Physics2D.OverlapBox(transform.position, size, 0, LayerMask.GetMask(despawnLayers));
                if (despawnCollision)
                {
                    gateObject.GetComponent <Animator>().SetTrigger("gateClose");
                    World.Instance.StartFade(false, World.Instance.GetNextScene(), 0);
                    startedFade = true;
                }
            }
        }
        else
        {
            if (frozen)
            {
                return;
            }

            float   moveSpeed = speed * Time.deltaTime;
            float   horiz     = Input.GetAxisRaw("Horizontal");
            float   vert      = Input.GetAxisRaw("Vertical");
            Vector3 toMove    = new Vector3(horiz * moveSpeed, vert * moveSpeed);

            if (toMove != Vector3.zero)
            {
                moving = true;
            }
            else
            {
                moving = false;
            }
            Move(gameObject, toMove);

            GetComponent <PlayerSprite>().Animate(toMove);

            if (toMove.x == 0 && toMove.y == 0)
            {
                if (walkSound.isPlaying)
                {
                    walkSound.Stop();
                }
            }
            else
            {
                if (!walkSound.isPlaying)
                {
                    walkSound.Play();
                }
            }

            Vector2    size            = GetComponent <BoxCollider2D>().size *transform.lossyScale.x;
            string[]   actionLayers    = { "Interactable" };
            Collider2D actionCollision = Physics2D.OverlapBox(transform.position, size, 0, LayerMask.GetMask(actionLayers));
            if (actionCollision && actionCollision.GetComponent <SpeechPad>())
            {
                currentSpeechPad = actionCollision.GetComponent <SpeechPad>();
            }
            //for gate open (Interactable, but doesn't have a speech pad)
            else if (actionCollision && actionCollision.name == "GateOpen")
            {
                GameObject.Find("Goal").GetComponent <Goal>().isOpen = true;
                currentSpeechPad = null;
            }
            else
            {
                currentSpeechPad = null;
            }
            if (Input.GetButtonDown("Speak1"))
            {
                GetComponentInChildren <Speech>().Speak(0);
                if (currentSpeechPad)
                {
                    currentSpeechPad.caller = this.gameObject;
                    currentSpeechPad.Action0();
                }
            }
            if (Input.GetButtonDown("Speak2"))
            {
                GetComponentInChildren <Speech>().Speak(1);
                if (currentSpeechPad)
                {
                    currentSpeechPad.caller = this.gameObject;
                    currentSpeechPad.Action1();
                }
            }
            if (Input.GetButtonDown("Speak3"))
            {
                GetComponentInChildren <Speech>().Speak(2);
                if (currentSpeechPad)
                {
                    currentSpeechPad.caller = this.gameObject;
                    currentSpeechPad.Action2();
                }
            }
            if (Input.GetButtonDown("Speak4"))
            {
                GetComponentInChildren <Speech>().Speak(3);
                if (currentSpeechPad)
                {
                    currentSpeechPad.caller = this.gameObject;
                    currentSpeechPad.Action3();
                }
            }

            /*
             * if (Input.GetKeyDown("1")) playerSprite.playerColor = PlayerSprite.PlayerColor.Black;
             * if (Input.GetKeyDown("2")) playerSprite.playerColor = PlayerSprite.PlayerColor.Blue;
             * if (Input.GetKeyDown("3")) playerSprite.playerColor = PlayerSprite.PlayerColor.Red;
             */

            if (Physics2D.OverlapBox(transform.position, size, 0, LayerMask.GetMask(new string[] { "Death" })))
            {
                if (timeOutOfLine == 0)
                {
                    World.Instance.PlaySound(World.Clip.Exclamation);
                }
                timeOutOfLine += Time.deltaTime;
                if (timeOutOfLine > timeUntilCaught)
                {
                    World.Instance.Freeze();
                }
                float exValue = timeOutOfLine / timeUntilCaught;
                foreach (Collider2D collider in Physics2D.OverlapCircleAll(transform.position, size.x * 7, LayerMask.GetMask(new string[] { "NPC" })))
                {
                    ExclamationPoint ex = collider.GetComponentInChildren <ExclamationPoint>();
                    ex.SetStatus(true, exValue);
                }
                exclamation.SetStatus(true, exValue);
            }
            else if (Physics2D.OverlapBox(transform.position, size, 0, LayerMask.GetMask(new string[] { "MoveDeath" })) && moving)
            {
                exclamation.SetStatus(true, 1);
                World.Instance.Freeze();
            }
            else
            {
                if (timeOutOfLine != 0)
                {
                    // Remove all exclamation points
                    foreach (ExclamationPoint ex in FindObjectsOfType <ExclamationPoint>())
                    {
                        ex.SetStatus(false, 0);
                    }
                }

                timeOutOfLine = 0;
            }

            goalCheck();

            if (Input.GetKeyDown(KeyCode.R))
            {
                frozen = true;
                walkSound.Stop();
                World.Instance.StartFade(true, 0, 0);
            }

            // Sacrifice trigger
            if (Physics2D.OverlapBox(transform.position, size, 0, LayerMask.GetMask(new string[] { "SacrificeTrigger" })))
            {
                gameObject.AddComponent <Sacrifice>();
                frozen = true;
                playerSprite.Animate(Vector2.zero);
                walkSound.Stop();
                World.Instance.PlaySound(World.Clip.Sacrifice);
                World.Instance.StartFade(false, World.Instance.GetTitleScene(), 6.0f);
            }
        }
    }