void GameLayer::updateGround(float dt) { CCSprite *groundSp1 = (CCSprite *)mGrounds->objectAtIndex(0); CCSprite *groundSp2 = (CCSprite *)mGrounds->objectAtIndex(1); groundSp1->setPositionX(groundSp1->getPositionX() - getGroundSpeed()); groundSp2->setPositionX(groundSp2->getPositionX() - getGroundSpeed()); if (groundSp1->getPositionX() < -groundSp1->getContentSize().width) { groundSp1->setPositionX(groundSp2->getPositionX() + groundSp2->getContentSize().width); mGrounds->exchangeObject(groundSp1, groundSp2); } }
void GameLayer::updateCollisions(float dt) { if (!mCollisionArray->count()) { return; } for (int i=0; i<mCollisionArray->count(); ++i) { BarPipe *pBarPipe = (BarPipe *)mCollisionArray->objectAtIndex(i); pBarPipe->setBarPositionX(pBarPipe->getBarPositionX() - getGroundSpeed()); } /** 检测第一个是否出界, 如是 1.改变它的位置 2.把第一个放到最后一个 **/ BarPipe *pFirstBarPipe = (BarPipe *)mCollisionArray->objectAtIndex(0); if (pFirstBarPipe->getBarPositionX() < -pFirstBarPipe->getSize().width) { BarPipe *pLastBarPipe = (BarPipe *)mCollisionArray->lastObject(); float firstX = pLastBarPipe->getBarPositionX() + BarPipe::getSize().width + INTERVAL_COLLISION; pFirstBarPipe->setBarPositionX(firstX); pFirstBarPipe->setRandomY(); pFirstBarPipe->setIsPassed(false); CC_SAFE_RETAIN(pFirstBarPipe); mCollisionArray->removeObjectAtIndex(0); mCollisionArray->addObject(pFirstBarPipe); CC_SAFE_RELEASE(pFirstBarPipe); } }
//------------------------------------------------------------------------------ // weaponDynamics -- default dynamics; using Robot Aircraft (RAC) dynamics //------------------------------------------------------------------------------ void Effects::weaponDynamics(const LCreal dt) { // Useful constant static const LCreal g = ETHG * Basic::Distance::FT2M; // Acceleration of Gravity (m/s/s) // --- // Compute & Set acceleration vector (earth) // --- // First drag osg::Vec3 tmp = getVelocity() * (-dragIndex); // then gravity osg::Vec3 ae1 = tmp; ae1[IDOWN] += g; setAcceleration(ae1); // --- // Comute & set new velocity vectory (earth) // --- osg::Vec3 ve1 = getVelocity() + (ae1 * dt); setVelocity(ve1); // --- // .. Only after setVelocity has been called ... // --- LCreal vp = getTotalVelocity(); LCreal vg = getGroundSpeed(); // --- // Set velocity vector (body) // (total velocity is along X) // --- setVelocityBody(vp, 0.0, 0.0); // --- // Sent angular values // --- LCreal newPsi = lcAtan2(ve1[IEAST],ve1[INORTH]); LCreal newTheta = lcAtan2( -ve1[IDOWN], vg ); setEulerAngles(0.0, newTheta, newPsi); setAngularVelocities(0.0, 0.0, 0.0); }