public PlayerState GetInputState(float dt) { if (!controlDisabled) { _inputState.GetInputState(); } PlayerState state = new PlayerState(_currentState, _inputState); bool inAttack = state.CheckState(PlayerFrameState.ATTACK_CANCELLABLE) || state.CheckState(PlayerFrameState.ATTACK_NONCANCELLABLE); if (inAttack) { state += anim.GetFrameMovement(dt); //produce hit boxes here... World.instance.UpdateWorldHitboxes(anim.GetFrameHitbox(hurtbox)); //state += anim.GetFrameHitboxRelativeToCharacter(); } else { bool inAir = state.CheckState(PlayerFrameState.AERIAL); bool inNeutral = !inAttack && !state.CheckState(PlayerFrameState.HITSTUN) && !state.CheckState(PlayerFrameState.BLOCKSTUN); if (!inAir && !inAttack && inNeutral) { if (_inputState.y < 0) { state.AddState(PlayerFrameState.CROUCHING); _currentAttackAnimation = GetCrouchingButtons(); if (_currentAttackAnimation != "") { state.AddState(PlayerFrameState.ATTACK_NONCANCELLABLE); } state.stateData.velocity = Vector2.zero; } else { state.RemoveState(PlayerFrameState.CROUCHING); _currentAttackAnimation = GetStandingGroundedButtons(); if (_currentAttackAnimation != "") { state.AddState(PlayerFrameState.ATTACK_NONCANCELLABLE); state.stateData.velocity = Vector2.zero; } else { Vector2 velocity = GetGroundMovement(_inputState); state.stateData.velocity = velocity; } } } else { _currentAttackAnimation = GetAerialButtons(); if (_currentAttackAnimation != "") { state.AddState(PlayerFrameState.ATTACK_NONCANCELLABLE); } } } return(state); }
//should this be done before the animation? public void ResolveState(PlayerState unresolvedState) { PlayerState lastFrame = _currentState; PlayerState thisFrame = unresolvedState; bool grounded = (thisFrame.stateData.Collisions & CollisionState.BOTTOM) != 0; bool lastFrameGrounded = (lastFrame.stateData.Collisions & CollisionState.BOTTOM) != 0; bool justLanded = grounded && lastFrame.CheckState(PlayerFrameState.AERIAL); bool beganAerial = !grounded && !lastFrame.CheckState(PlayerFrameState.AERIAL); //check animator to see if something has finished bool startedAttack = anim.InAttackAnimation() || thisFrame.IsAttacking(); //check animator to see if something has finished bool endedAttack = !anim.InAttackAnimation() && lastFrame.IsAttacking(); if (endedAttack) { _currentAttackAnimation = ""; thisFrame.RemoveState(PlayerFrameState.ATTACK_CANCELLABLE); thisFrame.RemoveState(PlayerFrameState.ATTACK_NONCANCELLABLE); } if (thisFrame.stateData.velocity.x != 0) { thisFrame.AddState(PlayerFrameState.MOVING_HORIZ); } else { thisFrame.RemoveState(PlayerFrameState.MOVING_HORIZ); } if (thisFrame.stateData.velocity.y != 0) { thisFrame.AddState(PlayerFrameState.MOVING_VERT); } else { thisFrame.RemoveState(PlayerFrameState.MOVING_HORIZ); } if (!grounded) { thisFrame.AddState(PlayerFrameState.AERIAL); } else { thisFrame.RemoveState(PlayerFrameState.AERIAL); } if (lastFrame.CheckState(PlayerFrameState.HITSTUN) || lastFrame.CheckState(PlayerFrameState.BLOCKSTUN)) { thisFrame.nextActionDelay--; if (thisFrame.nextActionDelay == 0) { thisFrame.RemoveState(PlayerFrameState.HITSTUN); thisFrame.RemoveState(PlayerFrameState.BLOCKSTUN); } } _lastState = _currentState; _currentState = thisFrame; entityPhysics.UpdateState(_currentState.stateData); //Debug.Log(PrintState()); }