void PlayerController::jump() { if (isOnGround()) { m_velocity.z += jumpSpeed; } }
void wp_puck_proj::updateSprite() { if (!isOnGround() && wasOnGround()) { vy = -150; //jump up to clear a small gap } if (getx() < -16 || getx() > 271) //out of the screen now, dont wanna see the death FX either { destroy(); return; } else if (y >= (s32)SCREENH+4096) //fell out of bottom so make a splash, go low enough to hide death FX { #ifdef __WITHSOUND playSound(&owner->gm->smallSplash); #endif //GFX warning! u8 f[3] = {13, 14, 15}; vector<u8> temp(f, f+3); sm->createSingleFireSprite(owner->gm->FXSprite.palleteID, owner->gm->FXSprite.spriteData, temp, TICKSPERFRAME*2, getx(), gameManager::MALLOWYPOS, OBJ_SIZE_32X32, 16, 16); destroy(); return; } massObject::updateSprite(); }
sf::Vector2f cHero::getMovement(const sf::Input & theInput, sf::Clock & jumpClock) { sf::Vector2f movementVector; xSpeed = 0; ySpeed = 0; // horizontal movement if (theInput.IsKeyDown(sf::Key::Left)) { xSpeed += -5; xAccel += -.2; } else if (theInput.IsKeyDown(sf::Key::Right)) { xSpeed += 5; xAccel += .2; } // vertical movement if (theInput.IsKeyDown(sf::Key::Up)) { if (isOnGround()) { jumpClock.Reset(); //ySpeed = -8; } if (jumpClock.GetElapsedTime() < .3) { yAccel -= .12 / (jumpClock.GetElapsedTime()); ySpeed = 30 * (jumpClock.GetElapsedTime() - .3); } } if (isOnGround()) { yAccel = 0; if (xAccel > .2) xAccel -= .05; else if (xAccel < -.2) xAccel += .05; } else { yAccel += 1 + (jumpClock.GetElapsedTime() / 20); } movementVector.x = xSpeed + xAccel; movementVector.y = ySpeed + yAccel; return movementVector; }
//----------------------------------------------------------------------------- // // VActorPhysicsController::isInAir(); // // Is the Actor in the Air? // //----------------------------------------------------------------------------- const bool VActorPhysicsController::isInAir( void ) { // Valid Objects? if ( !isValidObject() ) { // No. return false; } // In Air? return ( !isOnGround() && !isInWater() ); }
void PlayerController::updateVelocity(const double deltaT) { // Change in velocity from previous frame glm::vec3 deltaV; // True if and onyl if the player is decelerating while moving in the given direction bool axPosDec = false; // Positive axial (forward-backward) bool axNegDec = false; // Negative axial bool latPosDec = false; // Positive lateral (right in egocentric coordinates) bool latNegDec = false; // Negative lateral (left) // Forward-backward if ((m_axial == AxialDirection::Forward && m_velocity.y < maxSpeed) || (axNegDec = (m_axial == AxialDirection::Null && m_velocity.y < 0.0f))) { deltaV.y = acceleration * deltaT; } else if (m_axial == AxialDirection::Backward && m_velocity.y > -maxSpeed || (axPosDec = (m_axial == AxialDirection::Null && m_velocity.y > 0.0f))) { deltaV.y = -acceleration * deltaT; } // Left-right translation if ((m_lateral == LateralDirection::Right && m_velocity.x < maxSpeed) || (latNegDec = (m_lateral == LateralDirection::Null && m_velocity.x < 0.0f))) { deltaV.x = acceleration * deltaT; } else if (m_lateral == LateralDirection::Left && m_velocity.x > -maxSpeed || (latPosDec = (m_lateral == LateralDirection::Null && m_velocity.x > 0.0f))) { deltaV.x = -acceleration * deltaT; } // Update velocity m_velocity += deltaV; // Deceleration to zero if a direction key is released if ((axNegDec && m_velocity.y > 0.0f) || (axPosDec && m_velocity.y < 0.0f)) { m_velocity.y = 0.0f; } if ((latNegDec && m_velocity.x > 0.0f) || (latPosDec && m_velocity.x < 0.0f)) { m_velocity.x = 0.0f; } // Vertical deceleration, after a jump if (!isOnGround()) { m_velocity.z += gravity * deltaT; } }
/** * Updates the sprite to apply gravitational effects to it. * The sprite will accellerate downwards unless it lands on another baseable spriteObject. */ void massObject::updateSprite() { spriteObject::updateSprite(); //move sprite first wasGrounded = grounded; if (!isOnGround() && !bStasis) { vy += GRAVITY; if (vy > TERMINALVEL) vy = TERMINALVEL; checkPenetration(); } grounded = false; //is re-checked in collidingWith() later in the tick }
sf::Vector2f cMario::getMovement(void) { sf::Vector2f movementVector; if (!getIsDead()) { if (isOnGround()) { ySpeed = -8; yAccel = 0; xAccel = rand() % 4; } } yAccel += .3; movementVector.x = xSpeed + xAccel; movementVector.y = ySpeed + yAccel; return movementVector; }
void wp_gren_proj::updateSprite() { if (isOnGround()) { setBounds(2, 8, 5, -4); //bigger collision to take out neighbouring platforms for (vector<spriteObject*>::iterator it = sm->gameSprites.begin(); it != sm->gameSprites.end(); ++it) { if (dynamic_cast<floorTile*>(*it) != NULL && isColliding(*it)) { //check if the destroyed floor was under a player gameManager *gm = dynamic_cast<gameManager *>(sm); if (gm->player1->isStandingOn(*it)) gm->player1->groundDeleted(Player::CS_GRENFALL); if (gm->player2->isStandingOn(*it)) gm->player2->groundDeleted(Player::CS_GRENFALL); (*it)->destroy(); } } destroy(); return; } if (getx() < -16 || getx() > 271) //out of the screen now, dont wanna see the death FX either { destroy(); return; } else if (y >= (s32)SCREENH+4096) //fell out of bottom so make a splash, go low enough to hide death FX { #ifdef __WITHSOUND playSound(&owner->gm->smallSplash); #endif //GFX warning! u8 f[3] = {13, 14, 15}; vector<u8> temp(f, f+3); sm->createSingleFireSprite(owner->gm->FXSprite.palleteID, owner->gm->FXSprite.spriteData, temp, TICKSPERFRAME*2, getx(), gameManager::MALLOWYPOS, OBJ_SIZE_32X32, 16, 16); destroy(); return; } massObject::updateSprite(); }
task main(){ bool onramp = false; // Wait 0.1 seconds to give some time to initialize the values wait1Msec(100); getValues(); // Turn on the engines... motor[motorD] = 20; motor[motorF] = 20; // ...wait 2 seconds... //wait1Msec(2000); for (int g = 0; g<200; g++) { // 2 sec wait1Msec(10); getValues(); if(x < -60){ onramp = true; g = 2001; } } // ...and disable the engines. // Get the x, y, and z values motor[motorD] = 0; motor[motorF] = 0; getValues(); // The robot is on the ramp // So execute the isOnRamp function if(onramp) { isOnRamp(); } // The robot is on the floor // So execute the isOnGround function else {isOnGround(); } }
bool CharacterObject::canTurn() const { return isOnGround() && !jumped && isAlive() && controller->getCurrentActivity() == nullptr; }
void CharacterObject::updateCharacter(float dt) { /* * You can fire weapons while moving * * Two Modes: Moving and Action * Moving covers walking & jumping * Action covers complex things like shooting, entering vehicles etc. * * Movement animation should be handled here * If Current weapon is one handed, then it can be used while walking. * This means blending the weapon animation with the walk animation. * No weapons can be used while sprinting. * Need an "aim vector" to apply torso correction. * * If movement vector is less than some threshold, fully walk animation * (time adjusted for velocity). */ if(physCharacter) { glm::vec3 walkDir = updateMovementAnimation(dt); position = getPosition(); if (canTurn()) { rotation = glm::angleAxis(m_look.x, glm::vec3{0.f, 0.f, 1.f}); } walkDir = rotation * walkDir; if( jumped ) { if( !isOnGround() ) { walkDir = rotation * glm::vec3(0.f, jumpSpeed * dt, 0.f); } } if (isAlive()) { physCharacter->setWalkDirection(btVector3(walkDir.x, walkDir.y, walkDir.z)); } else { physCharacter->setWalkDirection(btVector3(0.f, 0.f, 0.f)); } auto Pos = physCharacter->getGhostObject()->getWorldTransform().getOrigin(); position = glm::vec3(Pos.x(), Pos.y(), Pos.z()); // Handle above waist height water. auto wi = engine->data->getWaterIndexAt(getPosition()); if( wi != NO_WATER_INDEX ) { float wh = engine->data->waterHeights[wi]; auto ws = getPosition(); wh += engine->data->getWaveHeightAt(ws); // If Not in water before // If last position was above water // Now Underwater // Else Not Underwater // Else // Underwater if( ! inWater && ws.z < wh && _lastHeight > wh ) { ws.z = wh; btVector3 bpos(ws.x, ws.y, ws.z); physCharacter->warp(bpos); auto& wt = physObject->getWorldTransform(); wt.setOrigin(bpos); physObject->setWorldTransform(wt); physCharacter->setGravity(0.f); inWater = true; } else { physCharacter->setGravity(9.81f); inWater = false; } } _lastHeight = getPosition().z; } else { updateMovementAnimation(dt); } }
glm::vec3 CharacterObject::updateMovementAnimation(float dt) { glm::vec3 animTranslate; if (motionBlockedByActivity) { // Clear any residual motion animation animator->playAnimation(AnimIndexMovement, nullptr, 1.f, false); return glm::vec3(); } // Things are simpler if we're in a vehicle if (getCurrentVehicle()) { animator->playAnimation(0, animations.car_sit, 1.f, true); return glm::vec3(); } Animation* movementAnimation = animations.idle; Animation* currentAnim = animator->getAnimation(AnimIndexMovement); bool isActionHappening = (animator->getAnimation(AnimIndexAction) != nullptr); float animationSpeed = 1.f; bool repeat = true; constexpr float movementEpsilon = 0.1f; float movementLength = glm::length(movement); if (!isAlive()) { movementAnimation = animations.ko_shot_front; repeat = false; } else if (jumped) { repeat = false; if (currentAnim == animations.jump_start && animator->isCompleted(AnimIndexMovement)) { movementAnimation = animations.jump_start; } if (isOnGround()) { if (currentAnim != animations.jump_land || !animator->isCompleted(AnimIndexMovement)) { movementAnimation = animations.jump_land; } else { // We are done jumping jumped = false; } } else { movementAnimation = animations.jump_glide; } } else if (movementLength > movementEpsilon) { if (running && !isActionHappening) { // No slow running movementAnimation = animations.run; animationSpeed = 1.f; } else { animationSpeed = 1.f / movementLength; // Determine if we need to play the walk start animation if (currentAnim != animations.walk) { if (currentAnim != animations.walk_start || !animator->isCompleted(AnimIndexMovement)) { movementAnimation = animations.walk_start; } else { movementAnimation = animations.walk; } } else { // Keep walkin movementAnimation = animations.walk; } } } // Check if we need to change the animation or change speed if (animator->getAnimation(AnimIndexMovement) != movementAnimation) { animator->playAnimation(AnimIndexMovement, movementAnimation, animationSpeed, repeat); } else { animator->setAnimationSpeed(AnimIndexMovement, animationSpeed); } // If we have to, interrogate the movement animation if (movementAnimation != animations.idle) { if(! model->resource->frames[0]->getChildren().empty() ) { ModelFrame* root = model->resource->frames[0]->getChildren()[0]; auto it = movementAnimation->bones.find(root->getName()); if (it != movementAnimation->bones.end()) { AnimationBone* rootBone = it->second; float step = dt; const float duration = animator->getAnimation(AnimIndexMovement)->duration; float animTime = fmod(animator->getAnimationTime(AnimIndexMovement), duration); // Handle any remaining transformation before the end of the keyframes if ((animTime+step) > duration) { glm::vec3 a = rootBone->getInterpolatedKeyframe(animTime).position; glm::vec3 b = rootBone->getInterpolatedKeyframe(duration).position; glm::vec3 d = (b-a); animTranslate.y += d.y; step -= (duration - animTime); animTime = 0.f; } glm::vec3 a = rootBone->getInterpolatedKeyframe(animTime).position; glm::vec3 b = rootBone->getInterpolatedKeyframe(animTime+step).position; glm::vec3 d = (b-a); animTranslate.y += d.y; Skeleton::FrameData fd = skeleton->getData(root->getIndex()); fd.a.translation.y = 0.f; skeleton->setData(root->getIndex(), fd); } } } return animTranslate; }
//------------------------------------------------------------------------------------- bool MoveToPointHandler::update() { if(pController_ == NULL) { delete this; return false; } Entity* pEntity = pController_->pEntity(); const Position3D& dstPos = destPos(); Position3D currpos = pEntity->getPosition(); Direction3D direction = pEntity->getDirection(); Vector3 movement = dstPos - currpos; if (!moveVertically_) movement.y = 0.f; bool ret = true; if(KBEVec3Length(&movement) < velocity_ + range_) { float y = currpos.y; currpos = dstPos; if(range_ > 0.0f) { // 单位化向量 KBEVec3Normalize(&movement, &movement); movement *= range_; currpos -= movement; } if (!moveVertically_) currpos.y = y; ret = false; } else { // 单位化向量 KBEVec3Normalize(&movement, &movement); // 移动位置 movement *= velocity_; currpos += movement; } // 是否需要改变面向 if (faceMovement_ && (movement.x != 0.f || movement.z != 0.f)) direction.yaw(movement.yaw()); // 设置entity的新位置和面向 if(pController_) pEntity->setPositionAndDirection(currpos, direction); // 非navigate都不能确定其在地面上 if(pController_) pEntity->isOnGround(isOnGround()); // 通知脚本 if(pController_) pEntity->onMove(pController_->id(), pyuserarg_); // 如果达到目的地则返回true if(!ret) { return !requestMoveOver(); } return true; }
void DynamicGoo::moveToTarget(){ //Stop to follow if the goo is dragged for the use if (isDragging()) { stopFollow(); return; } if (onGround && groundPoint!=getPPosition()) { onGround=false; } if (isFalling()) return; if (hasJoint()){ return; } if (!hasJoint() && !isDragging() && isOnGround() && target==NULL ){ emit this->nextTargetPlease(NULL); } if (following && !falling){ if (prevTarget){ if (!target->isLinked(prevTarget)){ drop(); return; } QPoint meTarget=target->getPPosition()-getPPosition(); if (toVec(meTarget).Length()>15+radius/10) { stopFollow(); fallDown(); return; } //Compute mx and my for the position float mx,my; mx=(target->getVPosition().x-prevTarget->getVPosition().x); my=(target->getVPosition().y-prevTarget->getVPosition().y); float d=qSqrt(mx*mx+my*my); float md=qSqrt(qPow((target->getVPosition().x-getVPosition().x),2)+qPow((target->getVPosition().y-getVPosition().y),2)); mx/=d; my/=d; float tx,ty; //Compute tehorical x and y tx=(getVPosition().x-prevTarget->getVPosition().x)/mx; ty=(getVPosition().y-prevTarget->getVPosition().y)/my; float yt=my*tx+prevTarget->getVPosition().y; float xt=mx*ty+prevTarget->getVPosition().x; //if my y position is different at least of 12 falldown and return if ((qAbs(getVPosition().y-yt)>getRadius() && qAbs(getVPosition().x-xt)>getRadius()) || (md>d+radius)){ stopFollow(); fallDown(); return; } } //this is a work around for the very ugly bug of the "FLYING GOOS" //description of the bug if no prevTarget is setted but target is and the goo tower start to fall down the goo start to fly //for reach his target! //check if prevtarget is not setted and target is if (!prevTarget && target && !target->isOnGround()){ //compute distance between target and me float d=(target->getVPosition()-getVPosition()).Length(); //if that distance is more than 25 falldown and return //PS: remember that 30 is a single point contact between two goos if (d>=radius*0.2) { stopFollow(); fallDown(); return; } else if (d<radius*0.2){ emit this->nextTargetPlease(target); body->SetLinearVelocity(b2Vec2(0,0)); return; } } b2Vec2 dP; if (target!=NULL /*&& target->getBody()!=NULL*/) dP=target->getVPosition()-this->getVPosition(); else { stopFollow(); fallDown(); return; } if (dP.Length()<=(radius-radius/4.0)/10.0){ emit this->nextTargetPlease(target); body->SetLinearVelocity(b2Vec2(0,0)); return; } if (!prevTarget){ b2Vec2 dvec=(target->getVPosition()-getVPosition()); float d=qSqrt(dvec.x*dvec.x+dvec.y*dvec.y); if (onGround && target->isOnGround() && d<distanceToJoint){ double omega =(dP.x>0 ? speed*body->GetMass() : -speed*body->GetMass()); body->SetAngularVelocity(omega); body->ApplyForceToCenter(body->GetMass()*body->GetWorld()->GetGravity()); } else if (!onGround && d<radius*2) { emit this->nextTargetPlease(target); body->SetLinearVelocity(b2Vec2(0,0)); return; dP.x=(dP.x>0 ? speed*2 : -speed*2); dP.y=body->GetMass()*body->GetWorld()->GetGravity().y; body->ApplyForceToCenter(dP); } else{ body->SetGravityScale(1); stopFollow(); } } else { dP.x=dP.x*speed/dP.Length(); dP.y=dP.y*speed/dP.Length() ; body->SetLinearVelocity(dP); } } }
void Player::logic(Room *room) { //std::cout << "HP:" << getHealth() << " MP:" << getMana() << "/" << getMaximumMana() << " Couter:" << mRegenerateManaCounter << std::endl; mStateCounter++; if (mInvincibleCounter > 0) { mInvincibleCounter--; } if (getState() == DEAD) { return; } regenerateMana(); const KeyState &keys = room->getKeyState(); TileMap *tileMap = room->getTileMap(); bool onIce = isOnIce(tileMap); int acceleration = AIR_ACCELERATION; if (getState() == GROUND) { if (onIce) { acceleration = ICE_ACCELERATION; } else { acceleration = GROUND_ACCELERATION; } } if (keys.isLeftHeld() && !keys.isRightHeld() && !mHurt) { mDX -= acceleration; if (mDX < -RUN_SPEED) { mDX = -RUN_SPEED; } mRunFrame += onIce && mDX > -20 ? 3 : 2; mFacingLeft = true; mRunning = true; } else if (!keys.isLeftHeld() && keys.isRightHeld() && !mHurt) { mDX += acceleration; if (mDX > RUN_SPEED) { mDX = RUN_SPEED; } mRunFrame += onIce && mDX < 20 ? 3 : 2; mFacingLeft = false; mRunning = true; } else if (mDX > 0 && !mHurt) { mDX -= onIce ? 1 : 4; if (mDX < 0) { mDX = 0; } mRunning = false; } else if (mDX < 0 && !mHurt) { mDX += onIce ? 1 : 4; if (mDX > 0) { mDX = 0; } mRunning = false; } else { mRunning = false; } // Crouching if (!mRunning && keys.isDownHeld() && getState() == GROUND) { if (!mCrouching) { mCrouching = true; mY += CROUCH_SHRINK; mH -= CROUCH_SHRINK; } } else if (mCrouching) { mCrouching = false; mY -= CROUCH_SHRINK; mH += CROUCH_SHRINK; } if (mDX == 0 || getState() != GROUND) { mRunFrame = 0; } // Interrupting jumping if (!keys.isJumpHeld() && getState() == AIR_UP && mDY > JUMP_CONTROL && !mHurt) { mDY = JUMP_CONTROL; } if (!keys.isJumpHeld() && (getState() == AIR_UP || getState() == AIR_DOWN)) { mJumpKeyHeld = false; } // Jumping if (keys.isJumpPressed() && getState() == GROUND && !keys.isDownHeld()) { mDY = JUMP_STRENGTH; setState(AIR_UP); mJumpKeyHeld = true; mJumpY = getCenterY(); } // Drop off platform if (keys.isJumpPressed() && mOnPlatform && keys.isDownHeld()) { mDY = 1; mY++; setState(AIR_DOWN); mJumpKeyHeld = true; mJumpY = getCenterY(); } // Sideways movement if (onIce) { if (mDX < 0) { mX += (mDX - 7) / 8; } else { mX += (mDX + 7) / 8; } } else { mX += mDX / 8; } // Left Wall int solidLeftOffset; if (mDX < 0 && solidLeft(room, solidLeftOffset)) { // Align player to solid object mX += solidLeftOffset; mDX = 0; } // Right Wall int solidRightOffset; if (mDX > 0 && solidRight(room, solidRightOffset)) { // Align player to solid object mX -= solidRightOffset; mDX = 0; } // Vertical movement if (getState() == AIR_DOWN) { mY += mDY > MAX_AIR_SPEED ? MAX_AIR_SPEED : mDY; } else if (getState() == AIR_UP) { mY -= mDY > MAX_AIR_SPEED ? MAX_AIR_SPEED : mDY; } // Falling, acceleration if (getState() == AIR_DOWN) { mDY += 1; } // Raising, deacceleration if (getState() == AIR_UP) { mDY--; if (mDY < 0) { setState(AIR_DOWN); mDY = 0; } } // Ceiling bouncing int solidAboveOffset; if (getState() == AIR_UP && solidAbove(room, solidAboveOffset)) { setState(AIR_DOWN); mDY = 0; // Align player to solid object mY += solidAboveOffset; } // Ground bouncing / landing int groundOffset; if (getState() == AIR_DOWN && isOnGround(room, groundOffset)) { if (keys.isJumpHeld() && !mJumpKeyHeld && !keys.isDownHeld()) { // Rejump mDY = JUMP_STRENGTH; setState(AIR_UP); mJumpKeyHeld = true; } else { // Land setState(GROUND); mDY = 0; } mHurt = false; // Align to tile mY -= groundOffset; mJumpY = getCenterY(); } // Falling int fallingOffset; if (getState() == GROUND && !isOnGround(room, fallingOffset)) { setState(AIR_DOWN); mDY = 0; } // Shooting if (keys.isFirePressed()) { if (mShotCounter >= SHOT_DELAY) { mShotCounter = 0; room->addEntity(createShot()); mShootAfterDelay = false; } else { mShootAfterDelay = true; } } if (mShotCounter >= SHOT_DELAY && mShootAfterDelay) { mShotCounter = 0; room->addEntity(createShot()); mShootAfterDelay = false; } mShotCounter++; if (keys.isSpecialPressed()) { if (mShotType == NORMAL) { mShotType = ICE; } else if (mShotType == ICE) { mShotType = FIRE; } else { mShotType = NORMAL; } } }
/*! @brief Returns true if the robot is currently incapacitated. A robot is incapacitated if it is falling, fallen, not on the ground or getting up */ bool NUSensorsData::isIncapacitated() { bool gettingup = false; get(MotionGetupActive, gettingup); return isFalling() or isFallen() or not isOnGround() or gettingup; }
float getAcceleration() { return isOnGround() ? ACCELERATION : ACCELERATION * Physics::airFraction; }
//----------------------------------------------------------------------------- // // VActorPhysicsController::postTickUpdate( pDelta ); // // ... // //----------------------------------------------------------------------------- void VActorPhysicsController::postTickUpdate( const F32 &pDelta ) { switch( mControlState ) { case k_PathControlState : { AssertFatal( isPathing(), "VActorPhysicsController::postTickUpdate() - Invalid Path State." ); // Fetch Mount Transform. MatrixF transform; mMountedPath->getMountTransform( mObject->getMountNode(), getTransform(), &transform ); // Fetch Mount Position. const Point3F &mountPosition = transform.getPosition(); // Update X & Y Position. Point3F position = getPosition(); position.x = mountPosition.x; position.y = mountPosition.y; // In Water? bool underWater = false; if ( isInWater() ) { // Fetch Body of Water. WaterObject *waterBody = getWaterObject(); // Fetch Surface Position. const F32 &waterSurfacePosition = waterBody->getSurfaceHeight( Point2F( position.x, position.y ) ); // Fetch Submersion Position. const F32 sumbersionPosition = waterSurfacePosition - ( mObject->getWorldBox().len_z() * mObject->getDataBlock()->getSumbergeCoverage() ); // Choose a Z Value. // Note: This is done so that the Actor will either path under the // water, or it will swim along the water's surface. position.z = getMin( mountPosition.z, sumbersionPosition ); // Under Water? underWater = ( position.z < sumbersionPosition ); } // Under Water? if ( !underWater ) { // Fetch Y Column. VectorF forwardVector; transform.getColumn( 1, &forwardVector ); // Determine Angle. const F32 &angle = -mAtan2( -forwardVector.x, forwardVector.y ); // Reset Transform. transform.set( EulerF( 0.f, 0.f, angle ) ); // In the air? if ( !isOnGround() ) { // Apply z-axis force. position.z += ( getVelocity().z * pDelta ); } } // Update Transform. transform.setPosition( position ); // Apply Update. setTransform( transform ); } break; default : { // Fetch Transform. MatrixF transform = getTransform(); // Determine the Post-Tick Position. Point3F postTickPosition = getPosition() + ( getVelocity() * pDelta ); // Set the Post Tick Position. transform.setPosition( postTickPosition ); // Apply the Transform. setTransform( transform ); } break; } // Push Delta. mInterpController.pushDelta( getTransform() ); }
void GameMainObject::DoUpdate(int iCurrentTime) { m_iPreviousScreenX = m_iCurrentScreenX; m_iPreviousScreenY = m_iCurrentScreenY; counterTime++; if(counterTime > 7) { counterTime = 0; if (m_iPlayerSpriteX == 0) { m_iPlayerSpriteX +=121; } else if(m_iPlayerSpriteX == 121) { m_iPlayerSpriteX +=121; } else if(m_iPlayerSpriteX == 242) { m_iPlayerSpriteX +=121; } else if(m_iPlayerSpriteX == 363) { m_iPlayerSpriteX +=121; } else if(m_iPlayerSpriteX == 484) { m_iPlayerSpriteX +=121; } else { m_iPlayerSpriteX = 0; } } if(isOnGround()) { velocityX*=0.9; if(GetEngine()->IsKeyPressed(SDLK_SPACE)) { if(jumpAgain == true){ velocityY=-10; jumpAgain = false; } } else { jumpAgain = true; } } if(!isOnGround()) { velocityY+=0.5; } m_iCurrentScreenY += velocityY+(0.5); m_iCurrentScreenYObject = m_iCurrentScreenY; if((m_iCurrentScreenY+m_iDrawHeight)>=521) { m_iCurrentScreenY=521-m_iDrawHeight; m_iCurrentScreenYObject = m_iCurrentScreenY; } RedrawObjects(); }