Ejemplo n.º 1
0
    public IEnumerator AppearAfter(float time, string dialogueText = "", float x = 3, float y = -3)
    {
        // Wait for an amount of time before appearing and displaying next dialogue
        Debug.Log("HERE!");
        yield return(new WaitForSeconds(time));

        Debug.Log("WHOO HOO");
        //Make sure all the dialogue is reset...
        textObjectScript.currentTextObjectName = "";
        textObjectScript.optionTree            = "";
        textObjectScript.hasNextOption         = false;
        textObjectScript.hasNextPage           = false;
        textObjectScript.virtualActivation     = false;
        textObjectScript.notOption             = true;
        textObjectScript.currentPage           = 0;
        textObjectScript.DisplayDialog();
        //Turn them back on with new dialogue!
        textObjectScript.virtualActivationFuntion(dialogueText, playerObject.transform.position);
        demonKingRigidbody2D.MovePosition(new Vector2(x, y));
        yield return(new WaitForSeconds(0.1f));

        demonKingRigidbody2D.constraints = RigidbodyConstraints2D.FreezeAll;
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        checkAudioListeners();

        //MOVEMENT
        //Debug.Log(horizontal.ToString());
        //Debug.Log(Input.GetAxis("Horizontal").ToString());

        //Debug.Log("Game Controller Text: " + gameControllerObject.currentText);
        //Debug.Log("Text Object Text: " + textObjectScript.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text);
        //Debug.Log(Input.mouseScrollDelta.y);

        //Debug.Log("Current Selected Item: " + currentSelectedItem);

        //Debug.Log("GameController Player: " + gameControllerObject.player);
        //Debug.Log("GameController PlayerObject: " + gameControllerObject.playerObject);
        if (horizontal > 0 && Input.GetAxis("Horizontal") >= horizontal)
        {
            horizontal = 1;
        }
        else if (horizontal < 0 && Input.GetAxis("Horizontal") <= horizontal)
        {
            horizontal = -1;
        }
        else
        {
            horizontal = 0;
        }

        if (vertical > 0 && Input.GetAxis("Vertical") >= vertical)
        {
            vertical = 1;
        }
        else if (vertical < 0 && Input.GetAxis("Vertical") <= vertical)
        {
            vertical = -1;
        }
        else
        {
            vertical = 0;
        }

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);

        //Don't update movement variables during scene transition
        if (!inTransition & !lockedMovement)
        {
            Vector2 position = rigidBody2D.position;
            position += move * speed * Time.deltaTime;
            rigidBody2D.MovePosition(position);
            animator.SetFloat("Speed", move.magnitude);

            //Foot Steps Audio
            if (move.x != 0 || move.y != 0)
            {
                footSteps.GetComponent <AudioSource>().volume = 0.25f;
            }
            else
            {
                footSteps.GetComponent <AudioSource>().volume = 0;
            }
        }
        else
        {
            //Debug.Log("Not Moving  " + "In transition: " + inTransition + lockedMovement);
            footSteps.GetComponent <AudioSource>().volume = 0;
        }

        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        //RAYCAST
        //Check If Raycast hit anything when "X" is pressed, if yes turn on the dialog OR if mouse left click is pressed, change the dialogue page
        if (Input.GetKeyDown(KeyCode.X) && textBox.activeSelf == false || Input.GetKeyDown(KeyCode.Mouse0) && textBox.activeSelf == true)
        {
            if (Input.GetKeyDown(KeyCode.Mouse0) && textObjectScript.virtualActivation && textObjectScript.notOption)
            {
                textObjectScript.interactablePos = gameObject.transform.position;
                textObjectScript.DisplayDialog();
            }
            else
            {
                RaycastHit2D hit = Physics2D.Raycast(rigidBody2D.position + Vector2.up * 0.2f, lookDirection, raycastDistance, LayerMask.GetMask("NonPlayerCharacter"));

                if (hit.collider != null)
                {
                    hitObject = hit.collider.gameObject;
                    //Debug.Log("hit.collider.gameObject.name:" + hit.collider.gameObject.name + " textObjectScript.notOption:" + textObjectScript.notOption);

                    if (hitObject.CompareTag("TextInteract") && textObjectScript.notOption)
                    {
                        // REVIEW LATER "if (textObjectScript.hasNextPage == false)" AND "else if (!textObjectScript.hasNextPage)"
                        textObjectScript.interactablePos       = gameObject.transform.position;
                        textObjectScript.currentTextObjectName = hit.collider.name;
                        textObjectScript.DisplayDialog();
                    }

                    if (hitObject.CompareTag("SceneTransitionInteract"))
                    {
                        //Get the name of the scene
                        if (hitObject.name == "CabinetWithKey")
                        {
                            nextScene = "KeyPuzzle";
                        }

                        //Call scene transition function (which is a coroutine that allows the code to pause)
                        StartCoroutine(TransitionToScene(nextScene, fadeDuration, timeBeforeFadeIn));
                        nextScene = "";
                    }

                    if (hitObject.CompareTag("ItemInteract"))
                    {
                        checkItemInInventory("CropsPuzzleShed", "Key", "CropsPuzzleShedNoKey", "Bucket Wooden Parts");
                        checkItemInInventory("Lake", "Empty Bucket", "CropsPuzzleLakeNoBucket", "Full Bucket");
                        checkItemInInventory("BadFarm", "Full Bucket", "CropsPuzzleFarmNoBucket", "Empty Bucket", "OldManFarmer2");
                        checkItemInInventory("AllFence", "Sack of Boar Food", "FarmNoPigFood", "", "Pigsties");
                        checkItemInInventory("TownMailbox", "Letter", "TownNoLetter", "", "mailBoxLetterText");
                        checkItemInInventory("Carriage", "Carriage Wheel", "CarriageNoFixPart", "", "carraigeFix");
                    }
                }
            }
        }

        //Increament Item amount
        //if colidded with a new object
        if (currentPickableItem != null)
        {
            //check if dictionary contains this objectS
            if (inventoryAmount.ContainsKey(currentPickableItem.name))
            {
                //increment by 1, and update the inventory display
                inventoryAmount[currentPickableItem.name] += 1;
                InventoryScript.InventoryUpdate();
            }
            else
            {
                //else, add a new one
                inventoryAmount.Add(currentPickableItem.name, 1);
                InventoryScript.InventoryUpdate();
            }
            //if currently no item is selected
            if (currentSelectedItem == "")
            {
                //the current object will be selected
                currentSelectedItem = currentPickableItem.name;
                InventoryScript.InventoryUpdate();
            }
            //destroy the obejct
            currentPickableItem.SetActive(false);
            currentPickableItem = null;
        }

        //Drop Item

        /*if (Input.GetKeyDown(KeyCode.Q))
         * {
         *  //if an item is selected and its amount is not equals to zero
         *  if (currentSelectedItem != "" && inventoryAmount[currentSelectedItem] > 0)
         *  {
         *      //create it, decrese the amount by 1 and update the inventory display
         *      currentDroppedItem = Instantiate(pickableGameObjects[currentSelectedItem], rigidBody2D.position + lookDirection * 1.1f, Quaternion.identity);
         *      currentDroppedItem.name = pickableGameObjects[currentSelectedItem].name;
         *      inventoryAmount[currentDroppedItem.name] -= 1;
         *      Debug.Log(currentSelectedItem);
         *      Debug.Log(inventoryAmount[currentSelectedItem]);
         *      InventoryScript.InventoryUpdate();
         *      Debug.Log(currentSelectedItem);
         *      Debug.Log(inventoryAmount[currentSelectedItem]);
         *  }
         *
         *  if (currentSelectedItem != "" && inventoryAmount[currentSelectedItem] == 0)
         *  {
         *
         *      //Debug.Log(currentSelectedItem);
         *      //Debug.Log(inventoryAmount[currentSelectedItem]);
         *      currentSelectedItem = "";
         *      //InventoryScript.InventoryUpdate();
         *      //Debug.Log(currentSelectedItem);
         *      //Debug.Log("IT's NOTHING");
         *  }
         * }*/

        //change Scene short cut
        changeSceneForTesting();

        //Item UI pop-up
        //MINI MAP
        if (currentSelectedItem == "Map")
        {
            miniMapObjectScript.MiniMap(true);
        }
        else
        {
            miniMapObjectScript.MiniMap(false);
        }

        //Compass
        if (currentSelectedItem == "Compass")
        {
            compassObjectScript.Compass(true);
        }
        else
        {
            compassObjectScript.Compass(false);
        }

        //Torch
        if (currentSelectedItem == "Torch")
        {
            lightScript.pointLightOuterRadius = 8f;
        }
        else
        {
            lightScript.pointLightOuterRadius = 4f;
        }

        //Check distance between Player and Object, if it's more than "raycastLimitDistance"  ALL dialog turn off
        if (textObjectScript.currentTextObjectName != "" && Vector2.Distance(textObjectScript.interactablePos, rigidBody2D.position) > raycastLimitDistance)
        {
            if (textObjectScript.notOption == false)
            {
                for (int i = 1; i <= textObjectScript.optionObject.numOfButtons; i++)
                {
                    Destroy(textObjectScript.optionObject.gameObject.transform.GetChild(i).gameObject);
                }
            }
            textObjectScript.currentTextObjectName = "";
            textObjectScript.optionTree            = "";
            textObjectScript.hasNextOption         = false;
            textObjectScript.hasNextPage           = false;
            textObjectScript.virtualActivation     = false;
            textObjectScript.notOption             = true;
            textObjectScript.currentPage           = 0;
            //Debug.Log("possibility problem 2: " + textState);
            //Debug.Log("Distance over limit: " + Vector2.Distance(textObjectScript.interactablePos, rigidBody2D.position));
            //Debug.Log("Hmmm: " + textState);
            textObjectScript.DisplayDialog();
        }

        //Lock movement during certain dialogues
        lockMovementFunction(textToUnlock: "KING:What is going on? I wonder...\n \n (use W, A, S, D to move)");
        lockMovementFunction("KING: The entire chamber is in ruins!", "Leave, servant.");
        lockMovementFunction("DEMON: HA! Cannot find your dearest princess? Hmmm?", "By the summer solstice. I am waiting.");
        lockMovementFunction("KING: The summer soltace... That is in a week!", "Servant!!");
        lockMovementFunction("PLAYER: This is weird. There is no wall on the map.", "Good choice! Now we can properly play the game.");
        lockMovementFunction("Your Majesty.");
        lockMovementFunction(textToUnlock: "PLAYER: I can't turn back. If I did, there would be no game.");
        lockMovementFunction("DEMON: MUAHAHAHAHAHAHAHAHA!!!!!!!!!!!!!!!\n\nIt is time for your painful undoing!", "MUAHAHAHAHAHAHAHAHA!!!!!!!!!!!!!!!");

        lockMovementDilemma("First question:", "The kingdom is destroyed because of your selfish actions.");
        lockMovementDilemma(textToUnlock: "You dearest is dead because you tried to be so noble!");
        lockMovementDilemma("Your dearest is dying, and you have the power to save her!", "Are you willing to subject your dearest to joyless life");
        lockMovementDilemma(textToUnlock: "Are you willing to subject your dearest to a painful death");
        lockMovementDilemma("You have the power to end all of the world's problems!", "Now the world is going to end!");
        lockMovementDilemma(textToUnlock: "You had the power to make the world a better place and you didn't do it!");
        lockMovementDilemma("You are tied to a tree and you're going to starve to death", "You selfish bastard! That peasant was innocent!");
        lockMovementDilemma(textToUnlock: "Now you're going to die, and leave your dearest to grieve!");


        //Check if it's the dialogue for changing scene
        fadeOnDialogue("Fifty thousand pounds of gold! Now, begone!", "FarmHut", 5f, 2.5f);
        fadeOnDialogue("I’ll leave first thing tomorrow.", "FarmHut", 4f, 2f);
        fadeOnDialogue("Good choice! Now we can properly play the game.", "PushingStonePuzzle", 4f, 2f);
        fadeOnDialogue("PLAYER: I can't turn back. If I did, there would be no game.", "PushingStonePuzzle", 4f, 2f);
        fadeOnDialogue("OLD MAN: Thank you so much! You are free to go now.", "Beach", 5f, 2.5f);
        fadeOnDialogue("Wait here until I return. ", "DiningRoomFinale", 4f, 2f);
        fadeOnDialogue("I will do what I want. That is none of your business. ", "DiningRoomFinale", 4f, 2f);
        fadeOnDialogue("No…", "Sunset", 4f, 2f);
        fadeOnDialogue("What hell have I willingly stepped into?", "EndingTwo", 4f, 2f);


        //Cabinet Letter Change Name
        if (gameControllerObject.currentText == "*Sigh.*")
        {
            gameControllerObject.currentText          = "*Sigh.* ";
            GameObject.Find("CabinetWithLetter").name = "CabinetWithLetterDone";
        }

        if (gameControllerObject.currentText == "GUY: I gotta go now, wish you luck on your journy to rescue the princess")
        {
            gameControllerObject.currentText = "GUY: I gotta go now, wish you luck on your journy to rescue the princess ";
            StartCoroutine(CarriageFade(4f, 2f));
        }

        // Change the quiz box if we've done the question
        if (SceneManager.GetActiveScene().name == "Dilemma")
        {
            ChangeQuizBoxToDone(textObjectScript, "QuizBoxA");
            ChangeQuizBoxToDone(textObjectScript, "QuizBoxB");
            ChangeQuizBoxToDone(textObjectScript, "QuizBoxC");
            ChangeQuizBoxToDone(textObjectScript, "QuizBoxD");
        }

        changeTagOnDialogue("DiningRoom", "DiningTable", "Servant!");
        changeTagOnDialogue("Corridor", "TransitionToScenePrincessChamber", "Follow me, your majesty...", "SceneTransition");
        changeTagOnDialogue("Farm", "Carriage", "A replacement is required.", "ItemInteract");
    }