//// CST 112 Midterm exam (2011 Nov. 18) for: +++ ADD YOUR NAME HERE +++ //// The name of this file is "midterm-YOURNAME.pde" /* For specifications and coding standards, see: http://www.suffolk.li/cst112/19cst112/midterm.html This code must be fully "modularized" and follow the "coding standards" including: -- meaningful names for variables and functions. -- a comment line preceding the code for each function. To receive credit for this exam, make sure you enter name where required, and name the uploaded file correctly as: "midterm-Lastname.pde" */ //// GLOBAL DATA //////// int score=0; // Score for the game. float xBall,yBall; // Position of the ball. float xBullets,yBullets; // Position of the first bullet. float xBomb,yBomb; // Position of the bomb. float xHero,yHero; // Position of our "HERO". void setup() { //////// Set up the game: screen size, initialize value. size( 800, 600 ); // Screen size is 800x600. frameRate=30; smooth(); initialize(); } void initialize() { //// Initialize vales for new game. score=0; xBall= 0; yBall= height/2; xBullets= 0; yBullets= height/4; xBomb= width/2; yBomb= 0; } void draw() { //// Move everything; then draw everything. //// MOVE: ball, Bullets, bomb, hero. moveBall(); moveBullets(); moveBomb(); moveHero(); // Also show effects of hits, etc. (and update score). //// DRAW: scene + ball, Bullets, bomb, hero. Also show score. drawScene(); drawBall( xBall, yBall ); drawBullets( xBullets, yBullets ); drawBomb( xBomb, yBomb ); drawHero( mouseX, mouseY ); // Hero follows the mouse! // NOTE: This "draw()" function should not contain any code that moves or draws on the screen. // Updating (moving, score-keeping, checking for hits, etc.) and drawing // should be done ONLY in the functions called by "draw()". } void drawScene() { //// Draw the background, show your name, and display the score. background( 192, 255, 255 ); text( "WHO ARE YOU????", 10, height-10 ); // NOTE: Be sure to change the above line to include YOUR NAME! // No credit will be given for anonymous programs! Sign your work (or forfeit it!) //// Display the score. text( "SCORE: " + score, width-100, 10); //// Display the score. } void keyPressed() { //// Respond to different keys if (key == 'R') initialize(); //// ++++ ADD YOUR OWN CODE HERE ++++ } void mousePressed() { //// Respond to mouse click. //// ++++ ADD YOUR OWN CODE HERE ++++ } //// REMINDER: Be sure to place a // COMMENT at the beginnig of each function. //// (Functions that do not begin with a COMMENT will not be graded!) //// STUBS -- FILL THESE IN! void moveBall() { //// Move the ball (bouncing off the walls, bouncing off Hero). xBall= xBall + 5; yBall= yBall + 2; //// ++++ ADD YOUR OWN CODE HERE ++++ } void moveBullets() { //// Move the flock of Bullets. Take care of hits. //// ++++ ADD YOUR OWN CODE HERE ++++ } void moveBomb() { //// Move the bomb (downward). Take care of hits. //// ++++ ADD YOUR OWN CODE HERE ++++ } void moveHero() { //// Hero follows mouse. Nothing to do, here. } //////// DRAW: ball, Bullets, bomb, hero. Also show score. void drawBall( float x, float y ){ //// Draw red ball at (x,y); fill(255,0,0); ellipse( x, y, 50,50 ); } void drawBullets( float x, float y ){ //// Draw a bunch of Bullets. //// ++++ REPLACE THIS CODE WITH A LOOP! ++++ drawOneBullet( x, y ); drawOneBullet( x+50, y+100 ); drawOneBullet( x+100, y+200 ); drawOneBullet( x+150, y+300 ); drawOneBullet( x+200, y+400 ); } void drawOneBullet( float x, float y ){ //// Draw a single Bullet. //// ++++ REPLACE THIS WITH OWN CODE HERE ++++ fill(192); rect( x,y, 20,10 ); } void drawBomb( float x, float y ){ //// ++++ REPLACE THIS WITH OWN CODE HERE ++++ fill(127); rect( x,y+50, 10,30 ); } void drawHero( float x, float y ){ //// Hero follows the mouse! fill(0); rect( x, y, 20,40 ); //// +++++ Change the above code to draw correct figure !!!! // //// ++++ ADD YOUR OWN CODE HERE ++++ }