예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (this.preMovementTimePassed > 0.0f)
        {
            this.preMovementTimePassed -= Time.deltaTime;
            return;
        }

        if (this.timeTillStart > 0.0f)
        {
            this.timeTillStart -= Time.deltaTime;

            // make camera lerp
            float   cameraXPosition = Mathf.SmoothStep(this.cameraStartLerpPosition.x, this.initialCameraPosition.x, this.timePassed / this.startTime);
            Vector3 cameraPosition  = new Vector3(cameraXPosition, this.camera.transform.position.y, this.camera.transform.position.z);
            //Vector3 cameraPosition = Vector3.Lerp (this.cameraStartLerpPosition, this.initialCameraPosition, this.timePassed / this.startTime);
            this.camera.transform.position = cameraPosition;

            //float cameraAngle = Mathf.Lerp (0.0f, this.cameraInitialAngle, this.timePassed / this.startTime);
            float cameraAngle = Mathf.SmoothStep(0.0f, this.cameraInitialAngle, this.timePassed / this.startTime);

            this.camera.transform.rotation = Quaternion.Euler(cameraAngle, this.camera.transform.rotation.eulerAngles.y, this.camera.transform.rotation.eulerAngles.z);


            this.timePassed += Time.deltaTime;

            return;
        }
        else
        {
            if (this.adjustedCameraOnce == false)
            {
                // do only once
                this.camera.transform.position = this.initialCameraPosition;
                this.camera.transform.rotation = Quaternion.Euler(this.cameraInitialAngle, this.camera.transform.rotation.eulerAngles.y, this.camera.transform.rotation.eulerAngles.z);
                this.adjustedCameraOnce        = true;
            }
        }


        // decrease times
        this.speedTimeRemaining -= Time.deltaTime;
        this.cakeTimeRemaining  -= Time.deltaTime;


        // set which keys should move the player left/right
        string leftKey       = "j";
        string rightKey      = "l";
        string prostituteKey = "u";
        string fatKey        = "o";
        string cakeKey       = "i";

        if (this.playerNumber == PlayerNumber.Player1)
        {
            leftKey       = "a";
            rightKey      = "d";
            prostituteKey = "q";
            fatKey        = "e";
            cakeKey       = "w";
        }

        //Debug.DrawRay(this.transform.position, this.transform.forward * 5.0f, Color.magenta, 5.0f);
        //Debug.DrawRay(this.transform.position, this.transform.forward * (-1), Color.magenta, 20, true);

        // check for keyboard events to update current lane
        if (Input.GetKeyDown(leftKey))
        {
            // check if the left side is free
            RaycastHit hit;
            bool       allowLaneChange = true;
            if (Physics.Raycast(this.transform.position, this.transform.forward * (-1), out hit, 5.0f))
            {
                if (hit.collider.CompareTag("Player"))
                {
                    // player was hit, so don't allow change of lane
                    allowLaneChange = false;
                }
            }

            if (allowLaneChange)
            {
                // left arrow key was pressed
                if (this.lane == Lane.Middle)
                {
                    this.lane = Lane.Left;
                }
                if (this.lane == Lane.Right)
                {
                    this.lane = Lane.Middle;
                }
            }
        }

        if (Input.GetKeyDown(rightKey))
        {
            // check if the right side is free
            RaycastHit hit;
            bool       allowLaneChange = true;
            if (Physics.Raycast(this.transform.position, this.transform.forward * (1), out hit, 5.0f))
            {
                if (hit.collider.CompareTag("Player"))
                {
                    allowLaneChange = false;
                }
            }

            if (allowLaneChange)
            {
                // right arrow key was pressed
                if (this.lane == Lane.Middle)
                {
                    this.lane = Lane.Right;
                }
                if (this.lane == Lane.Left)
                {
                    this.lane = Lane.Middle;
                }
            }
        }

        if (Input.GetKeyDown(prostituteKey))
        {
            // check if the current woman is a prostitute
            if (this.women.Count > 0)
            {
                Woman woman = this.women.Peek();
                if (woman is ProstituteWoman)
                {
                    ProstituteWoman prostitute = (ProstituteWoman)woman;
                    if (this.money >= prostitute.moneyNeeded)
                    {
                        this.money -= prostitute.moneyNeeded;          // subtract money
                        this.women.Dequeue();                          // get rid of prostitute
                        this.updateMoneyText();                        // update GUI
                        this.updateWomenText();

                        // play audio
                        this.audioPlayer.playKissSound();
                    }
                }
            }
        }

        if (Input.GetKeyDown(fatKey))
        {
            // check if the current woman is a fatty
            if (this.women.Count > 0)
            {
                Woman woman = this.women.Peek();
                if (woman is FatWoman)
                {
                    FatWoman fatty = (FatWoman)woman;
                    fatty.loveNeeded--;
                    this.audioPlayer.playWomanGroaningSound();
                    if (fatty.loveNeeded <= 0)
                    {
                        // she got enough love, get rid of fatty
                        this.women.Dequeue();
                        this.updateWomenText();
                    }
                }
            }
        }

        // check if the cake button was touched
        if (Input.GetKeyDown(cakeKey))
        {
            if (this.cake > 0)
            {
                // "cake" the other player
                GameObject otherPlayer = null;
                if (this.playerNumber == PlayerNumber.Player1)
                {
                    // cake player 2
                    otherPlayer = GameObject.Find("player2");
                }
                else
                {
                    // cake player 2
                    otherPlayer = GameObject.Find("player1");
                }

                otherPlayer.GetComponent <Player>().cakePlayer();
                this.cake--;
                this.updateCakeText();

                // play audio
                this.audioPlayer.playCakedSound();
            }
        }

        // check if the next women is a granny
        if (this.women.Count > 0)
        {
            Woman woman = this.women.Peek();
            if (woman is GrandmaWoman)
            {
                GrandmaWoman granny = (GrandmaWoman)woman;
                granny.timeNeeded -= Time.deltaTime;

                Debug.Log("grandmaWoman time left: " + granny.timeNeeded);

                // check if grandma time left is <= 0
                if (granny.timeNeeded <= 0)
                {
                    this.women.Dequeue();
                    this.updateWomenText();
                }
            }
        }


        this.updateWomanHUD();
        this.updateCakePlane();


        // update the position based on the current lane
        this.setPositionBasedOnLane();

        // move the player forward
        float realSpeed = this.unitsPerSecond;

        if (this.women.Count > 0)
        {
            // there is a woman! slow player down
            Woman woman = this.women.Peek();
            realSpeed = realSpeed * woman.womanMultiplier;
        }

        if (this.speedTimeRemaining > 0)           // make player faster if it was on a speeder
        {
            realSpeed = realSpeed * this.speedMultiplier;
        }

        Debug.Log("realSpeed: " + realSpeed);
        if (this.transform.position.x < this.goalXPosition)           // only move forward if not at the goal yet
        {
            this.transform.Translate(realSpeed * Time.deltaTime * (-1), 0.0f, 0.0f);
        }

        // check if both players are in the goal
        GameObject theOtherPlayer = null;

        if (this.playerNumber == PlayerNumber.Player1)
        {
            theOtherPlayer = GameObject.Find("player2");
        }
        else
        {
            theOtherPlayer = GameObject.Find("player1");
        }

        if (this.transform.position.x >= this.goalXPosition &&
            theOtherPlayer.transform.position.x >= this.goalXPosition)
        {
            GameObject canvas = null;
            if (this.playerNumber == PlayerNumber.Player1)
            {
                canvas = GameObject.Find("CanvasP2");
            }
            else
            {
                canvas = GameObject.Find("CanvasP1");
            }

            GameObject playAgainTextUI = canvas.transform.FindChild("PlayAgainText").gameObject;
            playAgainTextUI.GetComponent <Text> ().enabled = true;

            // already at goal! reload scene when pressing space bar
            if (Input.GetKeyDown(KeyCode.Space))
            {
                SceneManager.LoadScene("Menu");
            }
        }

        // update position of minimap
        // get percentage of progress
        float totalDistance = this.goalXPosition - this.startXPosition;         // distance
        float distanceRun   = this.transform.position.x - this.startXPosition;  // current progress
        float progress      = distanceRun / totalDistance;

        if (this.playerNumber == PlayerNumber.Player1)
        {
            GameObject.Find("Logic").GetComponent <MiniMapManager> ().setProgressPlayer1(progress);
        }
        else
        {
            GameObject.Find("Logic").GetComponent <MiniMapManager> ().setProgressPlayer2(progress);
        }
    }
예제 #2
0
// PRAGMA MARK: - Trigger

    void OnTriggerEnter(Collider other)
    {
        // check if it collided with speeder
        if (other.CompareTag("Speeder"))
        {
            this.speedTimeRemaining = this.speedTime;

            // Play audio
            this.audioPlayer.playSpeedboostSound();

            // check if it collided with prostitute
        }
        else if (other.CompareTag("Prostitute"))
        {
            // make player slow again
            this.speedTimeRemaining = 0.0f;
            Destroy(other.gameObject);

            // Add Prostitute to woman queue
            Woman prostitute = new ProstituteWoman(this.prostituteMultiplier);
            this.women.Enqueue(prostitute);
            this.updateWomenText();
        }
        else if (other.CompareTag("Money"))
        {
            // make random money value
            //int moneyValue = Random.Range (0, 6) * 10 + 70; // range: 70 - 120
            int moneyValue = 100;
            this.money += moneyValue;

            this.updateMoneyText();

            // destroy money object
            Destroy(other.gameObject);

            // create a cake object where money was
            GameObject logic = GameObject.Find("Logic");
            logic.GetComponent <WorldBuilder> ().createCakeAtLocation(other.transform.position, this.playerNumber);

            // Play audio
            this.audioPlayer.playMoneyCollectedSound();
        }
        else if (other.CompareTag("Fatty"))
        {
            // make player slow again
            this.speedTimeRemaining = 0.0f;
            Destroy(other.gameObject);

            // add Fatty to woman queue
            Woman fatty = new FatWoman(this.fattyMultiplier);
            this.women.Enqueue(fatty);
            this.updateWomenText();
        }
        else if (other.CompareTag("Granny"))
        {
            //Debug.Log ("collided with granny");
            // make player slow again
            this.speedTimeRemaining = 0.0f;
            Destroy(other.gameObject);

            // add granny to woman queue
            Woman granny = new GrandmaWoman(this.grannyMultiplier);
            this.women.Enqueue(granny);
            this.updateWomenText();
        }

        // cake comparison... first find out which cakes are important
        string importantCakeTag;

        if (this.playerNumber == PlayerNumber.Player1)
        {
            importantCakeTag = "CakeByP2";
        }
        else
        {
            importantCakeTag = "CakeByP1";
        }

        if (other.CompareTag(importantCakeTag))
        {
            // collected a cake by the other player! --> instantly cake other player!
            Destroy(other.gameObject);

            // "cake" the other player
            GameObject otherPlayer = null;
            if (this.playerNumber == PlayerNumber.Player1)
            {
                // cake player 2
                otherPlayer = GameObject.Find("player2");
            }
            else
            {
                // cake player 2
                otherPlayer = GameObject.Find("player1");
            }

            otherPlayer.GetComponent <Player>().cakePlayer();
            this.audioPlayer.playCakedSound();

            /*
             * this.cake++;
             * this.updateCakeText ();
             *
             * // play audio
             * this.audioPlayer.playCakeCollectedSound();
             */
        }
    }