Lunar Tilt Lander

 Kharaka Enterprises, LLC



The idea of this project was simply to learn the basics of the motion sensors and the touchscreen capabilities of the android 2.0 platform.  The basics of this application only take a few days to learn and can be used widely in many applications such as google sky map or driving games where the device is used as a steering wheel.


  1. 1. Download and install the Android 2.0 sdk
  2. 2. Create a new project based on the Lunar Lander sample.
  3. 3. Open TiltLunarView.java
      1. import  android.hardware.SensorManager;

import  android.hardware.SensorListener;

import android.view.View.OnTouchListener;

  1. 4. Add code for class TiltListener attached: 
    1. 1. this class is used for all motion controls
      1. 1. mTilted is for engine firing and uses the Orientation listener of pitch
      2. 5. mRotating is the value of the “Y” rotation which is updated by a listener that fires every millesecond or so based on the “game mode” setting for the orientation listeners
      3. 6. The method getHeading uses the rotation angle to determine where the rocket is heading
      4. 7. If the “X” rotation is > 20 degrees, the user is trying to fire the engine


In the DoStart method we add the sensorlistener


mSensorManager.registerListener(mTiltListener, 

                        SensorManager.SENSOR_ACCELEROMETER | 

                        SensorManager.SENSOR_MAGNETIC_FIELD | 

                        SensorManager.SENSOR_ORIENTATION,

                        SensorManager.SENSOR_DELAY_FASTEST);


In the LunarThread we assign the Orientation sensor to the member variable

  mSensorManager = (SensorManager) mContext.getSystemService("sensor");



  1. 8. Finally we update the method updatePhysics which is fired each time the draw method is called by the main run method.  Set firing = true or false appropriately, sets the direction based on orientation.

9. The rest is commented well in the code... enjoy.


Download the code and documentation at: /mobile/lunartilt.zip



See the complete code and documentation for more details. This is a modified version of the Lunar Tilt app that came with the Android SDK by Google so you should register for the sdk first.



Send mail to SKharaka@kharaka.com with questions or comments about this web site.
Copyright © 2010 Kharaka Enterprises, LLC
Last modified: Jan 1, 2010