/*////////////////////////////////////////////////////////////////////////////////////////////// ** Crocodile Dentist by Annie Wang ** click to simulate pushing down the bottom teeth of the crocodile, like the real game ** if the trigger tooth is pushed, the crocodile chomps down and you lose ** if every tooth except for the trigger is pushed, you win /*////////////////////////////////////////////////////////////////////////////////////////////// //set initial height of tooth (theight where t=tooth) int theight=55; //set tooth height when pressed down (pheight where p=pressed) int pheight=20; //set tooth width, this doesnt change int twidth=25; //set different tooth heights: l means left, r means right; counting from the center int t0h=theight; int tl1h=theight; int tr1h=theight; int tl2h=theight; int tr2h=theight; int tl3h=theight; int tr3h=theight; int tl4h=theight; int tr4h=theight; int tl5h=theight; int tr5h=theight; //set starting win/lose booleans to false so it doesnt display the win or lose screen until the event happens boolean lose = false; boolean win = false; //setup the canvas and modes void setup () { size (600, 600); background (#BCDBFF); noStroke (); rectMode (CORNERS); // instructions println ("CROCODILE DENTIST"); println ("Click the teeth to push them down"); println ("If you push the trigger tooth, you lose"); println ("If every tooth except for the trigger is pushed, you win"); println ("Refresh to start over"); } void draw () { // lose screen: screen turns red and lose message is displayed if (lose) { fill (#F25656); rect (0, 0, 600, 600); fill(#7E1717); textSize (26); text ("You Lose! Refresh to play again.", 100, 250); println ("You Lose!"); // sad face fill (#FFFF6A); ellipse (300, 400, 150, 150); fill (0); ellipse (270, 370, 20, 20); ellipse (330, 370, 20, 20); noFill(); arc (300, 450, 80, 80, radians (-150), radians (-30)); } // win screen: screen turns green and win message is displayed else if (win) { fill (#91FF7C); rect (0, 0, 600, 600); fill(#397E17); textSize (26); text ("You Win! Refresh to play again.", 100, 250); println ("You Win!"); // happy face fill (#FFFF6A); ellipse (300, 400, 150, 150); fill (0); ellipse (270, 370, 20, 20); ellipse (330, 370, 20, 20); noStroke (); arc (300, 410, 80, 80, radians (0), radians (180)); } // GAME // since starting the game means lose and win are both false, the game is else { drawCrocodile (); } } void drawCrocodile () { //wallpaper pattern for (int i=20; i<600; i+=60) { noStroke (); fill (#71B9FF, 80); rect (i, 0, i+30, 600); } for (int i=20; i<600; i+=60) { noStroke (); fill (255, 80); rect (0, i, 600, i+30); } //table stroke (0); strokeWeight (2); fill (#93774D); rect (0, 320, 600, 600); //table pattern for (int i=320; i<600; i+=50) { stroke (#5A3C27); line (0, i, 600, i); } // game name sign // string stroke (0); line (20, 80, 300, 10); line (580, 80, 300, 10); // nail noStroke (); fill (150); ellipse (300, 17, 17, 17); stroke (50); strokeWeight (4); line (300, 12, 300, 22); line (295, 17, 305, 17); // board stroke (#5A3C27); strokeWeight (10); fill (255); rect (20, 80, 580, 180); // text fill(random (0,255), random (0,255), random (0,255)); textSize (50); text ("CROCODILE DENTIST", 50, 150); // CROCODILE // lower jaw stroke (0); strokeWeight (2); fill(#2BBF1F); arc (300, 440, 280, 230, radians (0), radians (180)); quad (180, 310, 160, 441, 440, 441, 420, 310); arc (300, 440, 280, 160, radians (0), radians (180)); // lower gums fill (#EA0514); quad (185, 300, 165, 441, 435, 441, 415, 300); arc (300, 440, 270, 150, radians (0), radians (180)); // tounge fill (#F52F3C); quad (240, 300, 220, 426, 380, 426, 370, 300); arc (300, 425, 160, 100, radians (0), radians (180)); // head fill(#2BBF1F); arc (260, 290, 150, 230, radians (-180), radians (0)); arc (340, 290, 150, 230, radians (-180), radians (0)); noStroke (); rect (270, 194, 330, 300); // eyes stroke (0); strokeWeight (2); fill(255); ellipse (258, 230, 58, 70); ellipse (342, 230, 58, 70); // iris // the iris moves with the mouse fill(#17A00B); ellipse (258+(mouseX-300)/25, 225+(mouseY-300)/30, 25, 25); ellipse (342+(mouseX-300)/25, 225+(mouseY-300)/30, 25, 25); fill (0); ellipse (258+(mouseX-300)/25, 225+(mouseY-300)/30, 12, 12); ellipse (342+(mouseX-300)/25, 225+(mouseY-300)/30, 12, 12); fill(255); noStroke (); ellipse (255+(mouseX-300)/25, 222+(mouseY-300)/30, 8, 8); ellipse (339+(mouseX-300)/25, 222+(mouseY-300)/30, 8, 8); constrain (mouseX, 0, 600); constrain (mouseY, 0, 600); //constrain mouse so the irises dont go outside of the eyes when the mouse is off the canvas // upper gums stroke (0); strokeWeight (2); fill (#EA0514); arc (300, 345, 280, 80, radians (0), radians (180)); // upper teeth (inactive) fill (255); arc (300, 345, 35, 70, radians (0), radians(180)); arc (240, 340, 35, 70, radians (0), radians(180)); arc (360, 340, 35, 70, radians (0), radians(180)); arc (190, 330, 32, 70, radians (0), radians(180)); arc (410, 330, 32, 70, radians (0), radians(180)); // upper mouth fill (#11B404); arc (300, 340, 300, 200, radians (-180), radians (0)); fill(#2BBF1F); arc (300, 340, 300, 50, radians (0), radians (180)); arc (240, 340, 180, 200, radians (-180), radians (0)); arc (360, 340, 180, 200, radians (-180), radians (0)); noStroke (); rect (200, 267, 400, 350); // nostrils stroke (0); strokeWeight (2); fill (0); ellipse (230, 310, 70, 50); ellipse (370, 310, 70, 50); // teeth fill (255); drawTeeth (300, 500, t0h); drawTeeth (260, 495, tl1h); drawTeeth (340, 495, tr1h); drawTeeth (227, 480, tl2h); drawTeeth (373, 480, tr2h); drawTeeth (200, 460, tl3h); drawTeeth (400, 460, tr3h); drawTeeth (192, 430, tl4h); drawTeeth (408, 430, tr4h); drawTeeth (192, 400, tl5h); drawTeeth (408, 400, tr5h); } // user defined function to draw teeth based on tooth location (X & Y) and tooth number void drawTeeth (int tX, int tY, int tnumber) { arc (tX, tY, twidth, tnumber, radians (-180), radians(0)); } void mousePressed () { //t0 if (mousePressed && mouseX<300+twidth/2 && mouseX>300-twidth/2 && mouseY>500-theight/2 && mouseY<500) { t0h=pheight; } //tl1 if (mousePressed && mouseX<260+twidth/2 && mouseX>260-twidth/2 && mouseY>495-theight/2 && mouseY<495) { tl1h=pheight; } //tr1 if (mousePressed && mouseX<340+twidth/2 && mouseX>340-twidth/2 && mouseY>495-theight/2 && mouseY<495) { tr1h=pheight; } //tl2 if (mousePressed && mouseX<227+twidth/2 && mouseX>227-twidth/2 && mouseY>480-theight/2 && mouseY<480) { tl2h=pheight; } //tr2 if (mousePressed && mouseX<373+twidth/2 && mouseX>373-twidth/2 && mouseY>480-theight/2 && mouseY<480) { tr2h=pheight; } //tl3*** trigger tooth if (mousePressed && mouseX<200+twidth/2 && mouseX>200-twidth/2 && mouseY>460-theight/2 && mouseY<460) { tl3h=pheight; lose=true; } //tr3 if (mousePressed && mouseX<400+twidth/2 && mouseX>400-twidth/2 && mouseY>460-theight/2 && mouseY<460) { tr3h=pheight; } //tl4 if (mousePressed && mouseX<192+twidth/2 && mouseX>192-twidth/2 && mouseY>430-theight/2 && mouseY<430) { tl4h=pheight; } //tr4 if (mousePressed && mouseX<408+twidth/2 && mouseX>408-twidth/2 && mouseY>430-theight/2 && mouseY<430) { tr4h=pheight; } //tl5 if (mousePressed && mouseX<192+twidth/2 && mouseX>192-twidth/2 && mouseY>400-theight/2 && mouseY<400) { tl5h=pheight; } //tr5 if (mousePressed && mouseX<408+twidth/2 && mouseX>408-twidth/2 && mouseY>400-theight/2 && mouseY<400) { tr5h=pheight; } if (t0h==pheight && tl1h==pheight && tr1h==pheight && tl2h==pheight && tr2h==pheight && tr3h==pheight && tl4h==pheight && tr4h==pheight && tl5h==pheight && tr5h==pheight) { win=true; println ("You Win!") ; } }