Example #1
0
    // Update is called once per frame

    protected void Update()
    {
        if (sacrificed)
        {
            return;
        }

        Vector2 size = GetComponent <BoxCollider2D>().size *transform.lossyScale.x;

        if (!lockMovement)
        {
            moveSpeed = speed * Time.deltaTime;
            if (BellStop.bellActive)
            {
                playerSprite.Animate(Vector2.zero);
            }
            else
            {
                playerSprite = GetComponent <PlayerSprite>();
                checkMovement();
                checkDirection();
            }
        }
        else
        {
            float   moveSpeed = 300f * Time.deltaTime;
            Vector3 toMove    = new Vector3(Mathf.Round((moveSpeed * Vector3.up).x), Mathf.Round((moveSpeed * Vector3.up).y));
            gameObject.transform.position += toMove;
            string[]   despawnLayers    = { "Despawn" };
            Collider2D despawnCollision = Physics2D.OverlapBox(transform.position, size, 0, LayerMask.GetMask(despawnLayers));
            if (despawnCollision)
            {
                gateObject.GetComponent <Animator>().SetTrigger("gateClose");
                Destroy(this.gameObject);
            }
        }

        // Sacrifice trigger
        if (!sacrificed && Physics2D.OverlapBox(transform.position, size, 0, LayerMask.GetMask(new string[] { "SacrificeTrigger" })))
        {
            gameObject.AddComponent <Sacrifice>();
            sacrificed = true;
            playerSprite.Animate(Vector2.zero);
            World.Instance.PlaySound(World.Clip.Sacrifice);
        }
    }
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);
            }
        }
    }