|
|
|
|
but some problems that occured with using the enum STATES was that while jumping, if I pressed right or left, the player would move all the way to the top of the screen and stay there until I was only pressing the jump button. If I was only pressing the jump button, the player would jump like he was supposed to , but if I released the jump key, the player would not continue his fall back down like supposed to. So the jump was only working if I continuously held the button. |
if(directional_button_pressed)
part of your program. if I pressed right or left, the player would move all the way to the top of the screen and stay there until I was only pressing the jump button |
if(directional_button_pressed)
part of your program, you're setting a value to the player_state enum (thus preventing it from following it's intended behavior as described in your original post), otherwise you wouldn't be getting this behavior. Make sure that the vertical position is calculated first (by subtracting gravity from y_velocity etc) and that the if(directional_button_pressed)
part only changes player_direction and adds the potential horizontal velocity if pressed while jumping -- but does not affect player_state.
|
|
|
|
if (player_state!=JUMPING)
determines events where you are either on the ground and stay on the ground, or events where you are on the ground but enter the jumping state for the first time (since you last where on the ground). else if (player_state==JUMPING)
part determines events where keys are pressed while the character is already in mid-air -- already in a jumping state.
|
|
enum STATE { STANDING = 0, STANDING_FIRE = 1, MOVING = 2, MOVING_FIRE = 3, JUMPING = 4, JUMPING_FIRE = 5, FAILING = 6, FAILING_FIRE = 7 }; enum DIRECTION { LEFT = 0, RIGHT = 1 //more... }; ........................ |
enum STATE { STANDING = 0, MOVING = 1, JUMPING = 2, FAILING = 3 }; enum DIRECTION { LEFT = 0, RIGHT = 1 //more... }; bool bFire; |
|
|
|
|
|
|
|
|