/*
     *	FUNCTION: Called when user runs out of energy
     *	CALLED BY:	Update()
     */
    private bool DeathScene()
    {
        bInAir = false;
        tPlayerRotation.localEulerAngles = new Vector3(0, 0, 0);

        if (fDeathAnimStartTime == 0)
        {
            hSoundManagerCS.stopSound(SoundManagerCS.CharacterSounds.Footsteps);
            bControlsEnabled = false;

            /*Vector3 v3EffectPosition = this.transform.position;
             * v3EffectPosition.x += 15;
             * v3EffectPosition.y += 5;*/

            if (!mecanimEnabled)            //if legacy animations enabled
            {
                aPlayer.CrossFade("death", 0.1f);
            }
            else            //if mecanim enabled
            {
                aPlayerMecAnim.SetBool("DeathAnim", true);
                aPlayerMecAnim.SetBool("RunAnim", false);
            }
            hEnemyControllerCS.playDeathAnimation();

            if (hInGameScriptCS.isCustomMenuEnabled())
            {
                hMenuScriptCS.hideHUDElements();
            }

            fDeathAnimStartTime = Time.time;
        }
        else if (fDeathAnimStartTime != 0 && (Time.time - fDeathAnimStartTime) >= iDeathAnimEndTime)
        {
            hInGameScriptCS.setupDeathMenu();
            return(true);
        }

        return(false);
    }
	void Start()
	{
		//script references
		hPatchesRandomizerCS = (PatchesRandomizerCS)this.GetComponent(typeof(PatchesRandomizerCS));
		//hMissionsControllerCS = (MissionsControllerCS)this.GetComponent(typeof(MissionsControllerCS));
		//hGlobalAchievementControllerCS = (GlobalAchievementControllerCS)this.GetComponent(typeof(GlobalAchievementControllerCS));
		hPlayerSidesColliderScriptCS = (PlayerSidesColliderScriptCS)GameObject.Find("PlayerSidesCollider").GetComponent(typeof(PlayerSidesColliderScriptCS));
		hPlayerFrontColliderScriptCS = (PlayerFrontColliderScriptCS)GameObject.Find("PlayerFrontCollider").GetComponent(typeof(PlayerFrontColliderScriptCS));
		hSoundManagerCS = (SoundManagerCS)GameObject.Find("SoundManager").GetComponent(typeof(SoundManagerCS));
		hInGameScriptCS = (InGameScriptCS)this.GetComponent(typeof(InGameScriptCS));
		hPitsMainControllerCS = (PitsMainControllerCS)this.GetComponent(typeof(PitsMainControllerCS));
		hCheckPointsMainCS = (CheckPointsMainCS)this.GetComponent(typeof(CheckPointsMainCS));
		hPowerupScriptCS = (PowerupsMainControllerCS)this.GetComponent(typeof(PowerupsMainControllerCS));
		//hEnemyControllerCS = (EnemyControllerCS)GameObject.Find("Enemy").GetComponent(typeof(EnemyControllerCS));
		hPowerupScriptCS = (PowerupsMainControllerCS)this.GetComponent(typeof(PowerupsMainControllerCS));
		hCameraControllerCS = (CameraControllerCS)GameObject.Find("Main Camera").GetComponent(typeof(CameraControllerCS));
		swipeLogic = (SwipeControlsCS)transform.GetComponent(typeof(SwipeControlsCS));
        //tPlayerMesh = (Transform)GameObject.Find("fatguy_").GetComponent(typeof(Transform));
		
		//check which type of menu (Custom or NGUI) to work with
		if (hInGameScriptCS.isCustomMenuEnabled())
		{
			//hMenuScriptCS = (MenuScriptCS)GameObject.Find("MenuGroup").GetComponent(typeof(MenuScriptCS));
			HUDCamera = GameObject.Find("HUDCamera").GetComponent<Camera>();
			
			tHUDGroup = GameObject.Find("HUDMainGroup/HUDGroup").transform;
			tPauseButton = GameObject.Find("HUDMainGroup/HUDGroup/HUDPause").transform;
		}
		
		tPlayer = transform;
		tPlayerRotation = transform.Find("PlayerRotation");
		
		//get the animation component of the player character
		if (this.transform.Find("PlayerRotation/PlayerMesh/Prisoner"))
		{
			mecanimEnabled = false;
			aPlayer = (Animation)this.transform.Find("PlayerRotation/PlayerMesh/Prisoner").GetComponent(typeof(Animation));			
			StartCoroutine("playIdleAnimations");//start playing idle animations
		}
		else if (this.transform.Find("PlayerRotation/PlayerMesh/Prisoner(MecAnim)"))//check for mecanim animated character
		{
			mecanimEnabled = true;
			aPlayerMecAnim = (Animator)this.transform.Find("PlayerRotation/PlayerMesh/Prisoner(MecAnim)").GetComponent(typeof(Animator));
			
			v3DefaultPlayerAnimPosition = aPlayerMecAnim.transform.localPosition;//get the default player position
			v3DefaultPlayerAnimRotation = aPlayerMecAnim.transform.localEulerAngles;//get the default player rotation		
		}
			
		tBlobShadowPlane = transform.Find("BlobShadowPlane");//get the shadow
		
		tPlayerSidesCollider = GameObject.Find("PlayerSidesCollider").transform;//get the sides collider to detect stumbles
		tFrontCollider = GameObject.Find("PlayerFrontCollider").transform;//get the front collider to detect collisions
		
		v3BNCDefaultScale = tFrontCollider.localScale;	
		v3BFCDefaultScale = tPlayerSidesCollider.localScale;
		
		bInAir = false;
		fCurrentDistanceOnPath = 50.0f;	//inital distance with respect to spline
		fCurrentDistance = 0.0f;
		fCurrentMileage = 0.0f;
		tCurrentAngle = 0.0f;	
		fPitFallLerpValue = 0.0f;
		fPitFallForwardSpeed = 0.0f;
		fPitPositionX = 0.0f;
		fDeathAnimStartTime = 0;
		bGroundhit = false;	
		bJumpFlag = false;
		bInJump = false;
		fCurrentUpwardVelocity = 0;
		fCurrentHeight = 0;
		
		bDirectionQueueFlag = false;
		directionQueue = SwipeControlsCS.SwipeDirection.Null;
		iLanePosition = 0;	//set current lane to mid	
		fCurrentWalkSpeed = fStartingWalkSpeed;
		
		//get the type of controls (swipe or gyro) set by user
		if (PlayerPrefs.HasKey("ControlsType"))
			swipeControlsEnabled = PlayerPrefs.GetInt("ControlsType") == 1 ? true : false;
		else
			PlayerPrefs.SetInt("ControlsType", (swipeControlsEnabled == true ? 1 : 0));
			
		//stop footsteps sound if playing
		hSoundManagerCS.stopSound(SoundManagerCS.CharacterSounds.Footsteps);
        stumbledXtimes = 0;
	}//end of Start()
Esempio n. 3
0
    void FixedUpdate()
    {
        if (hInGameScriptCS.isGamePaused() == true)
        {
            return;
        }

        //set the position of guard in current frame
        tEnemy.position = new Vector3(Mathf.Lerp(tEnemy.position.x, (tPlayer.position.x - fEnemyPosition), Time.deltaTime * 10),
                                      tEnemy.position.y, tEnemy.position.z);

        if (!hControllerScriptCS.isInAir())        //follow the player in y-axis if he's not jumping (cars cant jump)
        {
            tEnemy.position = new Vector3(tEnemy.position.x, Mathf.Lerp(tEnemy.position.y, tPlayer.position.y + fEnemyPositionY, Time.deltaTime * 8),
                                          tEnemy.position.z);
        }

        //ignore y-axis rotation and horizontal movement in idle and death state
        if (iEnemyState < 4)
        {
            tEnemy.position         = new Vector3(tEnemy.position.x, tEnemy.position.y, Mathf.Lerp(tEnemy.position.z, tPlayer.position.z, Time.deltaTime * 10));
            tEnemy.localEulerAngles = new Vector3(tEnemy.localEulerAngles.x, -hControllerScriptCS.getCurrentPlayerRotation(), tEnemy.localEulerAngles.z);
        }

        if (iEnemyState == 1)        //hide the chasing character
        {
            fCosLerp      += (Time.deltaTime / 10);
            fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX + 45, Mathf.Cos(fCosLerp) / 1000);

            if (fCosLerp >= 0.7f)
            {
                fCosLerp    = 0.0f;
                iEnemyState = 0;

                hSoundManagerCS.stopSound(SoundManagerCS.EnemySounds.Siren);
            }
        }
        else if (iEnemyState == 2)        //show the chasing character
        {
            hSoundManagerCS.playSound(SoundManagerCS.EnemySounds.Siren);

            fCosLerp      += (Time.deltaTime / 4);
            fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX, Mathf.Cos(fCosLerp));

            if (fCosLerp >= 1.5f)
            {
                fCosLerp    = 0.0f;
                iEnemyState = 3;
            }
        }
        else if (iEnemyState == 3)        //wait for 'fChaseTime' after showing character
        {
            if ((Time.time - fStumbleStartTime) % 60 >= fChaseTime)
            {
                iEnemyState = 1;
            }
        }

        //DEATH SEQUENCE
        else if (iEnemyState == 4)        //on death
        {
            //to ensure correct rotation animation
            tEnemy.localEulerAngles = new Vector3(tEnemy.localEulerAngles.x, 350, tEnemy.localEulerAngles.z);

            hSoundManagerCS.playSound(SoundManagerCS.EnemySounds.TiresSqueal);
            iEnemyState = 5;
        }
        else if (iEnemyState == 5)                                                                                        //pin behind the player
        {
            fEnemyPosition  = Mathf.Lerp(fEnemyPosition, fEnemyPositionX + 20, Time.fixedDeltaTime * 50);                 //vertical position after skid
            tEnemy.position = new Vector3(tEnemy.position.x, tEnemy.position.y,
                                          Mathf.Lerp(tEnemy.position.z, tPlayer.position.z + 20, Time.deltaTime * 10));   //horizontal position after skid

            tEnemy.localEulerAngles = Vector3.Lerp(tEnemy.localEulerAngles, new Vector3(0, 260, 0), Time.deltaTime * 10); //90 degree rotation
            if (tEnemy.localEulerAngles.y <= 261)
            {
                iEnemyState = 6;
            }
        }
        else if (iEnemyState == 6)
        {
            hSoundManagerCS.stopSound(SoundManagerCS.EnemySounds.Siren);
        }
    }    //end of Update
    void Start()
    {
        //script references
        hPatchesRandomizerCS           = (PatchesRandomizerCS)this.GetComponent(typeof(PatchesRandomizerCS));
        hMissionsControllerCS          = (MissionsControllerCS)this.GetComponent(typeof(MissionsControllerCS));
        hGlobalAchievementControllerCS = (GlobalAchievementControllerCS)this.GetComponent(typeof(GlobalAchievementControllerCS));
        hPlayerSidesColliderScriptCS   = (PlayerSidesColliderScriptCS)GameObject.Find("PlayerSidesCollider").GetComponent(typeof(PlayerSidesColliderScriptCS));
        hPlayerFrontColliderScriptCS   = (PlayerFrontColliderScriptCS)GameObject.Find("PlayerFrontCollider").GetComponent(typeof(PlayerFrontColliderScriptCS));
        hSoundManagerCS       = (SoundManagerCS)GameObject.Find("SoundManager").GetComponent(typeof(SoundManagerCS));
        hInGameScriptCS       = (InGameScriptCS)this.GetComponent(typeof(InGameScriptCS));
        hPitsMainControllerCS = (PitsMainControllerCS)this.GetComponent(typeof(PitsMainControllerCS));
        hCheckPointsMainCS    = (CheckPointsMainCS)this.GetComponent(typeof(CheckPointsMainCS));
        hPowerupScriptCS      = (PowerupsMainControllerCS)this.GetComponent(typeof(PowerupsMainControllerCS));
        hEnemyControllerCS    = (EnemyControllerCS)GameObject.Find("Enemy").GetComponent(typeof(EnemyControllerCS));
        hPowerupScriptCS      = (PowerupsMainControllerCS)this.GetComponent(typeof(PowerupsMainControllerCS));
        hCameraControllerCS   = (CameraControllerCS)GameObject.Find("Main Camera").GetComponent(typeof(CameraControllerCS));
        swipeLogic            = (SwipeControlsCS)transform.GetComponent(typeof(SwipeControlsCS));

        //check which type of menu (Custom or NGUI) to work with
        if (hInGameScriptCS.isCustomMenuEnabled())
        {
            hMenuScriptCS = (MenuScriptCS)GameObject.Find("MenuGroup").GetComponent(typeof(MenuScriptCS));
            HUDCamera     = GameObject.Find("HUDCamera").GetComponent <Camera>();

            tHUDGroup    = GameObject.Find("HUDMainGroup/HUDGroup").transform;
            tPauseButton = GameObject.Find("HUDMainGroup/HUDGroup/HUDPause").transform;
        }

        tPlayer         = transform;
        tPlayerRotation = transform.Find("PlayerRotation");

        //get the animation component of the player character
        if (this.transform.Find("PlayerRotation/PlayerMesh/Prisoner"))
        {
            mecanimEnabled = false;
            aPlayer        = (Animation)this.transform.Find("PlayerRotation/PlayerMesh/Prisoner").GetComponent(typeof(Animation));
            StartCoroutine("playIdleAnimations");                                    //start playing idle animations
        }
        else if (this.transform.Find("PlayerRotation/PlayerMesh/Prisoner(MecAnim)")) //check for mecanim animated character
        {
            mecanimEnabled = true;
            aPlayerMecAnim = (Animator)this.transform.Find("PlayerRotation/PlayerMesh/Prisoner(MecAnim)").GetComponent(typeof(Animator));

            v3DefaultPlayerAnimPosition = aPlayerMecAnim.transform.localPosition;            //get the default player position
            v3DefaultPlayerAnimRotation = aPlayerMecAnim.transform.localEulerAngles;         //get the default player rotation
        }

        tBlobShadowPlane = transform.Find("BlobShadowPlane");                    //get the shadow

        tPlayerSidesCollider = GameObject.Find("PlayerSidesCollider").transform; //get the sides collider to detect stumbles
        tFrontCollider       = GameObject.Find("PlayerFrontCollider").transform; //get the front collider to detect collisions

        v3BNCDefaultScale = tFrontCollider.localScale;
        v3BFCDefaultScale = tPlayerSidesCollider.localScale;

        bInAir = false;
        fCurrentDistanceOnPath = 50.0f;         //inital distance with respect to spline
        fCurrentDistance       = 0.0f;
        fCurrentMileage        = 0.0f;
        tCurrentAngle          = 0.0f;
        fPitFallLerpValue      = 0.0f;
        fPitFallForwardSpeed   = 0.0f;
        fPitPositionX          = 0.0f;
        fDeathAnimStartTime    = 0;
        bGroundhit             = false;
        bJumpFlag = false;
        bInJump   = false;
        fCurrentUpwardVelocity = 0;
        fCurrentHeight         = 0;

        bDirectionQueueFlag = false;
        directionQueue      = SwipeControlsCS.SwipeDirection.Null;
        iLanePosition       = 0;        //set current lane to mid
        fCurrentWalkSpeed   = fStartingWalkSpeed;

        //get the type of controls (swipe or gyro) set by user
        if (PlayerPrefs.HasKey("ControlsType"))
        {
            swipeControlsEnabled = PlayerPrefs.GetInt("ControlsType") == 1 ? true : false;
        }
        else
        {
            PlayerPrefs.SetInt("ControlsType", (swipeControlsEnabled == true ? 1 : 0));
        }

        //stop footsteps sound if playing
        hSoundManagerCS.stopSound(SoundManagerCS.CharacterSounds.Footsteps);
    }    //end of Start()
Esempio n. 5
0
    void FixedUpdate()
    {
        if (hInGameScriptCS.isGamePaused() == true)
        {
            return;
        }

        //set the position of guard in current frame

        /*
         * tEnemy.position = new Vector3(Mathf.Lerp(tEnemy.position.x, (tPlayer.position.x - fEnemyPosition), Time.deltaTime*10),
         *      tEnemy.position.y, tEnemy.position.z);
         */


        Matrix4x4 mat = new Matrix4x4();

        mat.SetTRS(new Vector3(0, 0, 0), Quaternion.Euler(new Vector3(0, -hControllerScriptCS.getCurrentPlayerRotation(), 0)), new Vector3(1, 1, 1));
        Vector3 pos = mat.MultiplyVector(new Vector3(-fEnemyPosition, 0, 0));

        tEnemy.position = new Vector3(Mathf.Lerp(tEnemy.position.x, (tPlayer.position.x + pos.x), Time.deltaTime * 10),
                                      tEnemy.position.y,        // Mathf.Lerp(tEnemy.position.y, (tPlayer.position.y - pos.y), Time.deltaTime*10),
                                      Mathf.Lerp(tEnemy.position.z, (tPlayer.position.z + pos.z), Time.deltaTime * 10));

        if (!hControllerScriptCS.isInAir())           //follow the player in y-axis if he's not jumping (cars cant jump)
        {
            tEnemy.position = new Vector3(tEnemy.position.x, Mathf.Lerp(tEnemy.position.y, tPlayer.position.y + fEnemyPositionY, Time.deltaTime * 8),
                                          tEnemy.position.z);
        }
        else
        {
            RaycastHit hitInfo;
            if (Physics.Linecast(tEnemy.position + new Vector3(0, 20, 0), tEnemy.position + new Vector3(0, -100, 0), out hitInfo, (1 << LayerMask.NameToLayer("Terrain_lyr"))))
            {
                tEnemy.position = new Vector3(tEnemy.position.x, Mathf.Lerp(tEnemy.position.y, hitInfo.point.y + fEnemyPositionY, Time.deltaTime * 8),
                                              tEnemy.position.z);
            }
        }

        //ignore y-axis rotation and horizontal movement in idle and death state
        if (iEnemyState < 4)
        {
            //	Vector3 pos = mat.MultiplyVector(new Vector3( 0, 0, 0));

            //tEnemy.position = new Vector3(tEnemy.position.x, tEnemy.position.y,	Mathf.Lerp(tEnemy.position.z, tPlayer.position.z, Time.deltaTime*10));
            tEnemy.localEulerAngles = new Vector3(tEnemy.localEulerAngles.x, -hControllerScriptCS.getCurrentPlayerRotation(), tEnemy.localEulerAngles.z);
        }

        if (iEnemyState == 1)        //hide the chasing character
        {
            fCosLerp      += (Time.deltaTime / 10);
            fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX + 45, Mathf.Cos(fCosLerp) / 1000);

            if (fCosLerp >= 0.7f)
            {
                fCosLerp    = 0.0f;
                iEnemyState = 0;

                hSoundManagerCS.stopSound(SoundManagerCS.EnemySounds.Siren);
            }
        }
        else if (iEnemyState == 2)        //show the chasing character
        {
            hSoundManagerCS.playSound(SoundManagerCS.EnemySounds.Siren);

            fCosLerp      += (Time.deltaTime / 4);
            fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX, Mathf.Cos(fCosLerp));

            if (fCosLerp >= 1.5f)
            {
                fCosLerp    = 0.0f;
                iEnemyState = 3;
            }
        }
        else if (iEnemyState == 3)        //wait for 'fChaseTime' after showing character
        {
            if ((Time.time - fStumbleStartTime) % 60 >= fChaseTime)
            {
                iEnemyState = 1;
            }
        }

        //DEATH SEQUENCE
        else if (iEnemyState == 4)        //on death
        {
            //to ensure correct rotation animation
            tEnemy.localEulerAngles = new Vector3(tEnemy.localEulerAngles.x, 350 - hControllerScriptCS.getCurrentPlayerRotation(), tEnemy.localEulerAngles.z);

            hSoundManagerCS.playSound(SoundManagerCS.EnemySounds.TiresSqueal);
            iEnemyState = 5;
        }
        else if (iEnemyState == 5)                                                                       //pin behind the player
        {
            fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX + 20, Time.fixedDeltaTime * 50); //vertical position after skid
            //	tEnemy.position = new Vector3(tEnemy.position.x, tEnemy.position.y,
            //		Mathf.Lerp(tEnemy.position.z, tPlayer.position.z + 20, Time.deltaTime*10));//horizontal position after skid

            tEnemy.localEulerAngles = Vector3.Lerp(tEnemy.localEulerAngles, new Vector3(0, 260 - hControllerScriptCS.getCurrentPlayerRotation(), 0), Time.deltaTime * 10);      //90 degree rotation
            if (tEnemy.localEulerAngles.y <= 261)
            {
                iEnemyState = 6;
            }
        }
        else if (iEnemyState == 6)
        {
            hSoundManagerCS.stopSound(SoundManagerCS.EnemySounds.Siren);
        }
    }    //end of Update