CSCE 4013 - Homework 2
Part 1 Due - 02/13/2014 at 11:59 PM
Part 2 Due - 02/20/2014 at 11:59 PM

1. Problem Statement:

For this programming assignment you will be using OpenGL to create a simple "whack a mole" game. This will be done in two parts.

Part 1:Your first task is to create the graphics program that displays the game board consisting of a green background, and a collection of black ovals representing the mole holes. You will also need a function that draws a mole face in the middle of any given hole. For now, lets use a light brown circle centered in the mole hole. To test the program, you need to create one image showing an empty board and a second image showing a mole face in every mole hole.

Part 2:Your second task is extend your program to control the user interaction and keep track of the score. There are three parts to this: 1) you need to create a background loop that controls where and when the moles pop up on the game board, 2) you need to modify the display function to show the board and the moles faces in the appropriate holes, and 3) you need a mouse handling function that uses the (x,y) coordinates of the mouse click to decide if the user whacked mole or not, and update the score accordingly. To test the program, you need to play the game and save some screen shots.

2. Design:

As you have already guessed, this is a 2D game, so we will not be needing the full 3D graphics capabilities of OpenGL. Take a look at the "disk" program and the "square" programs to see how to draw circles and rectangles, and adapt that code to draw your whack a mole game board.

Hint: You will probably want to write a "draw_circle" function that takes in x_center. y_center, radius as parameters, and another function "draw_ellipse" that takes in x_center, y_center, x_radius, and y_radius as parameters. You can call these functions several times to draw the holes and the faces of the moles. For example, here is what my sample program produces:

For user interaction, look at the "draw_rectangle" program for an example of the mouse callback. If you search for "glutMouseFunc" you can find several other example programs. To implement the background loop for your game, you need an "idle" function that is initiated using the "glutIdleFunc" call. The "render" and "balls" programs both show examples of an idle function can be used to change the display without user input.

Your hardest task will be to use the OpenGL function above to implement the "game logic". Start with a really simple game where the mole face stays on the board until the user clicks on it. Once you have this going, you can play with timing functions to show the mole face for a limited time, and have them duck back into their holes if the user does not click on them in time. To keep things simple, just display the game score on the terminal window using traditional I/O commands like cin/cout or scanf/printf.

3. Implementation:

You can implement this program using either a bottom-up approach or a top-down approach. If you go for a bottom-up approach, start by creating basic methods and classes, and test theses methods using a simple main program that calls each method. When this is working, you can create the main program that uses these methods to solve the problem above.

If you go for a top-down approach, start by creating your main program that reads user input, and calls empty methods to pretend to solve the problem. Then add in the code for these methods one at a time. This way, you will get an idea of how the whole program will work before you dive into the details of implementing each method and class.

Regardless of which technique you choose to use, you should always develop your code incrementally adding code, compiling, debugging, a little bit at a time. This way, you always have a program that "does something" even if it is not complete. Also, remember to keep backup versions of your code, so you always have a version to fall back on if you accidentally delete your code or your changes do not work out.

4. Testing:

Test your program to check that it operates correctly for all of the requirements listed above. Also check for the error handling capabilities of the code. You are required to include your testing results in your project report to demonstrate that your program works correctly. To do this use the "script" command to save all program input/output in a "typescript" file, and cut and paste from this ascii file into your program documentation.

5. Documentation:

When you have completed your C++ program, use the "Programming Report Template" on the class website to document your programming project. This report has separate sections to describe the problem statement, your design decisions, your implementation process, and your testing results. Each of these sections should be 1-2 paragraphs long, so your completed report will be 2-3 pages long once you have included your testing output.

6. Project Submission:

In this class, we will be using electronic project submission to make sure that all students hand their programming projects and labs on time, and to perform automatic analysis of all programs that are submitted. When you have completed the tasks above go to the class web site to "Upload" your documentation (a single docx file), and your C++ program (a single ascii text file).

The dates on your electronic submission will be used to verify that you met the due date above. All late projects will receive reduced credit:

You will receive partial credit for all programs that compile even if they do not meet all program requirements, so handing projects in on time is highly recommended.