// Aquesta funció comprova si hi ha algun motiu que impedeixi passar al nou estat.
    // De moment no hi ha cap motiu per cancel·lar cap estat.
    bool checkIfAbortOnStateCondition(PlayerStateController.playerStates newState)
    {
        bool returnVal = false;

        switch (newState)
        {
        case PlayerStateController.playerStates.idle:
            break;

        case PlayerStateController.playerStates.left:
            break;

        case PlayerStateController.playerStates.right:
            break;

        case PlayerStateController.playerStates.jump:
            break;

        case PlayerStateController.playerStates.landing:
            break;

        case PlayerStateController.playerStates.falling:
            break;

        case PlayerStateController.playerStates.kill:
            break;

        case PlayerStateController.playerStates.resurrect:
            break;
        }
        // Retornar True vol dir 'Abort'. Retornar False vol dir 'Continue'.
        return(returnVal);
    }
 public void endThrowKunai()
 {
     playerAnimator.SetInteger("StateAnim", 0);
     currentState = PlayerStateController.playerStates.idle;
     //newState = PlayerStateController.playerStates.idle;
     //onStateChange(PlayerStateController.playerStates.idle);
 }
    // onStateChange es crida sempre que canvia l'estat del player
    public void onStateChange(PlayerStateController.playerStates newState)
    {
        // Si l'estat actual i el nou són el mateix, no cal fer res
        if (newState == currentState)
        {
            return;
        }
        // Comprovar que no hi hagi condicions per abortar l'estat
        if (checkIfAbortOnStateCondition(newState))
        {
            return;
        }
        // Comprovar que el pas de l'estat actual al nou estat està permès. Si no ho està, no es continua.
        if (!checkForValidStatePair(newState))
        {
            return;
        }
        // Realitzar les accions necessàries en cada cas per canviar l'estat.
        // De moment només es gestionen els estats idle, right i left
        switch (newState)
        {
        case PlayerStateController.playerStates.idle:
            break;

        case PlayerStateController.playerStates.left:
            break;

        case PlayerStateController.playerStates.right:
            break;

        case PlayerStateController.playerStates.jump:
            break;

        case PlayerStateController.playerStates.landing:
            GetComponent <Rigidbody2D>().velocity = Vector2.zero;    //velocitat lineal: zero
            break;

        case PlayerStateController.playerStates.falling:
            break;

        case PlayerStateController.playerStates.kill:
            break;

        case PlayerStateController.playerStates.resurrect:
            transform.position = playerRespawnPoint.transform.position; //posicio: la de PlayerRespawnPoint
            transform.rotation = Quaternion.identity;                   //rotacio: cap
            GetComponent <Rigidbody2D>().velocity = Vector2.zero;       //velocitat lineal: zero
            break;

        case PlayerStateController.playerStates.teleport:
            transform.position = playerTeleportPortal.transform.position;
            transform.rotation = Quaternion.identity;
            GetComponent <Rigidbody2D>().velocity = Vector2.zero;
            break;
        }
        // Guardar estat actual com a estat previ
        previousState = currentState;
        // Assignar el nou estat com a estat actual del player
        currentState = newState;
    }
Example #4
0
    // onStateChange is called whenever we make a change to the player's state
    // from anywhere within the game's code.
    public void onStateChange(PlayerStateController.playerStates newState)
    {
        playerWalkSpeed = 100f;
        // If the current state and the new state are the same, abort - no
        // need to change to the state we're already in.
        if (newState == currentState)
        {
            return;
        }

        // Check if the current state is allowed to transition into // this
        // state.If it's not, abort.
        if (!checkForValidStatePair(newState))
        {
            return;
        }

        // Having reached here, we now know that this state change is
        // allowed.So let's perform the necessary actions depending
        // on what the new state is.
        switch (newState)
        {
        case PlayerStateController.playerStates.idle:
            break;

        case PlayerStateController.playerStates.left:
            break;

        case PlayerStateController.playerStates.right:
            break;
        }

        // And finally, assign the new state to the player object
        currentState = newState;
    }
    // Aquesta funció comprova si hi ha algun motiu que impedeixi passar al nou estat.
    // De moment no hi ha cap motiu per cancel·lar cap estat.
    bool checkIfAbortOnStateCondition(PlayerStateController.playerStates newState)
    {
        bool returnVal = false;

        switch (newState)
        {
        case PlayerStateController.playerStates.idle:
            break;

        case PlayerStateController.playerStates.left:
            break;

        case PlayerStateController.playerStates.right:
            break;

        case PlayerStateController.playerStates.jump:
            break;

        case PlayerStateController.playerStates.landing:
            break;

        case PlayerStateController.playerStates.falling:
            break;

        case PlayerStateController.playerStates.kill:
            break;

        case PlayerStateController.playerStates.resurrect:
            break;

        case PlayerStateController.playerStates.firingWeapon:
            // Ignorar si no ha passat prou temps
            if (PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.firingWeapon] > Time.time)
            {
                returnVal = true;
            }
            break;

        case PlayerStateController.playerStates.firingMortar:
            // Ignorar si no ha passat prou temps
            if (PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.firingMortar] > Time.time)
            {
                returnVal = true;
            }
            break;
        }
        // Retornar True vol dir 'Abort'. Retornar False vol dir 'Continue'.
        return(returnVal);
    }
Example #6
0
    // checkIfAbortOnStateCondition allows us to do additional state verification, to see
    // if there is any reason this state should not be allowed to begin.
    bool checkIfAbortOnStateCondition(PlayerStateController.playerStates newState)
    {
        bool returnVal = false;

        switch (newState)
        {
        case PlayerStateController.playerStates.idle:
            break;

        case PlayerStateController.playerStates.left:
            break;

        case PlayerStateController.playerStates.right:
            break;

        case PlayerStateController.playerStates.jump:
            float nextAllowedJumpTime = PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump];

            if (nextAllowedJumpTime == 0.0f || nextAllowedJumpTime > Time.time)
            {
                returnVal = true;
            }
            break;

        case PlayerStateController.playerStates.landing:
            break;

        case PlayerStateController.playerStates.falling:
            break;

        case PlayerStateController.playerStates.kill:
            break;

        case PlayerStateController.playerStates.resurrect:
            break;

        case PlayerStateController.playerStates.firingWeapon:
            if (PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.firingWeapon] > Time.time)
            {
                returnVal = true;
            }

            break;
        }

        // Value of true means 'Abort'. Value of false means 'Continue'.
        return(returnVal);
    }
Example #7
0
    // checkIfAbortOnStateCondition은 상태가 시작되지 말아야 하는 이유가 있는지 확인할 수 있도록 추가적인 상태 검증을 수행한다.
    bool checkIfAbortOnStateCondition(PlayerStateController.playerStates newState)
    {
        bool returnVal = false;

        switch(newState)
        {
        case PlayerStateController.playerStates.idle:
            break;

        case PlayerStateController.playerStates.left:
            break;

        case PlayerStateController.playerStates.right:
            break;

        case PlayerStateController.playerStates.jump:
            float nextAllowedJumpTime = PlayerStateController.stateDelayTimer[ (int)PlayerStateController.playerStates.jump ];

            if(nextAllowedJumpTime == 0.0f || nextAllowedJumpTime > Time.time)
                returnVal = true;
            break;

        case PlayerStateController.playerStates.landing:
            break;

        case PlayerStateController.playerStates.falling:
            break;

        case PlayerStateController.playerStates.kill:
            break;

        case PlayerStateController.playerStates.resurrect:
            break;

        case PlayerStateController.playerStates.firingWeapon:
            if(PlayerStateController.stateDelayTimer[ (int)PlayerStateController.playerStates.firingWeapon] > Time.time)
                returnVal = true;

            break;
        }

        // true 값은 ‘중지’, false 값은 ‘계속’을 의미한다.
        return returnVal;
    }
    // onStateChange es crida sempre que canvia l'estat del player
    public void onStateChange(PlayerStateController.playerStates newState)
    {
        // Si l'estat actual i el nou són el mateix, no cal fer res
        if (newState == currentState)
        {
            return;
        }
        // Comprovar que no hi hagi condicions per abortar l'estat
        if (checkIfAbortOnStateCondition(newState))
        {
            return;
        }
        // Comprovar que el pas de l'estat actual al nou estat està permès. Si no ho està, no es continua.
        if (!checkForValidStatePair(newState))
        {
            return;
        }
        // Realitzar les accions necessàries en cada cas per canviar l'estat.
        // De moment només es gestionen els estats idle, right i left
        switch (newState)
        {
        case PlayerStateController.playerStates.idle: playerAnimator.SetBool("caminant", false); break;

        case PlayerStateController.playerStates.left: playerAnimator.SetBool("caminant", true); break;

        case PlayerStateController.playerStates.right: playerAnimator.SetBool("caminant", true); break;

        case PlayerStateController.playerStates.jump: break;

        case PlayerStateController.playerStates.landing: break;

        case PlayerStateController.playerStates.falling: break;

        case PlayerStateController.playerStates.kill: break;

        case PlayerStateController.playerStates.resurrect: break;
        }
        // Guardar estat actual com a estat previ
        previousState = currentState;
        // Assignar el nou estat com a estat actual del player
        currentState = newState;
    }
Example #9
0
    // Compare the desired new state against the current, and see if we are
    // allowed to change to the new state. This is a powerful system that ensures
    // we only allow the actions to occur that we want to occur.
    bool checkForValidStatePair(PlayerStateController.playerStates newState)
    {
        bool returnVal = false;

        // Compare the current against the new desired state.
        switch (currentState)
        {
        case PlayerStateController.playerStates.idle:
            // Any state can take over from idle.
            returnVal = true;
            break;

        case PlayerStateController.playerStates.left:
            // Any state can take over from the player moving // left.
            returnVal = true;
            break;

        case PlayerStateController.playerStates.right:
            // Any state can take over from the player moving // right.
            returnVal = true;
            break;
        }
        return(returnVal);
    }
	//onStateChange is called when we need to change player's state
	public void OnStateChange(PlayerStateController.playerStates newState)
	{
		//if the current state and the new state are the same, do nothing
		if (newState == currentState)
			return;

		//can current state transition into a new state?
		if (!CheckForValidStatePair(newState))
			return;

		//if it passes the above check:
		switch(newState)
		{
		case PlayerStateController.playerStates.idle:
			break;
		case PlayerStateController.playerStates.left:
			break;
		case PlayerStateController.playerStates.right:
			break;
		case PlayerStateController.playerStates.kill:
			break;
		case PlayerStateController.playerStates.resurrect:
			transform.position = playerRespawnPoint.transform.position;
			transform.rotation = Quaternion.identity;
			rigidbody2D.velocity = Vector2.zero;
			break;
		case PlayerStateController.playerStates.jump:
			if(playerHasLanded)
			{
				float JumpDirection = 0.0f;
				if(currentState == PlayerStateController.playerStates.left)
					JumpDirection = -1.0f;
				else if (currentState == PlayerStateController.playerStates.right)
					JumpDirection = 1.0f;
				else
					JumpDirection = 0.0f;

				//Apply jump force
				rigidbody2D.AddForce(new Vector2(JumpDirection * playerJumpForceHorizontal, playerJumpForceVertical));

				playerHasLanded = false;
				PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump] = 0f;
			}
			break;
		}

		//update the state check variable
		currentState = newState;
	}
Example #11
0
    // onStateChange is called whenever we make a change to the player's state
    // from anywhere within the game's code.
    public void onStateChange(PlayerStateController.playerStates newState)
    {
        // If the current state and the new state are the same, abort - no need
        // to change to the state we're already in.
        if (newState == currentState)
            return;

        // Verify there are no special conditions that would cause this state to abort
        if (checkIfAbortOnStateCondition(newState))
            return;

        // Check if the current state is allowed to transition into this state. If it's not, abort.
        if (!checkForValidStatePair(newState))
            return;

        // Having reached here, we now know that this state change is allowed.
        // So let's perform the necessary actions depending on what the new state is.
        switch (newState)
        {
            case PlayerStateController.playerStates.idle:
                playerAnimator.SetBool("Walking", false);
                break;

            case PlayerStateController.playerStates.left:
                playerAnimator.SetBool("Walking", true);
                break;

            case PlayerStateController.playerStates.right:
                playerAnimator.SetBool("Walking", true);
                break;

            case PlayerStateController.playerStates.jump:
                if (playerHasLanded)
                {
                    // Use the jump direction variable to specify if the player
                    // should be jumping left, right, or verticle
                    float jumpDirection = 0.0f;

                    if (currentState == PlayerStateController.playerStates.left)
                        jumpDirection = -1.0f;
                    else if (currentState == PlayerStateController.playerStates.right)
                        jumpDirection = 1.0f;
                    else
                        jumpDirection = 0.0f;

                    // Apply the actual jump force
                    GetComponent<Rigidbody2D>().AddForce(new Vector2(jumpDirection * playerJumpForceHorizontal, playerJumpForceVertical));

                    playerHasLanded = false;
                    PlayerStateController.stateDelayTimer[(int) PlayerStateController.playerStates.jump] = 0f;
                }
                break;
            case PlayerStateController.playerStates.landing:
                playerHasLanded = true;
                PlayerStateController.stateDelayTimer[(int) PlayerStateController.playerStates.jump] = Time.time + 0.1f;
                break;
            case PlayerStateController.playerStates.falling:
                PlayerStateController.stateDelayTimer[(int) PlayerStateController.playerStates.jump] = 0f;
                break;
            case PlayerStateController.playerStates.kill:
                break;
            case PlayerStateController.playerStates.resurrect:
                transform.position = playerRespawnPoint.transform.position;
                transform.rotation = Quaternion.identity;
                GetComponent<Rigidbody2D>().velocity = Vector2.zero;
                break;
            case PlayerStateController.playerStates.firingWeapon:
                // Make the bullet object
                GameObject newBullet = (GameObject) Instantiate(bulletPrefab);

                // Set up the bullet's starting postion
                newBullet.transform.position = bulletSpawnTransform.position;

                // Acquire the PlayerBulletController component on the new object
                // so we can specify some data
                PlayerBulletController bullCon = newBullet.GetComponent<PlayerBulletController>();

                // Set the player object
                bullCon.playerObject = gameObject;

                // Launch the bullet!
                bullCon.lauchBullet();

                // With the bullet made, set the state of the player back to the
                // current state
                onStateChange(currentState);

                PlayerStateController.stateDelayTimer[(int) PlayerStateController.playerStates.firingWeapon] = Time.time + 0.25f;
                break;
        }

        // Store the current state as the previous state
        previousState = currentState;

        // And finally, assign the new state to the player object
        currentState = newState;
    }
Example #12
0
 void onPlayerStateChange(PlayerStateController.playerStates newState)
 {
     currentPlayerState = newState;
 }
 public void endTakeDamage()
 {
     playerAnimator.SetInteger("StateAnim", 0);
     currentState = PlayerStateController.playerStates.idle;
 }
    // zkontrolujeme specialni podminky, ktere by mohli zabranit zmene stavu
    private bool checkIfAbortOnStateCondition(PlayerStateController.playerStates newState)
    {
        bool returnVal = false;

        switch (newState)
        {
        case PlayerStateController.playerStates.idle:
            break;

        case PlayerStateController.playerStates.left:
            if (PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.left] > Time.time)
            {
                returnVal = true;
            }
            break;

        case PlayerStateController.playerStates.right:
            if (PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.right] > Time.time)
            {
                returnVal = true;
            }
            break;

        // mame prodlevu mezi skoky
        case PlayerStateController.playerStates.jump:
            float nextAllowedJumpTime = PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump];

            if (nextAllowedJumpTime == 0.0f || nextAllowedJumpTime > Time.time)
            {
                returnVal = true;
            }
            break;

        case PlayerStateController.playerStates.landing:
            break;

        case PlayerStateController.playerStates.falling:
            break;

        case PlayerStateController.playerStates.takingDMG:
            if (PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.takingDMG] > Time.time)
            {
                returnVal = true;
            }
            break;

        case PlayerStateController.playerStates.immortal:
            break;

        case PlayerStateController.playerStates.kill:
            break;

        case PlayerStateController.playerStates.resurrect:
            break;

        // mame prodlevy mezi strelami
        case PlayerStateController.playerStates.firingWeapon:
            if (PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.firingWeapon] > Time.time)
            {
                returnVal = true;
            }

            break;
        }

        // true - nedovol novy stav
        // false - v poradku, pokracuj
        return(returnVal);
    }
    // porovname jestli muze novy stav prevzit ten stary
    bool checkForValidStatePair(PlayerStateController.playerStates newState)
    {
        bool returnVal = false;

        // porovnani
        switch (currentState)
        {
        case PlayerStateController.playerStates.idle:
            // vsechny stavy mohou prevzit nicnedelani
            returnVal = true;
            break;

        case PlayerStateController.playerStates.left:
            // vsechny stavy mohou prevzit pohyb vlevo
            returnVal = true;
            break;

        case PlayerStateController.playerStates.right:
            // vsechny stavy mohou prevzit pohyb vpravo
            returnVal = true;
            break;

        case PlayerStateController.playerStates.jump:
            // ve skoku muzeme strilet a pohybovat se vlevo, vpravo nebo zemrit
            if (
                newState == PlayerStateController.playerStates.landing ||
                newState == PlayerStateController.playerStates.left ||
                newState == PlayerStateController.playerStates.right ||
                newState == PlayerStateController.playerStates.kill ||
                newState == PlayerStateController.playerStates.firingWeapon
                )
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.landing:
            if (
                newState == PlayerStateController.playerStates.left ||
                newState == PlayerStateController.playerStates.right ||
                newState == PlayerStateController.playerStates.idle ||
                newState == PlayerStateController.playerStates.firingWeapon
                )
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.falling:
            // // muzeme i kotrolovat padani jako je u arkady typicke
            if (
                newState == PlayerStateController.playerStates.landing ||
                newState == PlayerStateController.playerStates.left ||
                newState == PlayerStateController.playerStates.right ||
                newState == PlayerStateController.playerStates.kill ||
                newState == PlayerStateController.playerStates.firingWeapon
                )
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.takingDMG:
            if (newState == PlayerStateController.playerStates.immortal ||
                newState == PlayerStateController.playerStates.kill)
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.immortal:
            // vsechny stavy krome smrti mohou prevzit nesmrtelnost
            if (newState == PlayerStateController.playerStates.idle ||
                newState == PlayerStateController.playerStates.left ||
                newState == PlayerStateController.playerStates.right ||
                newState == PlayerStateController.playerStates.jump ||
                newState == PlayerStateController.playerStates.falling ||
                newState == PlayerStateController.playerStates.landing
                )
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.kill:
            // po smrti se muzeme jenom obzivit
            if (newState == PlayerStateController.playerStates.resurrect)
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.resurrect:
            // po oziveni jsme ve stavu nicnedelani
            if (newState == PlayerStateController.playerStates.idle)
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.firingWeapon:
            returnVal = true;
            break;
        }
        return(returnVal);
    }
    // funkce reagujici na event zmeny stavu hrace.
    public void onStateChange(PlayerStateController.playerStates newState)
    {
        // kontorlujeme zda se novy stav nerovna staremu stavu, neni nutno provadet akci
        if (newState == currentState)
        {
            return;
        }

        // zkontrolujeme specialni podminky zmeny stavu
        if (checkIfAbortOnStateCondition(newState))
        {
            return;
        }


        // zkontrolujeme, jestli novy stav muze prepsat stav, ve kterem se nachazi hrac
        if (!checkForValidStatePair(newState))
        {
            return;
        }

        // muzeme bezpecne provezt akce podle noveho stavu
        switch (newState)
        {
        // nastavime promenne ovladajici animace pohybu
        case PlayerStateController.playerStates.idle:
            playerAnimator.SetBool("Walking", false);
            playerAnimator.SetBool("Hurted", false);
            break;

        case PlayerStateController.playerStates.left:
            playerAnimator.SetBool("Walking", true);
            playerAnimator.SetBool("Hurted", false);
            break;

        case PlayerStateController.playerStates.right:
            playerAnimator.SetBool("Walking", true);
            playerAnimator.SetBool("Hurted", false);
            break;

        case PlayerStateController.playerStates.jump:
            playerAnimator.SetBool("Grounded", false);
            playerAnimator.SetBool("Hurted", false);
            if (playerHasLanded)
            {
                // nastavime jumpDirection podle tooh, jestli se skace doprava nebo doleva
                float jumpDirection = 0.0f;
                if (currentState == PlayerStateController.playerStates.left)
                {
                    jumpDirection = -1.0f;
                }
                else if (currentState == PlayerStateController.playerStates.right)
                {
                    jumpDirection = 1.0f;
                }
                else
                {
                    jumpDirection = 0.0f;
                }

                // aplikujeme jumpDirection jako silu pusobici na fyzicke telo hrace
                GetComponent <Rigidbody2D>().AddForce(new Vector2(jumpDirection * playerJumpForceHorizontal, playerJumpForceVertical));
                // hrac je ve vzduchu
                playerHasLanded = false;
                // nemuzeme skakat znovu - vypneme stav - skok
                PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump] = 0f;
            }
            break;

        // hrac pristal na zemi
        case PlayerStateController.playerStates.landing:
            playerAnimator.SetBool("Grounded", true);
            playerAnimator.SetBool("Hurted", false);
            playerHasLanded = true;
            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump] = Time.time + 0.1f;
            break;

        // hrac ve vzduchu
        case PlayerStateController.playerStates.falling:
            playerAnimator.SetBool("Grounded", false);
            playerAnimator.SetBool("Hurted", false);
            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump] = 0.0f;
            break;

        case PlayerStateController.playerStates.takingDMG:
#if UNITY_ANDROID
            if (PlayerPrefs.GetInt("vibrations") == 1)
            {
                Handheld.Vibrate();
            }
#endif
            playerAnimator.SetBool("Hurted", true);
            playerHealth--;
            if (OnTakingDmgAction != null)
            {
                OnTakingDmgAction(playerHealth);
            }

            break;

        case PlayerStateController.playerStates.immortal:
            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.takingDMG] =
                Time.time + 0.5f;
            break;

        case PlayerStateController.playerStates.kill:
            break;

        // oziveni hrace na predem specifikovane pozici
        case PlayerStateController.playerStates.resurrect:
            playerHealth = PlayerHealthDefault;
            playerAnimator.SetBool("Hurted", true);
            resetPosition();
            if (onRessurectAction != null)
            {
                onRessurectAction(playerHealth, -15);
            }
            break;

        case PlayerStateController.playerStates.firingWeapon:
            playerAnimator.Play("PlayerFireAnim");

            // Vytvor bullet object
            GameObject newBullet = (GameObject)Instantiate(bulletPrefab);

            // urci pocatecni pozici
            newBullet.transform.position = bulletSpawnTransform.position;

            // ziskame z gameObjectu Bullet jeji komponentu - skript PlayerBulletController
            PlayerBulletController bullCon = newBullet.GetComponent <PlayerBulletController>();

            // priradime gameObject - player
            bullCon.PlayerObject = gameObject;

            // vypalime
            bullCon.launchBullet();

            // zmenime stav na puvodni
            onStateChange(currentState);

            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.firingWeapon] = Time.time + fireDelay;

            break;
        }
        // nastavime novy stav
        currentState = newState;
    }
    // onStateChange es crida sempre que canvia l'estat del player

    public void onStateChange(PlayerStateController.playerStates newState)
    {
        // Si l'estat actual i el nou són el mateix, no cal fer res
        if (newState == currentState)
        {
            return;
        }
        // Comprovar que no hi hagi condicions per abortar l'estat
        if (checkIfAbortOnStateCondition(newState))
        {
            return;
        }

// Comprovar que el pas de l'estat actual al nou estat està permès. Si no està, no es continua.

        if (!checkForValidStatePair(newState))
        {
            return;
        }

        // Realitzar les accions necessàries en cada cas per canviar l'estat.
        // De moment només es gestionen els estats idle, right i left
        switch (newState)
        {
        case PlayerStateController.playerStates.idle:
            playerAnimator.SetBool("Walking", false);
            break;

        case PlayerStateController.playerStates.left:
            playerAnimator.SetBool("Walking", true);
            break;

        case PlayerStateController.playerStates.right:
            playerAnimator.SetBool("Walking", true);
            break;

        case PlayerStateController.playerStates.jump:
            Debug.Log(newState);
            if (playerHasLanded)
            {
                // jumpDirection determina si el salt es a la dreta, esquerra o vertical
                float jumpDirection = 0.0f;
                if (currentState == PlayerStateController.playerStates.left)
                {
                    jumpDirection = -1.0f;
                }
                else if (currentState == PlayerStateController.playerStates.right)
                {
                    jumpDirection = 1.0f;
                }
                else
                {
                    jumpDirection = 0.0f;
                }
                // aplicar la força per fer el salt
                GetComponent <Rigidbody2D>().AddForce(new Vector2(jumpDirection * playerJumpForceHorizontal, playerJumpForceVertical));
                //indicar que el Player esta saltant en l'aire
                playerHasLanded = false;
            }

            break;

        case PlayerStateController.playerStates.landing:
            playerHasLanded = true;
            break;

        case PlayerStateController.playerStates.falling:
            break;

        case PlayerStateController.playerStates.kill:
            break;

        case PlayerStateController.playerStates.resurrect:
            //posicio: la de PlayerRespawnPoint
            transform.position = playerRespawnPoint.transform.position;
            transform.rotation = Quaternion.identity;             //rotacio: cap
            GetComponent <Rigidbody2D>().velocity = Vector2.zero; //velocitat lineal: zero
            break;

        case PlayerStateController.playerStates.firingWeapon:
            // Construir l'objecte bala a partir del Prefab
            GameObject newBullet = (GameObject)Instantiate(bulletPrefab);
            // Establir la posicio inicial de la bala creada
            //(la posicio de BulletSpawnTransform)
            newBullet.transform.position = bulletSpawnTransform.position;

            // Agafar el component PlayerBulletController de la bala
            //que s'ha creat
            // Establir temps a partir del qual es pot tornar a disparar
            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.firingWeapon] = Time.time + 0.25f;
            PlayerBulletController bullCon = newBullet.GetComponent <PlayerBulletController>();
            // Assignar a l'atribut playerObject de l'script
            //PlayerBulletController el Player
            bullCon.playerObject = gameObject;
            // Invocar metode que dispara la bala
            bullCon.launchBullet();
            // Despres de disparar, tornar a l'estat previ.
            onStateChange(currentState);
            break;

        case PlayerStateController.playerStates.firingMortar:
            // Construir l'objecte bala a partir del Prefab
            GameObject newBullet2 = (GameObject)Instantiate(bulletPrefab2);
            // Establir la posicio inicial de la bala creada
            //(la posicio de BulletSpawnTransform)
            newBullet2.transform.position = bulletSpawnTransform.position;

            // Agafar el component PlayerBulletController de la bala
            //que s'ha creat
            // Establir temps a partir del qual es pot tornar a disparar
            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.firingMortar] = Time.time + 0.25f;
            PlayerBulletController2 bullCon2 = newBullet2.GetComponent <PlayerBulletController2>();
            // Assignar a l'atribut playerObject de l'script
            //PlayerBulletController el Player
            bullCon2.playerObject = gameObject;
            // Invocar metode que dispara la bala
            bullCon2.launchBullet();
            // Despres de disparar, tornar a l'estat previ.
            onStateChange(currentState);
            break;
        }
        // Guardar estat actual com a estat previ
        previousState = currentState;
        // Assignar el nou estat com a estat actual del player
        currentState = newState;
    }
    // Comprovar si es pot passar al nou estat des de l'actual.
    // Es tracten diversos estats que encara no estan implementats, perquè el
    // codi sigui més ilustratiu
    bool checkForValidStatePair(PlayerStateController.playerStates newState)
    {
        bool returnVal = false;

        // Comparar estat actual amb el candidat a nou estat.
        switch (currentState)
        {
        case PlayerStateController.playerStates.idle:
            // Des de idle es pot passar a qualsevol altre estat
            returnVal = true;
            break;

        case PlayerStateController.playerStates.right:
            // Des de moving right  es pot passar a qualsevol altre estat
            returnVal = true;
            break;

        case PlayerStateController.playerStates.jump:
            // Des de  Jump només es pot passar a  landing o a kill.
            if (newState == PlayerStateController.playerStates.landing ||
                newState == PlayerStateController.playerStates.kill)
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.landing:
            // Des de landing només es pot passar a idle, left o right.
            if (newState == PlayerStateController.playerStates.left || newState == PlayerStateController.playerStates.right || newState == PlayerStateController.playerStates.idle)
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.falling:
            // Des de falling només es pot passar a  landing o a kill.
            if (newState == PlayerStateController.playerStates.landing || newState == PlayerStateController.playerStates.kill)
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.kill:
            // Des de kill només es pot passar resurrect
            if (newState == PlayerStateController.playerStates.resurrect)
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.resurrect:
            // Des de resurrect només es pot passar Idle
            if (newState == PlayerStateController.playerStates.idle)
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.teleport:
            // Des de resurrect només es pot passar Idle
            if (newState == PlayerStateController.playerStates.idle)
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;
        }
        return(returnVal);
    }
    // onStateChange is called whenever we make a change to the player's state
    // from anywhere within the game's code.
    public void onStateChange(PlayerStateController.playerStates newState)
    {
        // If the current state and the new state are the same, abort - no need
        // to change to the state we're already in.
        if (newState == currentState)
        {
            return;
        }

        // Verify there are no special conditions that would cause this state to abort
        if (checkIfAbortOnStateCondition(newState))
        {
            return;
        }


        // Check if the current state is allowed to transition into this state. If it's not, abort.
        if (!checkForValidStatePair(newState))
        {
            return;
        }

        // Having reached here, we now know that this state change is allowed.
        // So let's perform the necessary actions depending on what the new state is.
        switch (newState)
        {
        case PlayerStateController.playerStates.idle:
            playerAnimator.SetInteger("StateAnim", 0);
            break;

        case PlayerStateController.playerStates.left:
            playerAnimator.SetInteger("StateAnim", 1);
            break;

        case PlayerStateController.playerStates.right:
            playerAnimator.SetInteger("StateAnim", 1);

            break;

        case PlayerStateController.playerStates.jump:
            if (playerHasLanded)
            {
                playerAnimator.SetInteger("StateAnim", 3);
                // Use the jumpDirection variable to specify if the player should be jumping left, right or vertical
                float jumpDirection = 0.0f;
                if (currentState == PlayerStateController.playerStates.left)
                {
                    jumpDirection = -1.0f;
                }
                else if (currentState == PlayerStateController.playerStates.right)
                {
                    jumpDirection = 1.0f;
                }
                else
                {
                    jumpDirection = 0.0f;
                }

                // Apply the actual jump force
                rigidbody2D.AddForce(new Vector2(jumpDirection * playerJumpForceHorizontal, playerJumpForceVertical));

                playerHasLanded = false;
                PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump] = 0f;
            }
            break;


        case PlayerStateController.playerStates.landing:
            playerHasLanded = true;
            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump] = Time.time + 0.1f;
            break;

        case PlayerStateController.playerStates.falling:
            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump] = 0.0f;
            break;

        case PlayerStateController.playerStates.kill:
            player_meter.updateDamage();
            break;

        case PlayerStateController.playerStates.resurrect:
            transform.position = playerRespawnPoint.transform.position;
            transform.rotation = Quaternion.identity;
            break;

        case PlayerStateController.playerStates.firingWeapon:
            playerAnimator.SetInteger("StateAnim", 2);
            break;

        case PlayerStateController.playerStates.attack:
            playerAnimator.SetInteger("StateAnim", 4);
            break;

        case PlayerStateController.playerStates.slide:
            playerAnimator.SetInteger("StateAnim", 5);

            // Apply the actual jump force
            //rigidbody2D.AddForce(new Vector2(110, playerJumpForceVertical));
            //transform.Translate(new Vector3(((playerWalkSpeed * 3) * -1.0f) * Time.deltaTime, 0.0f, 0.0f));
            //rigidbody2D.AddForce (new Vector2((2 * 90), 0));
            //VERIFICA O SCALE DA KUNEI BASEDO NO SCALE DO PERSONAGEM
            Vector3 localScale = transform.localScale;
            if (localScale.x < 0.0f)
            {
                rigidbody2D.AddForce(new Vector2((2 * -90), 0));
            }
            else
            {
                rigidbody2D.AddForce(new Vector2((2 * +90), 0));
            }
            break;

        case PlayerStateController.playerStates.takeDamage:

            if (PlayerStateController.playerStates.jump == currentState)
            {
                enemyAttackforce = 4;
            }
            else
            {
                enemyAttackforce = 2;
            }
            Vector3 localScale2 = transform.localScale;
            if (takeDamageWaitAnimation == true)
            {
                playerAnimator.SetInteger("StateAnim", 6);
                takeDamageWaitAnimation = false;
                if (enemieAttackDirection)
                {
                    rigidbody2D.AddForce(new Vector2((enemyAttackforce * -90), 180));
                }
                else
                {
                    rigidbody2D.AddForce(new Vector2((enemyAttackforce * +90), 180));
                }
            }
            player_meter.updateDamage();


            break;

        case PlayerStateController.playerStates.continueGame:


            Destroy(gameObject);
            GameObject      go     = new GameObject("ClickToContinue");
            ClickToContinue script = go.AddComponent <ClickToContinue> ();
            script.scene = Application.loadedLevelName;
            go.AddComponent <DisplayRestartText> ();

            break;
        }



        // Store the current state as the previous state
        previousState = currentState;

        // And finally, assign the new state to the player object
        currentState = newState;
    }
Example #20
0
    // onStateChange is called whenever we make a change to the player's state
    // from anywhere within the game's code.
    public void onStateChange(PlayerStateController.playerStates newState)
    {
        // If the current state and the new state are the same, abort - no need
        // to change to the state we're already in.
        if (newState == currentState)
        {
            return;
        }

        // Verify there are no special conditions that would cause this state to abort
        if (checkIfAbortOnStateCondition(newState))
        {
            return;
        }


        // Check if the current state is allowed to transition into this state. If it's not, abort.
        if (!checkForValidStatePair(newState))
        {
            return;
        }

        // Having reached here, we now know that this state change is allowed.
        // So let's perform the necessary actions depending on what the new state is.
        switch (newState)
        {
        case PlayerStateController.playerStates.idle:
            playerAnimator.SetBool("Walking", false);
            break;

        case PlayerStateController.playerStates.left:
            playerAnimator.SetBool("Walking", true);
            break;

        case PlayerStateController.playerStates.right:
            playerAnimator.SetBool("Walking", true);
            break;

        case PlayerStateController.playerStates.jump:
            if (playerHasLanded)
            {
                // Use the jumpDirection variable to specify if the player should be jumping left, right or vertical
                float jumpDirection = 0.0f;
                if (currentState == PlayerStateController.playerStates.left)
                {
                    jumpDirection = -1.0f;
                }
                else if (currentState == PlayerStateController.playerStates.right)
                {
                    jumpDirection = 1.0f;
                }
                else
                {
                    jumpDirection = 0.0f;
                }

                // Apply the actual jump force
                GetComponent <Rigidbody2D>().AddForce(new Vector2(jumpDirection * playerJumpForceHorizontal, playerJumpForceVertical));

                playerHasLanded = false;
                PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump] = 0f;
            }
            break;


        case PlayerStateController.playerStates.landing:
            playerHasLanded = true;
            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump] = Time.time + 0.1f;
            break;

        case PlayerStateController.playerStates.falling:
            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump] = 0.0f;
            break;

        case PlayerStateController.playerStates.kill:
            break;

        case PlayerStateController.playerStates.resurrect:
            transform.position = playerRespawnPoint.transform.position;
            transform.rotation = Quaternion.identity;
            GetComponent <Rigidbody2D>().velocity = Vector2.zero;
            break;

/*
 *          case PlayerStateController.playerStates.firingWeapon:
 *              // Make the bullet object
 *              GameObject newBullet = (GameObject)Instantiate(bulletPrefab);
 *
 *              // Setup the bullet’s starting position
 *              newBullet.transform.position = bulletSpawnTransform.position;
 *
 *              // Acquire the PlayerBulletController component on the new object so we can specify some data
 *              //PlayerBulletController bullCon = newBullet.GetComponent<PlayerBulletController>();
 *
 *              // Set the player object
 *              //bullCon.playerObject = gameObject;
 *
 *              // Launch the bullet!
 *              //bullCon.launchBullet();
 *
 *              // With the bullet made, set the state of the player back to the current state
 *              onStateChange(currentState);
 *
 *              PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.firingWeapon] = Time.time + 0.25f;
 *              break;*/
        }

        // Store the current state as the previous state
        previousState = currentState;

        // And finally, assign the new state to the player object
        currentState = newState;
    }
Example #21
0
    // 변경을 원하는 상태를 현재의 상태와 비교하여	새로운 상태로의 변경을 허용할지 확인한다.
    // 이것이 일어나길 원하는 일만 확실히 일어나도록 하는 강력한 시스템이다.
    bool checkForValidStatePair(PlayerStateController.playerStates newState)
    {
        bool returnVal = false;

        // 현재의 상태를 바꾸길 원하는 상태와 비교
        switch(currentState)
        {
        case PlayerStateController.playerStates.idle:
            // idle에서 어떤 상태로든 넘어갈 수 있음
            returnVal = true;
            break;

        case PlayerStateController.playerStates.left:
            // 좌측 이동에서 어떤 상태로든 넘어갈 수 있음
            returnVal = true;
            break;

        case PlayerStateController.playerStates.right:
            // 우측 이동에서 어떤 상태로든 넘어갈 수 있음
            returnVal = true;
            break;

        case PlayerStateController.playerStates.jump:
            // 점프 상태에서 넘아갈 수 있는 상태는 landing(착지)이나 kill뿐이다.
            if(
                newState == PlayerStateController.playerStates.landing
                || newState == PlayerStateController.playerStates.kill
                || newState == PlayerStateController.playerStates.firingWeapon
            )
                returnVal = true;
            else
                returnVal = false;
            break;

        case PlayerStateController.playerStates.landing:
            // 착지 상태에서 넘어갈 수 있는 상태는 idle, left, right 상태이다.
            if(
                newState == PlayerStateController.playerStates.left
                || newState == PlayerStateController.playerStates.right
                || newState == PlayerStateController.playerStates.idle
                || newState == PlayerStateController.playerStates.firingWeapon
            )
                returnVal = true;
            else
                returnVal = false;
            PlayerStateController.stateDelayTimer[ (int)PlayerStateController.playerStates.jump] = 0.1f;
            break;

        case PlayerStateController.playerStates.falling:
            // 추락 상태에서 넘어갈 수 있는 상태는 landing이나 kill뿐이다.
            if(
                newState == PlayerStateController.playerStates.landing
                || newState == PlayerStateController.playerStates.kill
                || newState == PlayerStateController.playerStates.firingWeapon
            )
                returnVal = true;
            else
                returnVal = false;
            PlayerStateController.stateDelayTimer[ (int)PlayerStateController.playerStates.jump] = 0.0f;
            break;

        case PlayerStateController.playerStates.kill:
            // kill 상태에서 넘어갈 수 있는 상태는 부활이다.
            if(newState == PlayerStateController.playerStates.resurrect)
                returnVal = true;
            else
                returnVal = false;
            break;

        case PlayerStateController.playerStates. resurrect :
            // 부활 상태에서 넘어갈 수 있는 상태는 idle 상태이다.
            if(newState == PlayerStateController.playerStates.idle)
                returnVal = true;
            else
                returnVal = false;
            break;

        case PlayerStateController.playerStates.firingWeapon:
            returnVal = true;
            break;
        }
        return returnVal;
    }
    // Compare the desired new state against the current, and see if we are
    // allowed to change to the new state. This is a powerful system that ensures
    // we only allow the actions to occur that we want to occur.
    bool checkForValidStatePair(PlayerStateController.playerStates newState)
    {
        bool returnVal = false;

        // Compare the current against the new desired state.
        switch (currentState)
        {
        case PlayerStateController.playerStates.idle:
            // Any state can take over from idle.
            returnVal = true;
            break;

        case PlayerStateController.playerStates.left:
            // Any state can take over from the player moving left.
            returnVal = true;
            break;

        case PlayerStateController.playerStates.right:
            // Any state can take over from the player moving right.
            returnVal = true;
            break;

        case PlayerStateController.playerStates.jump:

            if (newState == PlayerStateController.playerStates.landing || newState == PlayerStateController.playerStates.kill || newState == PlayerStateController.playerStates.continueGame || newState == PlayerStateController.playerStates.takeDamage)
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.landing:
            // The only state that can take over from landing is idle, left or right movement.
            if (
                newState == PlayerStateController.playerStates.left ||
                newState == PlayerStateController.playerStates.right ||
                newState == PlayerStateController.playerStates.idle
                )
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.falling:
            // The only states that can take over from falling are landing or kill
            if (
                newState == PlayerStateController.playerStates.landing ||
                newState == PlayerStateController.playerStates.kill ||
                newState == PlayerStateController.playerStates.continueGame
                )
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.kill:
            // The only state that can take over from kill is resurrect
            if (newState == PlayerStateController.playerStates.resurrect)
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.resurrect:
            // The only state that can take over from Resurrect is Idle
            if (newState == PlayerStateController.playerStates.idle)
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.firingWeapon:
            returnVal = false;
            break;

        case PlayerStateController.playerStates.attack:
            returnVal = false;
            break;

        case PlayerStateController.playerStates.slide:
            returnVal = false;
            break;

        case PlayerStateController.playerStates.takeDamage:
            if (PlayerStateController.playerStates.kill == newState || newState == PlayerStateController.playerStates.continueGame)
            {
                returnVal = true;
            }
            else
            {
                returnVal = false;
            }
            break;

        case PlayerStateController.playerStates.continueGame:
            returnVal = true;
            break;
        }
        return(returnVal);
    }
Example #23
0
    // onStateChange는 게임 코드의 어디서든 플레이어의 상태를 변경하면 호출된다
    public void onStateChange(PlayerStateController.playerStates newState)
    {
        // 현재 상태와 새로운 상태가 동일하면 중단 - 이미 지정된 상태를 바꿀 필요가 없다.
        if(newState == currentState)
            return;

        // 새로운 상태를 중단시킬 특별한 조건이 없는지 검증한다.
        if(checkIfAbortOnStateCondition(newState))
            return;

        // 현재의 상태가 새로운 상태로 전환될 수 있는지 확인한다. 아니면 중단.
        if(!checkForValidStatePair(newState))
            return;

        // 여기까지 도달했다면 이제 상태 변경이 허용된다는 것을 알 수 있다.
        // 새로운 상태가 무엇인지에 따라 필요한 동작을 하게 하자.
        switch(newState)
        {
        case PlayerStateController.playerStates.idle:
            playerAnimator.SetBool("Walking", false);
            break;

        case PlayerStateController.playerStates.left:
            playerAnimator.SetBool("Walking", true);
            break;

        case PlayerStateController.playerStates.right:
            playerAnimator.SetBool("Walking", true);
            break;

        case PlayerStateController.playerStates.jump:
            if(playerHasLanded)
            {
                // jumpDirection 변수를 이용하여 플레이어가 왼쪽/오른쪽/위쪽으로 점프할지를 지정한다
                float jumpDirection = 0.0f;
                if(currentState == PlayerStateController.playerStates.left)
                    jumpDirection = -1.0f;
                else if(currentState == PlayerStateController.playerStates.right)
                    jumpDirection = 1.0f;
                else
                    jumpDirection = 0.0f;

                // 실제로 점프하는 힘을 적용한다
                GetComponent<Rigidbody2D>().AddForce(new Vector2(jumpDirection * playerJumpForceHorizontal, playerJumpForceVertical));

                playerHasLanded = false;
                PlayerStateController.stateDelayTimer[ (int)PlayerStateController.playerStates.jump] = 0f;
            }
            break;

        case PlayerStateController.playerStates.landing:
            playerHasLanded = true;
            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump]= Time.time + 0.1f;
            break;

        case PlayerStateController.playerStates.falling:
            PlayerStateController.stateDelayTimer[ (int)PlayerStateController.playerStates.jump] = 0.0f;
            break;

        case PlayerStateController.playerStates.kill:
            break;

        case PlayerStateController.playerStates.resurrect:
            transform.position = playerRespawnPoint.transform.position;
            transform.rotation = Quaternion.identity;
            break;

        case PlayerStateController.playerStates.firingWeapon:
            // 총알 오브젝트를 만든다
            GameObject newBullet = (GameObject)Instantiate(bulletPrefab);

            // 총알의 시작 위치를 설정한다
            newBullet.transform.position = bulletSpawnTransform.position;

            // 새 오브젝트의 PlayerBulletController 컴포넌트를 할당해서 몇 가지 데이터를 지정할 수 있다
            PlayerBulletController bullCon = newBullet.GetComponent<PlayerBulletController>();

            // 플레이어 오브젝트를 지정한다
            bullCon.playerObject = gameObject;

            // 총알 발사!
            bullCon.launchBullet();

            // 총알이 발사되고 나면 플레이어의 상태를 이전 상태로 되돌린다
            onStateChange(currentState);

            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.firingWeapon] = Time.time + 0.25f;
            break;
        }

        // 현재의 상태를 이전 상태로 저장해 둔다
        previousState = currentState;

        // 최종적으로 새로운 상태를 플레이어 오브젝트에 할당한다.
        currentState = newState;
    }
Example #24
0
    public void onStateChange(PlayerStateController.playerStates newState)
    {
        if (newState == currentState)
        {
            return;
        }
        // Comprovar que no hi hagi condicions per abortar l'estat
        if (checkIfAbortOnStateCondition(newState))
        {
            return;
        }

        if (!checkForValidStatePair(newState))
        {
            return;
        }
        Debug.Log(newState + ", current: " + currentState);
        rb2D = GetComponent <Rigidbody2D>();

        switch (newState)
        {
        case PlayerStateController.playerStates.idle:
            playerAnimator.SetBool("Walking", false);
            break;

        case PlayerStateController.playerStates.left:
            playerAnimator.SetBool("Walking", true);
            break;

        case PlayerStateController.playerStates.right:
            playerAnimator.SetBool("Walking", true);
            break;

        case PlayerStateController.playerStates.jump:

            if (playerHasLanded)
            {
                if (right)
                {
                    if (playerJumpStrongY < 0)
                    {
                        playerJumpStrongY = playerJumpStrongY * -1f;
                    }
                    rb2D.AddForce(new Vector2(playerJumpStrongY, playerJumpStrongX));
                }
                else
                {
                    if (playerJumpStrongY < 0)
                    {
                        rb2D.AddForce(new Vector2(playerJumpStrongY, playerJumpStrongX));
                    }
                    else
                    {
                        playerJumpStrongY = playerJumpStrongY * -1f;
                        rb2D.AddForce(new Vector2(playerJumpStrongY, playerJumpStrongX));
                    }
                }
            }

            playerHasLanded = false;
            Debug.Log("landing = " + playerHasLanded);
            break;

        case PlayerStateController.playerStates.landing:
            // Debug.Log("Landed " + playerHasLanded);
            playerHasLanded = true;
            //  Debug.Log("Landed " + playerHasLanded);
            break;

        case PlayerStateController.playerStates.falling:
            break;

        case PlayerStateController.playerStates.kill:
            break;

        case PlayerStateController.playerStates.resurrect:

            transform.position = playerRespawnPoint.transform.position;
            transform.rotation = Quaternion.identity;
            rb2D.velocity      = Vector2.zero;

            break;

        case PlayerStateController.playerStates.firingWeapon:
            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.firingWeapon] = Time.time + 0.25f;
            GameObject newBullet = (GameObject)Instantiate(bulletPrefab);
            newBullet.transform.position = bulletSpawnTransform.position;
            PlayerBulletController bullCon = newBullet.GetComponent <PlayerBulletController>();
            bullCon.playerObject = gameObject;
            bullCon.launchBullet();
            onStateChange(currentState);
            break;

        case PlayerStateController.playerStates.firingWeapon2:
            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.firingWeapon2] = Time.time + 0.25f;
            GameObject newBullet2 = (GameObject)Instantiate(bulletPrefab2);
            newBullet2.transform.position = bulletSpawnTransform.position;
            PlayerBulletController2 bullCon2 = newBullet2.GetComponent <PlayerBulletController2>();
            bullCon2.playerObject = gameObject;
            bullCon2.launchBullet();
            onStateChange(currentState);
            break;
        }
        previousState = currentState;
        currentState  = newState;
    }
Example #25
0
 void onPlayerStateChange(PlayerStateController.playerStates newState)
 {
     currentPlayerState = newState;
 }
Example #26
0
 private void onPlayerStateChange(PlayerStateController.playerStates newState)
 {
     currentPlayerState = newState;
     Debug.Log(currentPlayerState.ToString());
 }