Game Development Reference
In-Depth Information
break;
OnStateChange:
case PlayerStateController.playerStates.landing:
playerHasLanded = true;
break;
checkForValidStatePair:
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;
Now, the player can only jump if they have already landed, and the state system can
safely transition to and from the jump state.
There is one more thing to do here. With the preceding code, we can now support
the falling state of the player as well. In the PlayerColliderListener script, add
the following function:
void OnTriggerExit2D( Collider2D collidedObject)
{
switch(collidedObject.tag)
{
case"Platform":
// When the player leaves a platform, set the state as falling. If //
the player actually is not falling, this will get verified by //the
PlayerStateListener.
targetStateListener.onStateChange(PlayerStateController.
playerStates.falling);
break;
}
}
 
Search WWH ::




Custom Search