Original Post
Say I have a player class. This player is made up of a few things: A bounding box, a moveable entity, and animations.
When this player moves left, what is actually happening is a force pushing the moveable entity in the negative direction. A bounding box detects any on-coming obstacles. On the case of contact, the force applied needs to be halted immediately. Also, the animation state knows that RUN_LEFT should be playing as the player moves.
Cool.
But what about when the player jumps? The animation consists of an elaborate transition from a squat to an upright launch and finally the "in the air jumping" pose is reached. During this time of the animation, the user cannot make the player move or do anything else. When the player is "in the air" he can do something again.
Okay.
I thought about breaking up the player into pieces, or states. One state consists of the update moving left and checking for all left-stuff. Another state for moving right. Another state for mid-jump, and when the jump is completed; a final state for being in the air ( abs(Y velocity) > 0 && no_contact ).
If each state is represented as a class that the player can "be in", would this be over kill? The pros would be that it will 1) be easy to debug. We'd know exactly what state it is in if the logic breaks. 2) The pre-jump animation would play and move onto the next state satisfying the condition of the player being unable to do anything until this animation is completed and 3) the player's logic function doUpdate() will be very clean and not cluttered with flags.
The cons: More classes. Perhaps overkill.
If I choose to break the animation system into states instead, the player class would still be a tad bloated (but not too much) and I'd still have to clutter it with animation checks (i.e. if(inputRecieved() && !animation->is(PLAYER_PRE_JUMP) then ... )
So overkill? Or is there a better way to do this?
Thanks!
When this player moves left, what is actually happening is a force pushing the moveable entity in the negative direction. A bounding box detects any on-coming obstacles. On the case of contact, the force applied needs to be halted immediately. Also, the animation state knows that RUN_LEFT should be playing as the player moves.
Cool.
But what about when the player jumps? The animation consists of an elaborate transition from a squat to an upright launch and finally the "in the air jumping" pose is reached. During this time of the animation, the user cannot make the player move or do anything else. When the player is "in the air" he can do something again.
Okay.
I thought about breaking up the player into pieces, or states. One state consists of the update moving left and checking for all left-stuff. Another state for moving right. Another state for mid-jump, and when the jump is completed; a final state for being in the air ( abs(Y velocity) > 0 && no_contact ).
If each state is represented as a class that the player can "be in", would this be over kill? The pros would be that it will 1) be easy to debug. We'd know exactly what state it is in if the logic breaks. 2) The pre-jump animation would play and move onto the next state satisfying the condition of the player being unable to do anything until this animation is completed and 3) the player's logic function doUpdate() will be very clean and not cluttered with flags.
The cons: More classes. Perhaps overkill.
If I choose to break the animation system into states instead, the player class would still be a tad bloated (but not too much) and I'd still have to clutter it with animation checks (i.e. if(inputRecieved() && !animation->is(PLAYER_PRE_JUMP) then ... )
So overkill? Or is there a better way to do this?
Thanks!