private void InitialiseFSM() { _fsm = new FSM.FSM(); State idleState = new IdleState(this); State rollingState = new RollingState(this); State mountedState = new MountedState(this); _fsm.AddTransition(idleState, rollingState, () => { return(_currentHeading != Vector3.zero); }); _fsm.AddTransition(rollingState, idleState, () => { return(_currentHeading == Vector3.zero); }); _fsm.AddTransition(idleState, mountedState, () => { if (Input.GetKeyDown(KeyCode.F)) { return(EnterGolem()); } return(false); }); _fsm.AddTransition(mountedState, idleState, () => { return(Input.GetKeyDown(KeyCode.F)); }); _fsm.SetDefaultState(idleState); }
void RollingMovementUpdate() { this.rollEnumerator.MoveNext(); if (this.rollEnumerator.Current.HasValue) { this.transform.rotation = Quaternion.Euler(0, 0, (float)this.rollEnumerator.Current); } else { this.rollingState = RollingState.Flying; } }
/***************************************************** * HASH METHODS *****************************************************/ /// <summary> /// a rolling hash, based on the Adler checksum. By using a rolling hash /// we can perform auto resynchronisation after inserts/deletes /// /// internally, h1 is the sum of the bytes in the window and h2 /// is the sum of the bytes times the index /// /// h3 is a shift/xor based rolling hash, and is mostly needed to ensure that /// we can cope with large blocksize values /// </summary> /// <param name="c">The c.</param> /// <returns>Hash value</returns> private static uint roll_hash(RollingState roll_state, byte c) { roll_state.h2 -= roll_state.h1; roll_state.h2 += (uint)ROLLING_WINDOW * c; roll_state.h1 += c; roll_state.h1 -= roll_state.window[roll_state.n % ROLLING_WINDOW]; roll_state.window[roll_state.n % ROLLING_WINDOW] = c; roll_state.n++; /* The original spamsum AND'ed this value with 0xFFFFFFFF which * in theory should have no effect. This AND has been removed * for performance (jk) */ roll_state.h3 = (roll_state.h3 << 5); //& 0xFFFFFFFF; roll_state.h3 ^= c; return(roll_state.h1 + roll_state.h2 + roll_state.h3); }
public void Awake() { Input = GetComponent <IPlayerInput>(); Anim = GetComponent <IPlayerAnimationManager>(); RollHitbox = GetComponent <PlayerRollAttackHitbox>(); DiveHitbox = GetComponent <PlayerDiveAttackHitbox>(); Motor = GetComponent <PlayerMotor>(); Walking = new WalkingState(this); StandardJumping = new StandardJumpingState(this); DoubleJumping = new DoubleJumpingState(this); RollJumping = new RollJumpingState(this); SideFlipJumping = new SideFlipJumpingState(this); FreeFall = new FreeFallState(this); WallSliding = new WallSlidingState(this); WallJumping = new WallJumpingState(this); Rolling = new RollingState(this); Diving = new DivingState(this); Bonking = new BonkingState(this); GrabbingLedge = new GrabbingLedgeState(this); _allStates = new[] { Walking, FreeFall, WallSliding, WallJumping, Rolling, Diving, Bonking, GrabbingLedge }; // Start in FreeFall ChangeState(FreeFall); Debug.Log("Jump speed: " + PlayerConstants.STANDARD_JUMP_VSPEED); }
void FlyingMovementUpdate() { // Turns based on user input. +1 for positive rotation (left), -1 for negative rotation (right), 0 for no change int turnDirection; turnDirection = (Input.GetKey(KeyCode.LeftArrow) ? 1 : 0) - (Input.GetKey(KeyCode.RightArrow) ? 1 : 0); if (turnDirection != 0) { this.transform.Rotate(Vector3.forward, 360 * this.turnRate * Time.fixedDeltaTime * turnDirection); if (Mathf.Abs(this.ZRotation) > this.turnLimit) { this.transform.rotation = Quaternion.Euler(0, 0, turnDirection * this.turnLimit); } } else { turnDirection = (int)-Mathf.Sign(this.ZRotation); this.transform.Rotate(Vector3.forward, 360 * this.centeringRate * turnRate * Time.fixedDeltaTime * turnDirection); if (turnDirection * this.ZRotation > 0) { this.transform.rotation = Quaternion.Euler(0, 0, 0); } turnDirection = 0; } // Determines x-velocity based on current rotation, drifting left or right according to angle. if (Time.fixedTime >= this.nextRollTime && turnDirection != 0 && Input.GetKeyDown(KeyCode.Space)) { this.rollingState = RollingState.Rolling; this.rigidbody2D.velocity = -turnDirection * this.speed * Vector2.right; this.rollEnumerator = this.Roll(turnDirection).GetEnumerator(); this.nextRollTime = Time.fixedTime + this.rollCooldown; } else { this.rigidbody2D.velocity = -this.ZRotation / this.turnLimit * this.speed * Vector2.right; } }
/// <summary> /// Reset the state of the rolling hash and return the initial rolling hash value /// </summary> /// <returns>Hash value</returns> private static uint roll_reset(out RollingState roll_state) { roll_state = new RollingState(); return(0); }
// Start is called before the first frame update void Start() { this.halfWidth = this.spriteRenderer.bounds.size.x / 2; this.rollingState = RollingState.Flying; this.nextRollTime = 0; }