/** * The first version, using DP method and recursive style, but will exceed * time limit. */ bool canJump(int A[], bool canReach[], int n, int curPos){ if( curPos >= n ) // out of range return false; if( curPos == n-1 ) // reach last postion return true; if( !canReach[curPos] ) // can not reach from current position return false; int curMaxStep = A[curPos]; if( curMaxStep < 1 ){ canReach[curPos] = false; return false; } bool can = false; for( int i = 1; i <= curMaxStep; i++ ){ can = can || canJump(A, canReach, n, curPos + i); if( can ) break; } if( can ) return true; else{ canReach[curPos] = false; return false; } }
void CPlayerBase::UpdateJumpState() { PROFILE_FUNCTION("update jump state base"); if (!canJump()) return; if (controller->JumpButtonBecomesPressed()) { logic_manager->throwEvent(logic_manager->OnJump, ""); Jump(); } }
void btKinematicController::jump () { if (!canJump()) return; m_verticalVelocity = m_jumpSpeed; m_wasJumping = true; }
void PlateformerPhysic::jump() { if(canJump()) { { state[PlateformerPhysic::Jumping] = true; speed.y = -jump_power; } } }
void JumpHolder::postCanJumpNow(float dt) { --minTimeNeedWaitBeforeJump; if (canJump()) { // 通知可以jump了 CCDirector::sharedDirector()->getScheduler()->unscheduleSelector(schedule_selector(JumpHolder::postCanJumpNow), this); CCNotificationCenter::sharedNotificationCenter()->postNotification(MSG_JUMP_CAN_JUMP,NULL); } }
void CCharacterController::jump() { if (!canJump()) return; SetJumpSpeed((float)m_hEntity->JumpStrength()); m_hEntity->SetGlobalVelocity(ToTVector(GetUpVector()) * m_flJumpSpeed + m_hEntity->GetGlobalVelocity()); m_hEntity->SetGroundEntity(nullptr); }
void DynamicCharacterController::jump () { if (!canJump()) return; btTransform xform; m_rigidBody->getMotionState()->getWorldTransform (xform); btVector3 up = xform.getBasis()[1]; up.normalize (); btScalar magnitude = (btScalar(1.0)/m_rigidBody->getInvMass()) * btScalar(8.0); m_rigidBody->applyCentralImpulse (up * magnitude); }
int main(int arg, char *argv[]) { // insert code here... printf("LeetCode 055 Jump Game, C ...\n\n"); //int nums[] = {2,3,1,1,4}; int nums[] = {3,2,1,0,4}; int numsSize = sizeof(nums)/sizeof(int); printf("%s\n", canJump(nums, numsSize) ? "true" : "false"); return 0; }
void duCharacter::jump() { if (!canJump()) return; if (!m_isJumping) { m_isJumping = true; btVector3 up = btVector3(0.f, 0.f, 1.f); btScalar magnitude = btScalar(m_jumpStrength) / m_rigidBody->getInvMass(); m_rigidBody->applyCentralImpulse (up * magnitude); } }
void bulletCharacterController::jump () { if (!canJump()) return; m_verticalVelocity = m_jumpSpeed; #if 0 currently no jumping. btTransform xform; m_rigidBody->getMotionState()->getWorldTransform (xform); btVector3 up = xform.getBasis()[1]; up.normalize (); btScalar magnitude = (btScalar(1.0)/m_rigidBody->getInvMass()) * btScalar(8.0); m_rigidBody->applyCentralImpulse (up * magnitude); #endif }
int main() { vector<int> vec = {5,8,3,0,6,7,9,6,3,4,5,2,0,6,2,6,7,10,8,0}; cout << canJump(vec) << endl; }