Game Development Reference
In-Depth Information
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;
}
// 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.
playerStatesnewState)
{
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;
}
}
 
Search WWH ::




Custom Search