/* PACMAN: By Sanaa Memon // // September 21st, 2016 // ~ Pacman and the ghosts follow the horizontal position of the cursor. ~ Clicking the mouse changes your score, makes Pacman close his mouth, and turns the ghosts blue. //________________________*/ void setup() { //Set canvas size to 400 square pixels size(400, 400); //Hide the cursor noCursor(); } void draw() { //Draw rectangles by specifying the top-left vertex, width & height rectMode(CORNER); //Shapes will have no stroke noStroke(); //Top bar for score fill(20); rect(0, 0, 400, 120); stroke(0, 0, 255); strokeWeight(10); fill(20); rect(50, 20, 300, 80); //Fake score counter fill(255); textAlign(CENTER); textSize(30); text("SCORE: 0", 200, 70); //Ground Plane noStroke(); fill(100); rect(0, 220, 400, 60); fill(75); rect(0, 270, 400, 10); //Bottom bar for lives fill(20); rect(0, 280, 400, 120); stroke(255); strokeWeight(4); rect(10, 290, 380, 100); //Smooth all shapes smooth(); //Pacman Lives noStroke(); fill(255, 220, 0); arc(40, 340, 40, 40, PI/6, 11*PI/6); arc(90, 340, 40, 40, PI/6, 11*PI/6); arc(140, 340, 40, 40, PI/6, 11*PI/6); //Cherry Stem noFill(); stroke(105, 62, 42); strokeWeight(3); arc(387, 380, 160, 160, 7*PI/6, 17*PI/12); line(360, 360, 368, 302); //Cherry Shading noStroke(); fill(200, 0, 0); ellipse(316, 340, 40, 40); ellipse(356, 360, 40, 40); //Cherries fill(255, 0, 0); ellipse(320, 340, 40, 40); ellipse(360, 360, 40, 40); //Cherry Highlight fill(255); ellipse(318, 339, 30, 30); fill(255, 0, 0); ellipse(321, 338, 30, 30); fill(255); ellipse(357, 360, 30, 30); fill(255, 0, 0); ellipse(359, 358, 30, 30); //BRICK WALL BACKGROUND //Set stroke weight to 3 px //Bricks have light grey stroke strokeWeight(3); stroke(200); //Light grey bricks fill(180); rect(0, 120, 60, 20, 5); rect(120, 120, 60, 20, 5); rect(240, 120, 60, 20, 5); rect(360, 120, 60, 20, 5); rect(100, 180, 60, 20, 5); rect(120, 160, 60, 20, 5); rect(280, 140, 60, 20, 5); rect(300, 200, 60, 20, 5); rect(40, 140, 60, 20, 5); rect(120, 200, 60, 20, 5); rect(220, 180, 60, 20, 5); //Medium grey bricks fill(150); rect(0, 140, 40, 20, 5); rect(160, 140, 60, 20, 5); rect(220, 140, 60, 20, 5); rect(340, 140, 60, 20, 5); rect(280, 180, 60, 20, 5); rect(40, 180, 60, 20, 5); rect(300, 160, 60, 20, 5); rect(240, 160, 60, 20, 5); rect(240, 200, 60, 20, 5); rect(60, 200, 60, 20, 5); rect(60, 120, 60, 20, 5); rect(300, 120, 60, 20, 5); //Dark grey bricks fill(120); rect(0, 160, 60, 20, 5); rect(60, 160, 60, 20, 5); rect(180, 160, 60, 20, 5); rect(360, 160, 60, 20, 5); rect(180, 120, 60, 20, 5); rect(100, 140, 60, 20, 5); rect(0, 180, 40, 20, 5); rect(160, 180, 60, 20, 5); rect(340, 180, 60, 20, 5); rect(0, 200, 60, 20, 5); rect(180, 200, 60, 20, 5); rect(360, 200, 60, 20, 5); rect(280, 140, 60, 20, 5); //Pacman Shadow noStroke(); fill(50, 200); ellipse(50+mouseX/2, 240, 80, 15); fill(0, 150); ellipse(50+mouseX/2, 240, 60, 10); //PACMAN noStroke(); fill(255, 220, 0); arc(50+mouseX/2, 200, 80, 80, PI/6, 11*PI/6); //Darker yellow arc for shading fill(255, 180, 0); arc(50+mouseX/2, 200, 80, 80, 5*PI/12, 7*PI/6); fill(255, 220, 0); arc(55+mouseX/2, 195, 80, 80, 5*PI/12, 7*PI/6); //PINK GHOST SHADING fill(217, 70, 134); ellipse(207+mouseX/3, 190, 60, 60); rect(177+mouseX/3, 190, 60, 30); triangle(177+mouseX/3, 220, 197+mouseX/3, 220, 177+mouseX/3, 240); triangle(197+mouseX/3, 220, 207+mouseX/3, 240, 217+mouseX/3, 220); triangle(217+mouseX/3, 220, 237+mouseX/3, 220, 237+mouseX/3, 240); //PINK GHOST fill(50, 200); ellipse(210+mouseX/3, 240, 80, 15); fill(0, 150); ellipse(210+mouseX/3, 240, 60, 10); fill(255, 139, 195); ellipse(210+mouseX/3, 190, 60, 60); rect(180+mouseX/3, 190, 60, 30); triangle(180+mouseX/3, 220, 200+mouseX/3, 220, 180+mouseX/3, 240); triangle(200+mouseX/3, 220, 210+mouseX/3, 240, 220+mouseX/3, 220); triangle(220+mouseX/3, 220, 240+mouseX/3, 220, 240+mouseX/3, 240); fill(255); ellipse(195+mouseX/3, 190, 20, 20); ellipse(225+mouseX/3, 190, 20, 20); fill(0); ellipse(190+mouseX/3, 190, 10, 10); ellipse(220+mouseX/3, 190, 10, 10); //GREEN GHOST SHADING fill(0, 150, 0); ellipse(297+mouseX/3, 190, 60, 60); rect(267+mouseX/3, 190, 60, 30); triangle(267+mouseX/3, 220, 287+mouseX/3, 220, 267+mouseX/3, 240); triangle(287+mouseX/3, 220, 297+mouseX/3, 240, 307+mouseX/3, 220); triangle(307+mouseX/3, 220, 327+mouseX/3, 220, 327+mouseX/3, 240); fill(255); ellipse(285+mouseX/3, 190, 20, 20); ellipse(315+mouseX/3, 190, 20, 20); fill(0); ellipse(280+mouseX/3, 190, 10, 10); ellipse(310+mouseX/3, 190, 10, 10); //GREEN GHOST fill(50, 200); ellipse(300+mouseX/3, 240, 80, 15); fill(0, 150); ellipse(300+mouseX/3, 240, 60, 10); fill(0, 235, 0); ellipse(300+mouseX/3, 190, 60, 60); rect(270+mouseX/3, 190, 60, 30); triangle(270+mouseX/3, 220, 290+mouseX/3, 220, 270+mouseX/3, 240); triangle(290+mouseX/3, 220, 300+mouseX/3, 240, 310+mouseX/3, 220); triangle(310+mouseX/3, 220, 330+mouseX/3, 220, 330+mouseX/3, 240); fill(255); ellipse(285+mouseX/3, 190, 20, 20); ellipse(315+mouseX/3, 190, 20, 20); fill(0); ellipse(280+mouseX/3, 190, 10, 10); ellipse(310+mouseX/3, 190, 10, 10); if (mousePressed) { //PACMAN'S closed-mouth state fill(255, 220, 0); ellipse(50+mouseX/2, 200, 80, 80); fill(255, 180, 0); arc(50+mouseX/2, 200, 80, 80, 5*PI/12, 7*PI/6); fill(255, 220, 0); arc(55+mouseX/2, 195, 80, 80, 5*PI/12, 7*PI/6); //Turn Pink ghost Blue fill(0, 0, 180); ellipse(207+mouseX/3, 190, 60, 60); rect(177+mouseX/3, 190, 60, 30); triangle(177+mouseX/3, 220, 197+mouseX/3, 220, 177+mouseX/3, 240); triangle(197+mouseX/3, 220, 207+mouseX/3, 240, 217+mouseX/3, 220); triangle(217+mouseX/3, 220, 237+mouseX/3, 220, 237+mouseX/3, 240); fill(0, 0, 255); ellipse(210+mouseX/3, 190, 60, 60); rect(180+mouseX/3, 190, 60, 30); triangle(180+mouseX/3, 220, 200+mouseX/3, 220, 180+mouseX/3, 240); triangle(200+mouseX/3, 220, 210+mouseX/3, 240, 220+mouseX/3, 220); triangle(220+mouseX/3, 220, 240+mouseX/3, 220, 240+mouseX/3, 240); fill(255); ellipse(195+mouseX/3, 190, 20, 20); ellipse(225+mouseX/3, 190, 20, 20); //Turn Green ghost Blue fill(0, 0, 180); ellipse(297+mouseX/3, 190, 60, 60); rect(267+mouseX/3, 190, 60, 30); triangle(267+mouseX/3, 220, 287+mouseX/3, 220, 267+mouseX/3, 240); triangle(287+mouseX/3, 220, 297+mouseX/3, 240, 307+mouseX/3, 220); triangle(307+mouseX/3, 220, 327+mouseX/3, 220, 327+mouseX/3, 240); fill(0, 0, 255); ellipse(300+mouseX/3, 190, 60, 60); rect(270+mouseX/3, 190, 60, 30); triangle(270+mouseX/3, 220, 290+mouseX/3, 220, 270+mouseX/3, 240); triangle(290+mouseX/3, 220, 300+mouseX/3, 240, 310+mouseX/3, 220); triangle(310+mouseX/3, 220, 330+mouseX/3, 220, 330+mouseX/3, 240); fill(255); ellipse(285+mouseX/3, 190, 20, 20); ellipse(315+mouseX/3, 190, 20, 20); //Change Score when mouse is pressed stroke(0, 0, 255); strokeWeight(10); fill(20); rect(50, 20, 300, 80); fill(255); textAlign(CENTER); textSize(30); text("SCORE: 100,000", 200, 70); } }