I'm having troubles with proper management of objects states.
Check out the following:
class PlayerController
{
bool canMove = true;
bool canRotate = true;
bool canShoot = true;
bool canCastAbility = true;
}
class PlayerCamera
{
bool canLookAround = true;
bool followPlayer = true;
}
class PlayerAbility
{
when used over time - PlayerCamera.canLookAround = false;
}
class PauseScreen
{
when game is paused - PlayerCamera.canLookAround != PlayerCamera.canLookAround;
}
You might already see what's the problem here - When we are NOT using our ability and we want to pause the game, "canLookAround" will be properly set to false. Although when we are using our ability and at the same time we want to pause the game, "canLookAround" will be set to true - which is incorrect.
I believe I dont have to add that this way of managing states looks terrible and it's super easy to get lost around all of these "canDoSomething" booleans. Not only Player have that kind of booleans, a lot of scripts inside the project are affected by this kind of poor states management and it's causing a lot of frustration and this feeling of being lost.
After all you end up with some kind of abomination like this:
void PauseGame(){
enemy.canMove = false;
enemy.canShoot = false;
player.canMove = false;
player.canShoot = false;
player.canCastAbility = false;
NPCs.canMove = false;
etc...
}
Apart of having enumerator holding current state of an object, what would be a proper way of handling states like these ?
Is there any design pattern that handles this problem well? Is there any principle that has to be followed on the architecture level of the project in order to handle states easily?
Please share your experiences with me, thank you.
Aucun commentaire:
Enregistrer un commentaire