CompSci 4
Java for Video Games

Homework 3
Lunar Lander

250 points, due 11:30pm February 15, 2006


Lunar Lander is one of the earliest computer games, even though it is as much a simulation as a game. The premise of the game is that you are in control of a lunar lander ship, descending to the surface of the moon for a landing. Gravity steadily accelerates your ship faster and faster toward the surface of the moon. You, the astronaut piloting the ship, have a single control: a button with the label "thrust" on it. Applying thrust slows your ship down. Your goal is to get your ship to land on the moon at a slow enough speed so that it doesn't crash on impact. What's the catch? You have only a limited amount of fuel. If you slow down your ship too much too early, you will run out of fuel and crash into the surface of the moon.

With a proper choice of initial values, it is quite a bit of fun to play.


You will be given a basic version of the game in which a ball starts at the top of the screen and falls, never stopping. There are two classes that you will modify as part of this game: LunarLander (the game) and LanderTracker (which moves the ship each step of the game).

In the class LunarLander, you should add code to make the lunar surface and a fuel gauge that indicates how much fuel is left in the ship (like the gauge showing the ship's current velocity). Then you should add code to detect when the ship intersects the lunar surface and determines if the player won or lost the game (i.e., hit the surface too fast). Finally, you should add interaction so that the player can press the "i" key to apply the ship's thrusters. Each time the key is pressed, the ship's velocity and fuel should be decreased once by a set amount and these new values updated on the indicators on the game screen.

In the class LanderTracker, you should add code that simulates gravity being applied to increase the ship's velocity at each step by a set amount. Also, you should add code that actually applies the player's thrust to the ship's velocity.

Note, you will have to spend some time choosing fixed values for gravity, the thrust's effect, the amount of fuel burned for each thrust, and the speed threshold that determines a safe landing. If the ship falls so fast that it is impossible to land safely with your chosen thrust power, then the game will be no fun to play.

Extra Credit

Once you have the basic game working, you can add a variety of features to make your game more fun to play (listed below roughly in order of difficulty):

How to

  1. Using Eclipse, snarf the project lander which contains the beginning code for the game.
  2. Run the program by running LunarLander. You can run LunarLander either as an applet or an application.
  3. When done, submit your assignment using Eclipse as lander.
  4. Update your web page for this homework by posting your applet.