/* -- PAC-MAN --
Creator: Daniel Fraser, 991502630
Course: Intro to Media Computation
Finalized: September 16, 2018
Instructor: Nicholas Hesler
Move the mouse left-to-right to make Pac-Man eat pellets. Click the left mouse button to make the ghost "vulnerable".
*/
//Simply set up the window and background
void setup() {
noCursor();
size(400, 400);
background(0);
}
void draw() {
frameRate(60); //Regular frame rate
background(0); //Black background
//Pellets
noStroke();
fill(255, 255-((mouseX-100)*10)); //mouseX with alpha makes pellets transparent after Pac-Man "eats" it
ellipse(150, height/2, 10, 10);
fill(255, 255-((mouseX-200)*10));
ellipse(250, height/2, 10, 10);
fill(255, 255-((mouseX-300)*10));
ellipse(350, height/2, 10, 10);
fill(255);
ellipse(300, height/2+100, 10, 10); //Vertical pellets that do not interact with Pac-Man
ellipse(300, height/2-100, 10, 10);
ellipse(300, height/2+200, 10, 10);
ellipse(300, height/2-200, 10, 10);
//Ghost
noStroke();
fill(255, 0, 0);
arc(mouseX+200, height/2, 60, 60, PI, TWO_PI); //Ghost head
rectMode(CORNERS);
rect(mouseX+170, height/2, mouseX+230, (height/2)+20);//Ghost bulk body
arc(mouseX+180, (height/2)+20, 20, 30, 0, PI); //Left squib
arc(mouseX+200, (height/2)+20, 20, 30, 0, PI); //Middle squib
arc(mouseX+220, (height/2)+20, 20, 30, 0, PI); //Right squib
fill(255);
ellipse(mouseX+190, (height/2)-5, 15, 30); //Left eye
ellipse(mouseX+210, (height/2)-5, 15, 30); //Right eye
fill(0);
ellipse(mouseX+185, (height/2)-5, 10, 25); //Left pupil
ellipse(mouseX+205, (height/2)-5, 10, 25); //Right pupil
//Pac-Man himself
noStroke();
fill(255, 255, 0);
arc(mouseX, (height/2)+7, 75, 75, 0, PI+HALF_PI+(sin(mouseX*0.1))); //Sine oscilates; creates mouth movement
//Thick blue lines of the level geometry
rectMode(CENTER);
stroke(0, 0, 255);
strokeWeight(5);
noFill();
rect(100, 0, 300, 300, 10, 10, 10, 10); //Top bar
rect(100, 400, 300, 300, 10, 10, 10, 10); //Bottom bar
rect(500, 0, 300, 300, 10, 10, 10, 10); //Top right bar
rect(500, 400, 300, 300, 10, 10, 10, 10); //Top right bar
}
//When the mouse is pressed, the ghost turns blue or "vulnerable". Most of the code is copied from the code above
void mousePressed() {
frameRate(5); //Slower frame rate for new image
background(0); //Black background
//Pellets
noStroke();
fill(255, 255-((mouseX-100)*10)); //mouseX with alpha makes pellets transparent after Pac-Man "eats" it
ellipse(150, height/2, 10, 10);
fill(255, 255-((mouseX-200)*10));
ellipse(250, height/2, 10, 10);
fill(255, 255-((mouseX-300)*10));
ellipse(350, height/2, 10, 10);
fill(255);
ellipse(300, height/2+100, 10, 10); //Vertical pellets that do not interact with Pac-Man
ellipse(300, height/2-100, 10, 10);
ellipse(300, height/2+200, 10, 10);
ellipse(300, height/2-200, 10, 10);
//Ghost
noStroke();
fill(0, 0, 255);
arc(mouseX+200, height/2, 60, 60, PI, TWO_PI); //Ghost head
rectMode(CORNERS);
rect(mouseX+170, height/2, mouseX+230, (height/2)+20);//Ghost bulk body
arc(mouseX+180, (height/2)+20, 20, 30, 0, PI); //Left squib
arc(mouseX+200, (height/2)+20, 20, 30, 0, PI); //Middle squib
arc(mouseX+220, (height/2)+20, 20, 30, 0, PI); //Right squib
fill(255);
ellipse(mouseX+190, (height/2)-5, 15, 15); //Left eye
ellipse(mouseX+210, (height/2)-5, 15, 15); //Right eye
noFill();
stroke(255);
strokeWeight(3);
arc(mouseX+200, (height/2)+30, 40, 40, PI+QUARTER_PI, TWO_PI-QUARTER_PI); //Mouth
//Pac-Man himself
noStroke();
fill(255, 255, 0);
arc(mouseX, (height/2)+7, 75, 75, 0, PI+HALF_PI+(sin(mouseX*0.1))); //Sine oscilates; creates mouth movement
//Thick blue lines of the level geometry
rectMode(CENTER);
stroke(0, 0, 255);
strokeWeight(5);
noFill();
rect(100, 0, 300, 300, 10, 10, 10, 10); //Top bar
rect(100, 400, 300, 300, 10, 10, 10, 10); //Bottom bar
rect(500, 0, 300, 300, 10, 10, 10, 10); //Top right bar
rect(500, 400, 300, 300, 10, 10, 10, 10); //Top right bar
}