Application example Analysis of SurfaceView Class in Android Game Development
) mHeading-= 360;} / / Base accelerations-- 0 for x, gravity for y double ddx = 0; double ddy =-PHYS_DOWN_ACCEL_SEC * elapsed If (mEngineFiring) {/ / taking 0 as up, 90 as to the right / / cos (deg) is ddy component, sin (deg) is ddx component double elapsedFiring = elapsed; double fuelUsed = elapsedFiring * PHYS_FUEL_SEC / / tricky case where we run out of fuel partway through the / / elapsed if (fuelUsed > mFuel) {elapsedFiring = mFuel / fuelUsed * elapsed; fuelUsed = mFuel / / Oddball case where we adjust the "control" from here mEngineFiring = false;} mFuel-= fuelUsed; / / have this much acceleration from the engine double accel = PHYS_FIRE_ACCEL_SEC * elapsedFiring Double radians = 2 * Math.PI * mHeading / 360; ddx = Math.sin (radians) * accel; ddy + = Math.cos (radians) * accel;} double dxOld = mDX; double dyOld = mDY / / figure speeds for the end of the period mDX + = ddx; mDY + = ddy; / / figure position based on average speed during the period mX + = elapsed * (mDX + dxOld) / 2; mY + = elapsed * (mDY + dyOld) / 2; mLastTime = now / / Evaluate if we have landed... Stop the game double yLowerBound = TARGET_PAD_HEIGHT + mLanderHeight / 2-TARGET_BOTTOM_PADDING; if (mY