void CSPhysXObject_Character::frame(const float &elapsedtime) { float et = elapsedtime; // add the gravity each frame PxVec3 disp(0,0,0); if (!m_Jumping) disp = PxVec3(0, -32.0f, 0); vector3df tf = getTotalForce(); m_TotalForce = vector3df(0, 0, 0); disp += PxVec3(tf.X, tf.Y, tf.Z); disp.y += getHeight(et); PxU32 collisionFlags = moveCharacter(disp, et, 0); if (collisionFlags & PxControllerFlag::eCOLLISION_DOWN) stopJump(); }
/* * This updates the planes offsets and frame * * @param input is used to check for player input * @param deltaTime is used to update the frame of the plane */ void Plane::update(Input* input, int deltaTime) { //std::cout << "Delta is: " << deltaTime << std::endl; //If player press the space key then make the plane jump if (input->isKeyHit(SDLK_SPACE)) { startJump(); } //If plane is falling if (motion_ == MOTION_Falling) { setVelocityY(getVelocityY() + GRAVITY * (deltaTime/1000.0f)); setOffsetY(getOffsetY() + getVelocityY()); //Check if the plane has reach the bottom maximum bounds if (getOffsetY() >= SPRITE_MAX_BOTTOM) { setOffsetY(getOffsetY() - getVelocityY()); } } //Else if plane is jumping else if (motion_ == MOTION_Jumping) { jump_.update(deltaTime); if (jump_.getJumpTimeRemaining() > 0) { //Set the velocity setVelocityY( getVelocityY() + JUMP_VELOCITY); setOffsetY(getOffsetY() - getVelocityY()); //Check if the plane has reach the top maximum bounds if (getOffsetY() <= SPRITE_MAX_TOP) { setOffsetY(getOffsetY() + getVelocityY()); //Stop jumping stopJump(); } } //Max jump is reach else { stopJump(); } } elapseTime_ += deltaTime; if (elapseTime_ > FPS) { frameCounter_++; if (frameCounter_ == 3) { frameCounter_ = 0; } elapseTime_ = 0; } //Update the puff cloud puffCloud_.setOffsetY(getOffsetY() + 10.0f); puffCloud_.update(deltaTime); //Shift the collision boxes shiftCollisionBoxes(); }