CS 165 Project - Moon Lander

Overview

Lunar Lander was one of many influential early video games released by Atari in 1979, and was a precursor to their release of Asteroids (which we will also implement this semester). The object of the game is to safely navigate a lunar module to land on a flat portion of the moon's surface. To pilot the lander, horizontal thrusters can be activated to maneuver the ship left and right, and vertical thrusters can be fired to slow its descent.

Instructions

First, you need to set up your environment for OpenGL projects. See this link for information about your different options and instructions to set up each one.

Then, your assignment is to create a Moon Lander game that is a based on this classic arcade game. In the game, a random ground configuration is drawn, with a single safe landing platform. The lander begins at a random location along the top of the screen and begins falling according to gravity. The user can fire left, right, and bottom thrusters to guide the craft safely to the landing platform before the fuel is exhausted. The lander will crash if it touches the ground or approaches the platform with too much speed.

Moon Lander Game

Architectural Design

The entire program will need to be implemented using the principles of encapsulation. Thus, you need to think about the different components (classes) that you will need in the game, and their various actions (methods) and properties (member variables). Before you start programing, you will need to produce UML class diagrams for each of the classes you will be using. Please pay special attention to the design of these components, so they can be as general-purpose as possible. You will want to reuse some of them in future projects.

To assist you in your project, you will be given an implementation of a Point class that stores an x and y coordinate, and a Ground class that generates random terrain (including the landing platform), and has methods to identify the location of the platform (getPlatformPosition()), the elevation of an object above the ground (getGround(Point)), and if a point is above ground (not crashed) (isAboveGround(Point)). The following UML defines these classes:

Point
-x : float
-y : float
+Point()
+Point(float, float)
+getX() : float
+getY() : float
+setX(float) : void
+setY(float) : void
+addX(float) : void
+addY(float) : void
Ground
-platform : Point
-xSize : int
-ground : float*
-topLeft : Point
-bottomRight : Point
+Ground(Point, Point)
+draw() : void
+isAboveGround(Point) : bool
+getGround(Point) : Point
+generateGround() : void
+getPlatformPosition() : Point
+getPlatformWidth() : int

Game Play and Rules

The following describes the rules and game play of Moon Lander:

Error Handling

As usual, your classes and the game itself will need to be robust to any type of user or file input. Extensive error handling should also be built into each class to ensure that clients of the class will use them correctly. Similarly, there should be no way the user can cause the program to malfunction due to incorrectly formed input.

Using the Provided Files

The graphics and game play will be done with OpenGL. A simplified interface to this library is provided.

Essentially there are two sets of files, those that handle the details of the graphics and drawing, and those that relate to the Moon Lander part of the game. You are welcome to look through the first set of files, but you will likely not need to change anything there.

Set 1 - The Graphics interface

The part of graphics interface files that is important for you to know, is that it provides the following functions:

The files that compose this interface to the library are: (again, you should not need to worry about the details of them)

  • /home/cs165new/moonLander/uiInteract.h -- Header file describing the OpenGL interface
  • /home/cs165new/moonLander/uiInteract.cpp -- Source for uiInteract.h. Should not change
  • /home/cs165new/moonLander/uiDraw.h -- Header file with drawing function prototypes
  • /home/cs165new/moonLander/uiDraw.cpp -- All the drawing functions.
  • /home/cs165new/moonLander/point.h -- Ultra simple class describing a single point
  • /home/cs165new/moonLander/point.cpp -- Implementation of the Point class

Set 2 - Files Relating to Moon Lander

The next set of files relate directly to the Moon Lander. First, we have a makefile and a Ground class.

The makefile contains rules to build compile all of the files provided, but YOU WILL NEED TO UPDATE IT to compile any new files / classes you create.

The Ground class is used to draw the terrain of the world and the platform. It also contains methods that allow you to know how close a point is to the ground, etc.

Working as a Team (With your Instructor)

In some sections of this course, Moon Lander and future projects are done in pairs. Working in pairs helps divide the work and teaches important principles about agreeing on the interface of a class, but can also present some challenges. To try to achieve the same goals, without some of the challenges, this semester you will not be working in pairs with other students, but rather, will be collaborating with the instructor. In other words, the instructor will provide code for half of the project, and you will be completing the other half. (Please keep in mind that because other sections, now or in the future, may not have this luxury, you should not share the code you are given with friends in other sections.)

In other words, the instructor will provide a Game class that takes care of much of the logic of the game such as checking for collisions, handling the user input, and calling the appropriate draw functions. Your job is to create a class for the Lander and its Velocity and implement the necessary functions. This means that we need to agree upon the things that a lander can do (it's methods) so they can be called.

The following are the public methods for the Lander and Velocity that the game class expects to be implemented.

Lander
...
(private data is up to you)
...
...
+Lander()
+getPoint() : Point
+getVelocity() : Velocity
+isAlive() : bool
+isLanded() : bool
+getFuel() : int
+canThrust() : bool
+setLanded(bool) : void
+setAlive(bool) : void
+setFuel(int) : void
+applyGravity(float) : void
+applyThrustLeft() : void
+applyThrustRight() : void
+applyThrustBottom() : void
+advance() : void
+draw() : void
Velocity
...
(private data is up to you)
...
...
+Velocity()
+Velocity(float, float)
+getDx() : float
+getDy() : float
+setDx(float) : void
+setDy(float) : void

In order to work together, all we need to agree upon is the public interface of the classes. The private data members are completely up to you. Also, you should feel free to add any additional methods to this classes that you determine would be helpful.

The Instructor's Half

The instructor's half of the code is in the following files:

The Game Loop

The important elements of this code are that it starts up the game, and the continually loops through the following functions:

  1. advance - The moving of objects is done here.
  2. handleInput - Check for user input and take the corresponding actions.
  3. draw - Call draw on every object that should be on the screen.

More Detail on the Game Loop

The game loop is described in much more detail here: The Game Loop. It will be valuable to get familiar with the game loop because it will be the same for all of our graphics projects.

Getting the Files

All of the above-mentioned files are found in the directory:

You will need to copy them to your own directory in whatever environment you choose.

Examples

uiTest

A very simple OpenGL project is provided for you to observe and play with. It shows a shape in the middle of the screen and responds to arrows and the space bar. This is a great project to start with to make sure your environment is set up correctly, and then look at the code to observe the basic interactions. The project is found at:

Pong

Another working example is Pong. This example demonstrates handling user interaction and moving the ball. The source code for Pong can be found at:

Working Version of Moon Lander

So that you can observe the game play, and what the program should be doing, please refer to the following working program:

Assignments

This project will be broken up into the following assignment submissions:

Expectation to Excel

As explained in more detail in the Project link above, the requirements presented here are simply a base standard. To receive up to 100% on this assignment you are expected to show creativity and excel above and beyond what is specifically required.