//Jose M. Pena //game fixed String title = " CST112 ET GAME Jose M. Pena"; int score = 0; int numhits = 0; float etX, etY; float etSX, etSY; ///// float sunX, sunY; float speed; ///// float bombX, bombY; float bombSY; ////// float bulletX1,bulletY1; float bulletX2,bulletY2; float bulletX3,bulletY3; float bulletS; void setup(){ size(900,700); initialize(); smooth(); } void initialize(){ score = 0; etX = mouseX; etY = mouseY; etSX = 1; etSY= 3.3; //////// sunX = 0; sunY = 50; speed = .5; ///////// bombX = 0; bombY = -1; bombSY = 5; //bomb falls 5 frames ///////// bulletX1 = 0; bulletY1 = -150; bulletX2 = 0; bulletY2 = -150; bulletX3 = 0; bulletY3 = -150; bulletS = 10; } void draw(){ scene(); et(); bomb(); bullets(); checkHit(); } void keyPressed(){ //drops bomb if (key == 'b' || key == 'B') { bombX = random(width); bombY = 10; } else if(key == 'r' || key== 'R') //reset score score = 0; } void scene(){ background(100,100,200); fill(127,255,127); rectMode(CENTER); ellipseMode(CENTER); rect(0,height,width*2,height+500); fill(0); grass(); text( "SCORE: " + score, width-100, 100); //// Display the score. text( " PRESS B TO DROP BTHE BOMB." , width - 300,100); text(title,10,height-20); etX += etSX; etY += etSY; sunX += speed; //sun fill(250,250,0); ellipse(sunX,sunY,100,100); if ((etX > width) || (etX < 0)){ score = score + 1; } } void et(){ //draw et's body stroke(0); fill(255,0,0); rect(etX,etY,45,65); //draw et's head stroke(0); fill(0,255,0); ellipse(etX,etY-75,90,85); //draw et eyes stroke(0); fill(255); ellipse(etX-19,etY-80,16,32);//left ellipse(etX+19,etY-80,16,32);//right //draw et's pants stroke(0); fill(0,0,100); rect(etX+13,etY+51,19,35);//right rect(etX-13,etY+51,19,35);//left //shoes stroke(0); fill(255); rect(etX+12,etY+71,22,10);//right rect(etX-14,etY+71,22,10);//left if ((etX > width) || (etX < 0)){ etSX = etSX * -1; } if ((etY > height-70)|| (etY < 220)){ etSY = etSY * -1; } if ((sunX > width)|| (sunX < 0)){ speed = speed * -1; } if ((etY > height-70)|| (etY < 220)){ score = score + 1; } if (mousePressed == true) { etX = mouseX; etY = mouseY; } if (mousePressed == false) { etX = etX; etY = etY; } if (numhits > 0){ fill(0); text(numhits, etX - 5, etY); } } void bomb(){ //bomb if (bombY < 0 || bombY > height){ return; } bombY += bombSY; fill(0); //black ellipse(bombX, bombY, 50, 50); } void bullets(){ if(keyPressed){ if( key == 'q'){ bulletX1 = 0; bulletY1 = 150; } } if(keyPressed){ if( key == 'w'){ bulletX2 = 0; bulletY2 = 350; } } if(keyPressed){ if( key == 'e'){ bulletX1 = 0; bulletY1 = 600; } } //// make bullets fly across screen, but only when on the screen fill(0); if (bulletX1 > 0 || bulletX1 < width){ ellipse(bulletX1,bulletY1, 20,20); bulletX1 += bulletS; } if (bulletX2 > 0 || bulletX2 < width){ ellipse(bulletX2,bulletY2, 20,20); bulletX2 += bulletS; } if (bulletX3 > 0 || bulletY3 < width){ ellipse(bulletX3,bulletY3, 20,20); bulletX3 += bulletS; } //bullet holders fill(100); rect(0,150,10,30); rect(0,350,10,30); rect(0,600,10,30); } void grass(){ stroke(0,127,0); float wave= mouseX-pmouseX; for (float x=0; x