CS60 Project 4 --------------------------- Due Fri Nov 14th at Midnight Chase! --------------------------- The task of this project is to write a small graphical game called 'chase' where the object of the player is to simply avoid any enemies on the screen. Enemies try to touch the player by heading towards the current location of the player. The player character moves around by the user inputing movement keys for 'up', 'down', 'left' and 'right'. If an enemy 'touches' the player (enemy image overlaps player image) the game is over! The game must accept a single commandline argument, which specifies the number of enemies to begin the game with. For the graphics and keyboard handling for this project, we will be using the glut library. On the website is an example of a simple glut program that implements the basic functionality you'll need for the project. This program can be used as a starting point for your code but will require substantial modification. Glut ------------- Glut is a simple graphics/input handling library that allows us to write simple event driven graphical programs that can accept input from the keyboard and mouse (no mouse input required for this project, only keyboard). The programming model of the glut system is that of an 'event driven system'. Open the example glut program from the website, and step through the following. The basic flow of a glut program is as follows: declare global variables that all functions may need (outside main) in main, set up the graphical window glutInitWindowSize glutInit glutInitDisplayMode glutCreateWindow in main, set 'callback' functions that are called when various events occur - draw function is the basic functionality function. it is called repeatedly as fast as the machine/graphics subsystem can handle. It takes no parameters and returns no parameters. to register a draw function, use glutDisplayFunc - keyboard function is a function called whenever the user hits a key on the keyboard. It takes three parameters: the input key, the current x coord of the mouse, the current y coord of the mouse. For this project, the x/y coords can be ignored. It returns no value. To register a keyboard function, use glutKeyboardFunc. in main, enter the event loop glutMainLoop After glutMainLoop is called, no more code is executed from main. From that point on, your only chance to execute code is through the functions you registered with the glutDisplayFunc and glutKeyboardFunc calls. To compile a glut program, you must include the following options to the compiler during compilation: -I./ -ansi -pedantic -I/usr/X11R6/include And the following during linking: -L/usr/X11R6/lib -lXi -lXmu -lXext -lX11 -lGL -lGLU -lglut For example, the compile line that will compile 'basic.cpp' all in one line is the following: g++ -I./ -ansi -pedantic -I/usr/X11R6/include basic.cpp -o basic -L/usr/X11R6/lib -lXi -lXmu -lXext -lX11 -lGL -lGLU -lglut Program Requirements -------------------------- The program has a few special requirements. 1.) you must use class inheritance for object types used in this program. There are a few objects: the image passed to drawpixels, the player image, the enemy image. These objects have many things in common and as such can all be parented from one superclass that implements common functionality. For instance, my solution uses the following heirarchy: sprite / \ player background / \ goodguy badguy Such that in my main program, I only have instances of a goodguy, some badguys, and a single background that contains the combined image data passed to drawpixels. While this is a fine heirarchical design, you may choose to use your own heirarchy as long as there are at least two decendant classes from at one parent class. 2.) You must implement player and badguy movement. player movement happens only when the user hits a keyboard command. You must define keys that mean move 'up', 'down', 'left' and 'right'. Each time the user hits whicever key you decide means 'up', the player image must move up a unit on the screen. The badguy movement is automatic, based on the current player image location on the screen. For instance, if the player image is currently located at screen location '10, 20' and a badguy is located at '100, 100', the the badguy should move 'left' and 'down' towards the player. 3.) You must implement collision detection. Each player and badguy image has a location and a size. You must write a routine that checks to see if a badguy image is overlapping the player image. If this happens, the game is over and the program quits. HINTS ------------ Take this project one step at a time, here is a suggested outline 1.) get comforatable with the glut event driven model. Play with the example code and try to draw little squares on the screen and move them around. 2.) design your object heirarchy 3.) make an instance of a goodguy, make the image move around the screen by accepting keyboard commands. Each time 'keyfunc' is called, make a change to the goodguy's current location. Each time 'drawfunc' is called, look at the current player location and draw the player in the new location. Make sure to blank the buffer at the beginning of each drawfunc call. 4.) make an instance of a badguy who chases the goodguy 5.) code a collision detection function. on each time drawfunc is called, after all the movement functions happen, check to see if the badguy is touching the goodguy. 6.) implement multiple badguys. 7.) done! Turnin ------------ The turnin tag for this assignment is 'project4' and must include all code, header files, a Makefile, and a typescript showing compilation using '-ansi -pedantic'. The typescript need not show execution as there is no text requirement for this assignment. For grading, we will compile your code and execute it on a CSIL machine to verify correct functionality. You may include an optional README file with special grader instructions. Sample Output --------------- There is no required text output for this project. However, I have put a binary executable file on the website that should execute on the CSIL machines. Note that since this project is graphical in nature using the Xwindows system, you must be sitting in front of a CSIL machine in order to do the work. This project will not work over putty since it requires a local X display. When you download the binary, before you can execute it, you must set the permission flags to executable: chmod +x proj4 ./proj4