// Start is called before the first frame update void Start() { _CurrentJumpState = eJumpState.Landed; _BoxCollider = GetComponent <BoxCollider2D>(); _Rigidbody2D = GetComponent <Rigidbody2D>(); _ColliderSizeY = _BoxCollider.size.y; }
/// <summary> /// 更新高度 /// </summary> void UpdateHeight() { if (!mIsHover) { if (mYSpeed < gravity) { //加速下落的实现a*2,normal*1 if (mFallDown == eFallDown.normal) { mYSpeed += gravity * Time.deltaTime; } else if (mFallDown == eFallDown.doubleGravity) { mYSpeed += gravity * Time.deltaTime * 5f; } //mYSpeed+=gravity*Time.deltaTime*2f; if (mYSpeed < 0f) { isCanLand = false; } else { isCanLand = true; } } else if (mYSpeed > gravity) { mYSpeed = gravity; } if (mCC) { localYOffset = -mYSpeed * Time.deltaTime; if (mJumpState == eJumpState.FirstJump || mJumpState == eJumpState.DoubleJump) { if (mCC.isGrounded && isCanLand) { mA.SetBool("land", true); mJumpState = eJumpState.NoneJump; } } if (mFallDown == eFallDown.doubleGravity) //落地后清除加速下降状态 { if (mCC.isGrounded) { mFallDown = eFallDown.normal; mJumpState = eJumpState.NoneJump; mA.SetBool("land", true); } } } } else //滞留空中 { localYOffset = 0f; } }
private void sendJumpKeyDown() { if (MyJumpStyle > 10 & MyJumpStyle < 15) { SendMessage(MyHwnd, WM_KEYDN, WpSHIFTdn, LpSHIFTdn); } SendMessage(MyHwnd, WM_KEYDN, WpDdn, LpDdn); SendMessage(MyHwnd, WM_KEYDN, MyWpDirDn, MyLpDirDn); JumpState = eJumpState.KEY_WAIT; return; }
void KeyPressTimer_Tick(object sender, EventArgs e) { if (JumpState == eJumpState.IDLE) { stopKeyPressTimer(); } else { JumpState = eJumpState.KEY_UP; continueKeyPress(); } }
void Jump() { if (mJumpState == eJumpState.NoneJump) { mYSpeed = -10f; mJumpState = eJumpState.FirstJump; mA.SetTrigger("jump"); mA.SetBool("land", false); } else if (mJumpState == eJumpState.FirstJump) { mYSpeed = -10f; mJumpState = eJumpState.DoubleJump; mA.SetTrigger("jump"); mA.SetBool("land", false); } }
public void CheckSwipe() { if (Input.touches.Length > 0) { Touch t = Input.GetTouch(0); if (t.phase == TouchPhase.Began) { //save began touch 2d point firstPressPos = new Vector2(t.position.x, t.position.y); } else if (t.phase == TouchPhase.Ended) { //save ended touch 2d point secondPressPos = new Vector2(t.position.x, t.position.y); //create vector from the two points currentSwipe = new Vector3(secondPressPos.x - firstPressPos.x, secondPressPos.y - firstPressPos.y); //normalize the 2d vector currentSwipe.Normalize(); //swipe upwards if (currentSwipe.y > 0) { if (_CurrentJumpState == eJumpState.Landed) { _CurrentJumpState = eJumpState.Rising; SoundManager.PlaySound("Jump"); IsJumping = true; AnimatorLeo.SetBool("Jumping", true); AnimatorLeo.SetBool("Falling", false); Jump(); } } else { _Crouch = true; _BoxCollider.size = new Vector2(_BoxCollider.size.x, _ColliderSizeY / 2); StartCoroutine(GetUp(1f)); } } } }
private eJumpState UpdateJumpsState() { eJumpState ret = eJumpState.Landed; if (_Rigidbody2D.velocity.y > 0.0000001) { ret = eJumpState.Rising; } else if (_Rigidbody2D.velocity.y < 0) { ret = eJumpState.Falling; } else if (_CurrentJumpState == eJumpState.Falling && Mathf.Abs(_Rigidbody2D.velocity.y) < 0.0000001) { ret = eJumpState.Landed; } return(ret); }
public bool startKeyPress(int JumpStyle, int JumpPower) { if (JumpState == eJumpState.IDLE) { MyJumpStyle = JumpStyle; if (JumpStyle == 11 | JumpStyle == 21) { MyWpDirDn = WpUPdn; MyLpDirDn = LpUPdn; MyLpDirUp = LpUPup; } else if (JumpStyle == 12 | JumpStyle == 22) { MyWpDirDn = WpDOWNdn; MyLpDirDn = LpDOWNdn; MyLpDirUp = LpDOWNup; } else if (JumpStyle == 13 | JumpStyle == 23) { MyWpDirDn = WpLEFTdn; MyLpDirDn = LpLEFTdn; MyLpDirUp = LpLEFTup; } else if (JumpStyle == 14 | JumpStyle == 24) { MyWpDirDn = WpRIGHTdn; MyLpDirDn = LpRIGHTdn; MyLpDirUp = LpRIGHTup; } else { WriteToChat("Tank Commander: ", "Input Error on startKeyPress!"); } JumpState = eJumpState.KEY_DN; continueKeyPress(); startKeyPressTimer(JumpPower); return(true); } continueKeyPress(); return(false); }
// Update is called once per frame void Update() { CheckSwipe(); _CurrentJumpState = UpdateJumpsState(); AnimatorLeo.SetBool("Crouching", _Crouch); // Landing check if (_CurrentJumpState == eJumpState.Landed) { IsJumping = false; AnimatorLeo.SetBool("Jumping", false); AnimatorLeo.SetBool("Falling", false); } else if (_CurrentJumpState == eJumpState.Falling) { AnimatorLeo.SetBool("Falling", true); } }