Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        //print(GamePlayState);
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (ProgramMode == Program_Mode.MENU)
            {
                ProgramMode = Program_Mode.GAME;
            }
            else if (ProgramMode == Program_Mode.GAME)
            {
                ProgramMode = Program_Mode.MENU;
            }
        }

        if (Input.GetKeyDown(KeyCode.Return))
        {
            if (ProgramMode == Program_Mode.START_SCREEN)
            {
                ProgramMode = Program_Mode.GAME;
                ELEKTRICITY.Play();
            }

            StartCoroutine(DoorOpenEffect());
        }


        if (Input.GetKeyDown(KeyCode.Escape) && ProgramMode == Program_Mode.START_SCREEN)
        {
            Application.Quit(0);
        }


        if (ProgramMode == Program_Mode.START_SCREEN)
        {
            for (u32 Index = 0;
                 Index < StartScreenItems.Length;
                 ++Index)
            {
                StartScreenItems[Index].SetActive(true);
            }
            ThePlayer.SetActive(false);
        }
        else
        {
            for (u32 Index = 0;
                 Index < StartScreenItems.Length;
                 ++Index)
            {
                StartScreenItems[Index].SetActive(false);
            }
            ThePlayer.SetActive(true);
        }

        v3 PlayerPosition = ThePlayer.transform.position; // TODO(@rudra): Every frame?

        if (Rectangle.IsInRectangle(CSG_Room1.GetRect(), PlayerPosition))
        {
            CurrentPlayerRoom = PLAYER_CURRENT_ROOM.ROOM_1;
        }

        if (Rectangle.IsInRectangle(CSG_Room2.GetRect(), PlayerPosition))
        {
            CurrentPlayerRoom = PLAYER_CURRENT_ROOM.ROOM_2;
        }

        if (Rectangle.IsInRectangle(CSG_Room3.GetRect(), PlayerPosition))
        {
            CurrentPlayerRoom = PLAYER_CURRENT_ROOM.ROOM_3;

            if (GamePlayState == GAMEPLAY_STATE.RIGHT_DOOR_OPENED)
            {
                GamePlayState            = GAMEPLAY_STATE.START_CRAZINESS;
                Human.transform.rotation = Quaternion.Euler(0.0f, 25.0f, 0.0f);
                Camera.IncreaseVHSVerticalOffset(0.04f);

                VCR_Target_Volume = 9.0f;
                T = 0.0f;
#if IGNORED
                f32 CurrentPlayTime = GM_AudioSource.time;

                GM_AudioSource.clip = VCR_Mid;
                GM_AudioSource.loop = true;
                GM_AudioSource.Play();
                GM_AudioSource.time = CurrentPlayTime;
#endif
            }
        }


        if (CurrentPlayerRoom == PLAYER_CURRENT_ROOM.ROOM_2 && DoorState == DOOR_STATE.DOOR_OPEN && GamePlayState == GAMEPLAY_STATE.INIT)
        {
            CloseDoor();

            StartCoroutine(ActivateCoffins());
            //StartCoroutine(OpenDoorWhenCollected());
        }


        if (CurrentPlayerRoom == PLAYER_CURRENT_ROOM.ROOM_2 && DoorState == DOOR_STATE.DOOR_OPEN && GamePlayState == GAMEPLAY_STATE.READ_FOURTH_NOTE)
        {
            CloseDoor();
            GamePlayState = GAMEPLAY_STATE.LEVER_SEQUENCE;
            StartCoroutine(WaitAndStartCoffinsAndInitLever());
        }

        if (CurrentPlayerRoom == PLAYER_CURRENT_ROOM.ROOM_1 && DoorState == DOOR_STATE.DOOR_OPEN && GamePlayState == GAMEPLAY_STATE.FIRST_COLLECTED)
        {
            CloseDoor();
            GamePlayState = GAMEPLAY_STATE.WAITING_FOR_NOTES;

            Letter_1.GetComponent <Animation>().Play("SendLetter");
            Human.SetActive(true);
        }

        if (Camera.HitWithRaycast(LetterLayer) && ThePlayer.GetComponent <Player>().CollidedWithLetter)
        {
            Animation LetterAnimation = Camera.LookingAt.transform.parent.gameObject.GetComponent <Animation>();
            if (LetterAnimation.isPlaying)
            {
            }
            else
            {
                if (ReadingState == READING_STATE.NONE)
                {
                    ReadingState = READING_STATE.CAN_READ;
                }
            }
        }
        else
        {
            ReadingState = READING_STATE.NONE;
        }

        EKeyProcessed = false;

        if (ReadingState == READING_STATE.READING && Input.GetKeyDown(KeyCode.E))
        {
            EKeyProcessed = true;
            ReadingState  = READING_STATE.CAN_READ;

            Letter _L = Camera.LookingAt.GetComponent <Letter>();
            if (_L.LetterTag == Letter.Tag.FIRST)
            {
                if (GamePlayState == GAMEPLAY_STATE.WAITING_FOR_NOTES)
                {
                    GamePlayState = GAMEPLAY_STATE.READ_FIRST_NOTE;
                    Letter_1.transform.position = Letter_1_Table_Position.position;

                    GamePlayState = GAMEPLAY_STATE.SECOND_NOTE_SENT;
                    Letter_2.GetComponent <Animation>().Play("SendLetter");
                }
            }
            else if (_L.LetterTag == Letter.Tag.SECOND)
            {
                if (GamePlayState == GAMEPLAY_STATE.SECOND_NOTE_SENT)
                {
                    GamePlayState = GAMEPLAY_STATE.READ_SECOND_NOTE;
                    Letter_2.transform.position = Letter_2_Table_Position.position;

                    GamePlayState = GAMEPLAY_STATE.THIRD_NOTE_SENT;
                    Letter_3.GetComponent <Animation>().Play("SendLetter");
                }
            }
            else if (_L.LetterTag == Letter.Tag.THIRD)
            {
                if (GamePlayState == GAMEPLAY_STATE.THIRD_NOTE_SENT)
                {
                    GamePlayState = GAMEPLAY_STATE.READ_THIRD_NOTE;
                    Letter_3.transform.position = Letter_3_Table_Position.position;

                    GamePlayState = GAMEPLAY_STATE.FOURTH_NOTE_SENT;
                    Letter_4.GetComponent <Animation>().Play("SendLetter");
                }
            }
            else if (_L.LetterTag == Letter.Tag.FOURTH)
            {
                if (GamePlayState == GAMEPLAY_STATE.FOURTH_NOTE_SENT)
                {
                    GamePlayState = GAMEPLAY_STATE.READ_FOURTH_NOTE;
                    Letter_4.transform.position = Letter_4_Table_Position.position;

                    StartCoroutine(OpenDoorAndEnableLever());
                }
            }
            else
            {
                // NOTE(@rudra): Case for notes on the other side
                OtherNotesProgressHash = OtherNotesProgressHash | 1 << (i32)_L.LetterTag;
                if (OtherNotesProgressHash == GameCompleteHash)
                {
                    StartCoroutine(FinishingSequence());
                }
            }
        }


        if (ReadingState == READING_STATE.CAN_READ && Input.GetKeyDown(KeyCode.E) && !EKeyProcessed)
        {
            EKeyProcessed = true;
            ReadingState  = READING_STATE.READING;
        }

        ReadingBackground.SetActive(ReadingState == READING_STATE.READING);


        // NOTE(@rudra): Lever
        if (Camera.HitWithRaycast(LeverLayer) && ThePlayer.GetComponent <Player>().CollidedWithLever)
        {
            if (LeverState != LEVER_STATE.LEVER_ON)
            {
                LeverState = LEVER_STATE.LEVER_CAN_ACCESS;
            }
        }
        else
        {
            if (LeverState != LEVER_STATE.LEVER_ON)
            {
                LeverState = LEVER_STATE.LEVER_CANNOT_ACCESS;
            }
        }


        // NOTE(@rudra): Interact text
        if (ReadingState == READING_STATE.CAN_READ || LeverState == LEVER_STATE.LEVER_CAN_ACCESS)
        {
            InteractText.text = "E";
        }
        else
        {
            InteractText.text = "";
        }

        LetterText.text = "";
        if (ReadingState == READING_STATE.READING)
        {
            Letter _L = Camera.LookingAt.GetComponent <Letter>();
            if (_L != null)
            {
                LetterText.text = _L.Contents;
            }
        }

        // NOTE(@rudra): Handle Lever
        if (LeverState == LEVER_STATE.LEVER_CAN_ACCESS && Input.GetKeyDown(KeyCode.E))
        {
            LeverState = LEVER_STATE.LEVER_ON;
            Lever.GetComponent <Animation>().Play("LeverOn");

            StartCoroutine(LightOffSequence());
        }

        // NOTE(@rudra): Right door opening sequence
        if (GamePlayState == GAMEPLAY_STATE.LEVER_ACTIVATED)
        {
            f32 SqDistanceFromPlayer = DistanceSq(RightDoor.transform.position, ThePlayer.transform.position);

            if (SqDistanceFromPlayer <= 30.0f)
            {
                GamePlayState = GAMEPLAY_STATE.RIGHT_DOOR_OPENED;
                RightDoorPivot.GetComponent <Animation>().Play("RightDoorOpen");

                AudioSource RightDoorAudio = RightDoor.GetComponent <AudioSource>();
                RightDoorAudio.clip = RightDoorOpen;
                RightDoorAudio.Play();
            }
        }

        // NOTE(@rudra): Ending sequence
        if (CurrentPlayerRoom == PLAYER_CURRENT_ROOM.ROOM_3)
        {
        }

        GameMixer.GetFloat("GM_Volume", out VCR_Current_Volume);
        VCR_Current_Volume = Mathf.Lerp(VCR_Current_Volume, VCR_Target_Volume, T);
        GameMixer.SetFloat("GM_Volume", VCR_Current_Volume);
        T += 1.0f * Time.deltaTime;

        // NOTE(@rudra): Coffin sequence
        if (FirstCoffinActivated)
        {
            f32 SqDistanceFromPlayer = DistanceSq(FirstCoffinLight.transform.position, ThePlayer.transform.position);
            if (SqDistanceFromPlayer <= CoffinMinDistance)
            {
                StartCoroutine(WaitAndActivateSecondCoffin());
            }
        }
        if (SecondCoffinActivated)
        {
            f32 SqDistanceFromPlayer = DistanceSq(SecondCoffinLight.transform.position, ThePlayer.transform.position);
            if (SqDistanceFromPlayer <= CoffinMinDistance)
            {
                StartCoroutine(WaitAndActivateThirdCoffin());
            }
        }
        if (ThirdCoffinActivated && !StartedAlready)
        {
            f32 SqDistanceFromPlayer = DistanceSq(ThirdCoffinLight.transform.position, ThePlayer.transform.position);
            if (SqDistanceFromPlayer <= CoffinMinDistance)
            {
                StartCoroutine(WaitAndActivateOpenDoor());
            }
        }
    }