/* MORGAN LYN ASSIGNMENT 2 INTERACTIVE TOY Whack a Ghost,, A rip-off of Whack a Mole Mouse press over the ghost to hit the ghost (turn it black) Press any keyboard key to reset ghosts (back to white) Credits go to Daniel Shiffman (everything but mainly boolean expression to move ghosts) and classmate Zoe Chen (How to loop a pattern and turn ghosts black)*/ ///*Variables*/// //ghost variables float ghoststop; float ghostX; float ghostY; float ghostheadX; float ghostheadY; //fill variables for ghost float fill1; float fill2; float fill3; void setup() { size(400, 400); //ghost fill colours fill1 = 255; fill2 = 255; fill3 = 255; //ghost set up ghoststop = 0.5; ghostX = 90; ghostY = 290; ghostheadX = 110; ghostheadY = 290; } void draw() { //setting the colour of the background background(255, 204, 204); //The cursor is not visble when interacting with the drawing noCursor(); // draws the background game box drawBackgroundbox(); //draws the ghosts drawGhost1(); drawGhost2(); drawGhost3(); //MOVING THE GHOST// //logic to move ghost ghostY = ghostY -ghoststop; ghostheadY = ghostheadY -ghoststop; //boolean expression for ghost while (ghostY<220) { ghostY = 290; } while (ghostheadY<220) { ghostheadY = 290; } //draws the cover up ghost box drawCoverbg(); //draws the hammer drawHammer(); //draw deco drawdeco1(); drawdeco2(); } ///*FUNCTIONS*/// //mousepress turn ghosts black void mousePressed() { if (mouseX>90 && mouseX<130) { fill1=(0); } else if (mouseX>180 && mouseX<220) { fill2=(0); } else if (mouseX>270 && mouseX<310) { fill3=(0); } } void keyPressed() { fill1=(255); fill2=(255); fill3=(255); } //draw repeating pattern (game buttons) //draw decoX1 void drawdeco1() { //draw many decos for (int i =0; i<width; i+=30) { fill(255); noStroke(); rectMode(CENTER); rect(i, width-20, 20, 20); } } //draw decoX2 void drawdeco2() { //draw many decos for (int i =0; i<width; i+=30) { fill(255); noStroke(); rectMode(CENTER); rect(i, width-50, 20, 20); } } //DRAWING FUNCTIONS// //draws the background box void drawBackgroundbox() { //background square rectMode(CORNER); fill(204, 153, 153); noStroke(); rect(40, 40, 320, 280); //background lines stroke(153, 102, 102); strokeWeight(2); line(40, 40, 60, 60); line(340, 60, 360, 40); //background inner square fill(204, 153, 153); stroke(153, 102, 102); rect(60, 60, 280, 240); //background ghost sitting top noStroke(); fill(153, 153, 204); quad(60, 260, 40, 280, 360, 280, 340, 260); fill(204, 204, 255); rect(40, 280, 320, 40); } void drawCoverbg() { //background box fill(255, 204, 204); rectMode(CORNERS); rect(0, 320, 400, 400); //quad1 fill(153, 153, 204); quad(50, 270, 40, 280, 360, 280, 350, 270); //quad2 fill(204, 204, 255); quad(180, 270, 175, 275, 225, 275, 220, 270); //quad3 fill(204, 204, 255); quad(90, 270, 85, 275, 135, 275, 130, 270); //quad4 fill(204, 204, 255); quad(270, 270, 265, 275, 315, 275, 310, 270); //rect fill(204, 204, 255); rectMode(CORNER); rect(40, 280, 320, 40); } //GHOSTS// void drawGhost1() { //ghost body fill(fill1); rectMode(CORNER); rect(ghostX, ghostY, 40, 50); ellipse(ghostheadX, ghostheadY, 40, 40); //ghost 1 face fill(fill1); stroke(0); ellipse(ghostheadX-10, ghostheadY, 10, 10); ellipse(ghostheadX+10, ghostheadY, 10, 10); line(ghostheadX, ghostheadY+10, ghostheadX-10, ghostheadY+15); line(ghostheadX, ghostheadY+10, ghostheadX+10, ghostheadY+15); noStroke(); } void drawGhost2() { //ghost body fill(fill2); rectMode(CORNER); rect(180, ghostY, 40, 50); ellipse(200, ghostheadY, 40, 40); //ghost 2 face fill(fill2); stroke(0); strokeWeight(4); line(190, ghostheadY-8, 185+10, ghostheadY-5); line(205, ghostheadY-5, 200+10, ghostheadY-8); strokeWeight(2); ellipse(200-10, ghostheadY, 10, 10); ellipse(200+10, ghostheadY, 10, 10); line(190, ghostheadY+15, 195, ghostheadY+20); line(195, ghostheadY+20, 200, ghostheadY+15); line(200, ghostheadY+15, 205, ghostheadY+20); line(205, ghostheadY+20, 210, ghostheadY+15); noStroke(); } void drawGhost3() { //ghost body fill(fill3); rectMode(CORNER); rect(270, ghostY, 40, 50); ellipse(290, ghostheadY, 40, 40); //ghost 3 face fill(fill3); stroke(0); strokeWeight(2); ellipse(290-10, ghostheadY, 10, 10); ellipse(290+10, ghostheadY, 10, 10); line(280, ghostheadY+10, 280+10, ghostheadY+15); line(290, ghostheadY+15, 290+10, ghostheadY+10); noStroke(); } void drawHammer() { //hammer fill(153, 153, 204); strokeWeight(2); stroke(153, 102, 102); rectMode(CENTER); rect(mouseX, 170, 40, 80); fill(153, 102, 102); noStroke(); rect(mouseX, 130, 50, 10); rect(mouseX, 210, 50, 10); //hammer handle fill(153, 102, 102); noStroke(); rect(mouseX+60-(pmouseX-pmouseX), 170, 80, 10); rect(mouseX+100-(pmouseX-pmouseX), 170, 10, 30); }