Homework 2
Lunar Lander
250 points, due 11 PM on July 17, 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:
  1. 1. Make the lunar surface
  2. 2. Make a fuel gauge (text, like the velocity gauge)
  3. 3. Detect when the ship intersects with the lunar surface
  4. 4. Determine whether the player has won or lost (i.e., see if he was going too fast when he hit bottom)
  5. 5. Show the player a message (in a StringSprite) telling her whether she won or lost
  6. 6. Apply the ship’s thrusters when the player presses the “i” key.  Each time this key is pressed, the ship’s velocity and fuel should be decreased once by a set amount (and the gauges should be updated).  This code should call a method in the LanderTracker class which actually adds the thrust to the ship’s velocity.
In the class LanderTracker, you should add code to:
  1. 1. Simulate gravity being applied to increase the ship's velocity at each step by a set amount
  2. 2. Apply the player's thrust to the ship's velocity (this will be in a method that may be called from the main LunarLander class when the player hits “i”)
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 (or, conversely, if it falls so slowly that winning is trivial, it is also no fun).  It would be difficult to alter your grade based on “how fun” your game is, but do not make it impossible to lose or impossible to win.
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):
  1.   Create a new class called LanderSprite that extends fang.Sprite in the package lander and modify its constructor to make a more interesting sprite of your own design. Use CAG (Constructive Area Geometry) or a GeneralPath, rather than an image, to represent your ship's shape. For an example, see the “Custom Sprites” slide in the Game Engine notes.  Update: You don’t have to create a new LanderSprite class... Some extra credit will be given just for creating a lander using CAG or GeneralPath.
  2.   Add mountains to the lunar surface that destroy the ship when it hits them.
  3.   Create a graphical version of the fuel or velocity gauges (like a rectangle that shows how much fuel is left or something that changes color when the ship's velocity is moving at a safe speed).
  4.   Give the player the ability to thrust to the left or right to avoid the mountains.
  5.   Allow the player to turn the thruster on then off, so each thrust is not just a "pulse".
  6.   Create the mountains randomly rather than in a fixed pattern so they may be harder to avoid.
Submitting the Game
  1. 2.  Update your web page for this homework by posting your game as an applet. <more instructions to be given in class>