CSE 142 Homework 4

Due Tuesday, August 1st, 10:00 PM
Paper turn in Wednesday, August 2nd, 5:00 PM
Turn in Report is due the same time as the Paper turn in (Wednesday)


The success of Nim - The Power Returns has helped turn HHGG into an overnight success. Aware that HHGG needs another game to continue to ride this most excellent wave, you've been given another project. Evil Evil Monster Monster will be the next generation game from HHGG, incorporating amazing graphics and player interaction. The game was under development when you were put in charge, so you have a base to start from. As head developer, you've been given a lot of freedom to design the game as you see fit.

Homework Requirements:

Program -- Evil Evil Monster Monster
A Turn In Description -- details here

Overview

Evil Evil Monster Monster (EEMM) is a one-player game using graphics as well as keyboard and mouse events. The object is to collect as many pellets as possible while avoiding the Evil Monster. Different pellets have different behaviors. You will use your knowledge of functions, pointer parameters, and arrays, along with everything else, to fully develop the game. We will be providing you with a large amount of starting code (a completely functioning game) and some additional information to help you complete the assignment.

In addition to the concepts you've already learned, this assignment will give you experience working with two common necessities of real-world programming:

Read this entire assignment carefully, there are important bits throughout.

Quick Overview

Specifications

Read the entire assignment very carefully and thoroughly.

The starter program for this assignment is available both as a sample executable and as a C source file. Unlike past assignments, this time the starter code is the complete sample executable program. Some of this writeup won't make much sense until you've spent some time experimenting with the sample program and looking at the source code. The more familiar you are with the how it works, the easier this assignment will be.

To play Evil Evil Monster Monster you use the i,j,k,l keys like the arrow keys. You press them repeatedly to increase and decrease your speed. Use the p key to Pause and Unpause the game. Use the mouse to press the buttons. It will take a little bit of playing to understand how the game works. Note that only the Change Color button will work (however, it does work while the game is paused).

Your job is turn the code you've been given into a complete game. Right now it lacks some functionality. However, you have a lot of flexibility with how you complete this assignment -- use your imagination to make it more interesting.

Minimum Requirements -- you must do at least the following. Some small amount of extra credit will be awarded for programs that go above and beyond the basic requirements. How much will be determined by what you do. There will be a Hall of Fame where the best of the best (as determined by the TAs) will be on display for all to see. So try to knock our socks off. You are required to do the following:

Monster Changes: you must make the monster move. Currently the monster does not move. You must create a function, perhaps called update_monster_position which calculates where the monster should move. Each clock-tick (i.e. each time a PERIODIC event happens), the monster should move. The monster moves in either the x or y direction (but not both). The Evil Monster moves according to the following rule:

Pellet Changes: you must add the following pellets to the game:

Both pellets and the monster must remain completely inside the bounding box of the screen. This means that no part of the pellets or monster should overlap the buttons at the top, the sides, or the bottom of the screen.

Button Changes: you must implement functionality in the remaining Button:

You can add whichever additional interesting features you desire, be creative. Add more pellets, or another button. Remember, HHGG is counting on you for the success of this game.

Suggestions and Hints

Get Started Now! Really. We mean it.

The game is written using a library called GP142. This is the first assignment which has more than one file. How the different files are used and handled by the compiler will not be covered in depth. You should just use the provided workspaces.

Once you have a clear understanding of what the program does, you should study the code to find out how it accomplishes this. For example, make sure to understand how clicking a button actually changes the color of the player, tracing control flow carefully.

Remember, work in small steps. Make a small change and then recompile and test it. Then continue, one small step at a time.

You may want to make a static call graph to help you understand how the program works. You should start with main and trace how functions call each other. Don't worry about functions not called from hw4.c (i.e. ignore functions calls using GP142 not inside hw4.c).

Remember from lecture that a static call graph shows the calling relationship between functions in the program - which function(s) call which other function(s). In particular,

Study the event loop in the main program. Locate the place where button and key commands are handled. Next study the movement of the monster. Lastly, look at how pellets are created and changed.

Think about what needs to be changed in order to fulfill the requirements of the program. Which constants must be changed? Which functions? Which functions have to be written? How does the current program do these things? Will you need pointer parameters?

As always, remember to use good style:

The random number generator is used in the sample executable and skeleton program.

Final hint, the functions at the bottom of hw4.c may came in handy, take a look at what they do.

Using GP142

learning about GP142

You will find the GP142 User's Guide (also linked on the main Homework page) useful as a reference as you read and write graphics code in this homework.

special settings for building GP142 programs

If you are using Windows, we strongly advise that you compile and modify the program ONLY via the .dsw file that will be supplied in the self-extracting archive. Here's why: GP142 programs differ from previous projects in some important ways. First, they have multiple .c files (gp142.c in addition to your own). Second, they use a special .h file that must be available to the compiler. Third, they are built as "Windows Applications" rather than "Console Applications." All of this means that you cannot create a "default project workspace" to compile and run your program in. If you double-click on the .dsw file we give you (.dsp for users of some older versions of MSVC), all of these special settings are taken care of.

If you really need to know how to create your own project, look at the MSVC tips page.

We recommend that you work on a Windows PC to work on this homework, but the GP142 User's Guide. page also includes information for Macintosh and X Windows (UNIX) users.

Sample Executable

Download and run the sample PC executable hw4.exe.

To play Evil Evil Monster Monster you use the i,j,k,l keys like the arrow keys. You press them repeatedly to increase and decrease your speed. Use the p key to Pause and Unpause the game. Use the mouse to press the buttons.

We have also provided a sample solution, so that you can see one possible way to write the complete solution.

Download and run the sample PC solution executable hw4_sol.exe.

Getting Started

You need to use the provided workspaces for this assignment, as they are set up to appropriately handle the multiple files needed for compiling.

Submitting Your Work

You only need to sumbit hw4.c electronically, you don't need to submit the gp142 code. You must still hand in a turnin receipt and the turn in report.

Turn in the assignment Don't forget the the turnin description

You may turn in the program as many times as you wish. Only the last version is graded, and only the receipt from this last version should be handed in.