### Gaming: Player States problem

Hi, I am in the middle of working on a game right now utilizing the DirectX9 library. I am working on my player first and was doing good with the button presses until I switch over to using an enum called player_state to track all my players actions and enum DIRECTIONS to track if player is facing RIGHT or LEFT. Values in the enum player_state were STANDING = 0, STANDING_FIRE = 1, RUNNING = 2, RUNNING_FIRE = 3, JUMPING, JUMPING_FIRE, FALLING, and FALLING_FIRE (etc with their = values)

So originally I was using a couple of bools to track the states like bool player_jumping, player_falling.
I wrote my player jumping like

 ``123456789101112131415161718192021222324`` ``````if (button pressed to jump) { if (player_jumping == false) //no double jumping player_jumping == true player y velocity is set in here to ensure they have force to jump if (player_jumping == true) player y velocity -= GRAVITY player y += y velocity if (player hits ground) player_jumping = false player_falling = false }//end player jump when button is pressed if (the jump button is not pressed but player_jumping == true) { player_falling = true continue with the vely -= GRAVITY and player y += vely if player hits ground both jumping and falling = false }//end falling ``````

but when I went to using player states and tried to do
 ``123456789101112131415161718192021222324`` ``````if (button pressed to jump) { if (player_state != JUMPING) //no double jumping player_state = JUMPING player y velocity is set in here to ensure they have force to jump if (player_state == JUMPING) player y velocity -= GRAVITY player y += y velocity if (player hits ground) player_state = STANDING }//end player jump when button is pressed if (the jump button is not pressed and (player_state == JUMPING || player_state == FALLING)) //jumping and falling because state will be changed to falling inside this "function" { player_state = FALLING continue with the vely -= GRAVITY and player y += vely if player hits player_state = STANDING }//end falling ``````

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.
I did go back through and check to make sure that nothing like y values or vely were associated with the right or left key presses. Nothing.

So my problem is that I cannot get the player to jump and fall correctly using the player_state JUMPING and FALLING. After I get these to work correctly, I think it will be easy to add firing while jumping and falling.

and when I was drawing it would look something like

if (player_state == JUMPING)
if (player_direction == RIGHT)
draw right
else if (player_direction == LEFT)
draw left

same thing for all the states because they can only be in one state at a time.

Thanks for all your help in advance!!
Topic archived. No new replies allowed.