/*Tyler Tam 991476113
Pikmin throw. (Interactive toy)
9/28/2017
Why climb a tree to get an apple, when you have an endless supply of Pikmin at hand?!
Instead of exerting all that extra effort, you should buy some Pikmin seeds! Not only
do you gain the excitment of giving life, but you also atain the exhilaration of throwing
all your anger away while simultaniously committing murder! Though some folks may say
"murder is wrong," or, "murder is illegal," well I have just one thing to say to you!
It isnt a crime if no one is there to see it!
*/
int flowingWater = 0;
int flowingWaterBool = 1;
int cloud1X;
int cloud2X= 300;
int cloud3X=200;
int cloud1Y;
int cloud2Y;
int cloud3Y;
int daytimeChecker = 1;
int daytimeColor = 200;
int pikminDistance = -30;
int pikminColor = 0;
int pikminX = 200;
int pikminY = 200;
int pikminW = 80;
int pikminH = 80;
int colorSelector =0;
int appleY = 50;
int pikminCounter = 0;
boolean appleFallCheck =false;
boolean pikminThrown = false;
boolean pikminThrownBall= false;
boolean pikminThrownUncurled = false;
void setup() {
size(400, 400);
}
void draw() {
frameRate(50);
drawBackEnvironment(); //Draws the environment that will be behind the pikmin, so it doesnt hide them
pikminThrowChecker(); //The if for the Pikmin is in this
drawFrontEnvironment(); //Draws the environment that obscures the pikmin near the bottom
selector(); //Draws the Pikmin Selector so it isnt affected by anything
}
//Everything under this is custom draw functions
void drawBackEnvironment() {
colorMode(RGB, 255, 255, 255);
background(0, daytimeColor, daytimeColor + 55);
//Draw the sun or moon
if (daytimeChecker == 1) {
daytimeColor = 200;
colorMode(HSB, 360, 200, 100);
noStroke();
fill(53, daytimeColor, 100);
ellipse(380, 20, 70, 70);
} else if (daytimeChecker==0) {
daytimeColor = 0;
colorMode(HSB, 360, 200, 100);
fill(255);
ellipse(380, 20, 70, 70);
}
//Draw the clouds
cloud1X++;
cloud2X ++;
cloud3X++;
//If any of the clouds go off screen, they reset at a random Y
if (cloud1X >= width + 170) {
cloud1X = 0 - 170;
cloud1Y = (int)random(50);
}
if (cloud2X >= width + 200) {
cloud2X = 0 - 200;
cloud2Y = (int)random(50);
}
if (cloud3X >= width + 100) {
cloud3X = 0 - 100;
cloud3Y = (int)random(50);
}
drawClouds(cloud1X, cloud2X, cloud3X, cloud1Y, cloud2Y, cloud3Y);
//Draw the tree
colorMode(RGB, 255, 255, 255);
stroke(179, 115, 60);
strokeWeight(1);
fill(179, 115, 60);
triangle(0, 260, 100, 320, 0, 320);
quad(0, 320, 40, 320, 40, 0, 0, 0);
triangle(40, 0, 40, 40, 120, 0);
triangle(80, 20, 140, 20, 120, 0);
triangle(120, 0, 140, 20, 180, 0);
//Draw the apple that hangs on the tree
drawApple();
//Draw the rock
colorMode(RGB, 255, 255, 255);
fill(117, 117, 117);
stroke(117, 117, 117);
strokeWeight(1);
quad(160, 320, 280, 320, 260, 260, 180, 260);
quad(180, 260, 240, 260, 220, 240, 200, 240);
}
void drawFrontEnvironment() {
colorMode(RGB, 255, 255, 255);
//Draw the Water
if (flowingWater <=199) {
flowingWater++;
} else {
flowingWater=0;
} //Makes the water seem wavy
drawWater(flowingWater);
//Draw the grass
colorMode(RGB, 255, 255, 255);
rectMode(CORNERS);
fill(0, 125, 14);
rect(0, 290, 280, 320);
triangle(280, 320, 290, 290, 280, 290);
//Loops to draw 30 grass blades
for (int g = 0; g<30; g++) {
drawGrass(g);
}
fill(10, 175, 115);
strokeWeight(1);
stroke(10, 175, 115);
rect(0, 320, 280, 400);
//If it is night, this adds a semi transparent black retangle to simulate night.
if (daytimeChecker == 1) {
daytimeColor = 200;
colorMode(RGB, 255, 255, 255, 400);
noStroke();
rectMode(CORNERS);
fill(0, 0, 0, 0);
rect(0, 0, 400, 400);
} else if (daytimeChecker==0) {
colorMode(RGB, 255, 255, 255, 400);
daytimeColor = 0;
noStroke();
fill(0, 0, 0, 200);
rect(0, 0, 400, 400);
}
//Draws the pikmin color selector
pikminBox();
}
//Draws the apple that can fall
void drawApple() {
appleFall();
colorMode(RGB, 255, 255, 255);
strokeWeight(4);
stroke(224, 145, 0);
curve(100, appleY, 90, appleY - 15, 108, appleY-30, 110, appleY-20);
fill(255, 0, 0);
stroke(255, 0, 0);
strokeWeight(2);
ellipseMode(CENTER);
ellipse(83, appleY, 20, 35);
ellipse(100, appleY, 20, 35);
ellipse(91, appleY, 20, 35);
}
//Checks if the apple is falling
void appleFall() {
if (appleFallCheck == true) {
appleY = appleY + 10;
if (appleY>=height) {
appleFallCheck =false;
println("Apple Collected!");
}
}
}
void pikminBox() {
colorMode(HSB, 360, 100, 100);
fill(46, 0, 24);
stroke(10);
strokeWeight(2);
rectMode(CORNERS);
rect(100, 340, 300, 400);
//Below is the pikmin Chooser
//Red Pikmin
fill(0, 83, 89);
noStroke();
ellipse(125, 365, 20, 20);
ellipse(125, 375, 10, 30);
stroke(0, 83, 89);
strokeWeight(3);
line(123, 375, 120, 392);
line(123, 375, 129, 392);
line(123, 370, 114, 378);
line(123, 370, 134, 378);
noFill();
curve(140, 355, 122, 358, 130, 350, 123, 370);
stroke(93, 70, 74);
line(130, 350, 135, 347);
//Blue Pikmin
fill(200, 92, 88);
noStroke();
ellipse(176, 365, 20, 20);
ellipse(176, 375, 10, 30);
stroke(200, 92, 88);
strokeWeight(3);
line(174, 375, 172, 392);
line(174, 375, 181, 392);
line(174, 370, 166, 378);
line(174, 370, 186, 378);
noFill();
curve(192, 355, 174, 358, 182, 350, 175, 370);
stroke(93, 70, 74);
line(182, 350, 187, 347);
//Yellow Pikmin
fill(46, 100, 100);
noStroke();
ellipse(224, 365, 20, 20);
ellipse(224, 375, 10, 30);
stroke(46, 100, 100);
strokeWeight(3);
line(222, 375, 219, 392);
line(222, 375, 228, 392);
line(222, 370, 213, 378);
line(222, 370, 233, 378);
noFill();
curve(239, 355, 221, 358, 229, 350, 223, 370);
stroke(93, 70, 74);
line(229, 350, 234, 347);
//Rock Pikmin
fill(46, 0, 70);
strokeWeight(1);
stroke(46, 0, 70);
quad(260, 370, 265, 362, 285, 362, 290, 370);
triangle(265, 362, 285, 362, 275, 360);
rectMode(CORNERS);
rect(260, 370, 290, 385);
quad(260, 385, 265, 390, 285, 390, 290, 385);
quad(270, 390, 270, 393, 260, 393, 265, 390);
quad(280, 390, 280, 393, 290, 393, 285, 390);
strokeWeight(3);
line(260, 370, 255, 380);
line(288, 370, 295, 380);
curve(280, 370, 275, 363, 280, 350, 290, 355);
stroke(93, 70, 74);
line(280, 350, 285, 348);
}
void selector() {
//This is what indicates which pikmin color is currently selected
colorMode(RGB, 255, 255, 255, 100);
fill(188, 188, 188, 40);
stroke(117, 117, 117, 100);
rectMode(CORNERS);
rect(colorSelector*50 + 100, 340, colorSelector*50 + 150, 400);
}
void drawGrass (int grassX) {
colorMode(RGB, 255, 255, 255);
stroke(10, 175, 115);
strokeWeight(3);
noFill();
curve(340-(grassX * 10), 300, 300-(grassX * 10), 280, 280-(grassX * 10), 320, 300-(grassX * 10), 350);
}
void drawWater(int waterHeight) {
//Draw the Water
rectMode(CORNERS);
fill(0, 90, 255);
stroke(0, 90, 255);
rect(280, 330, 400, 400);
//Creates the false sensation of waves using ellipses that are the same colour as the background
fill(0, daytimeColor, daytimeColor + 55);
noStroke();
ellipseMode(CENTER);
ellipse(280-(waterHeight), 330, 100, 20);
fill(0, 90, 255);
ellipse(380-(waterHeight), 331, 98, 20);
fill(0, daytimeColor, daytimeColor + 55);
ellipse(480-(waterHeight), 330, 100, 20);
fill(0, 90, 255);
ellipse(580-(waterHeight), 331, 98, 20);
}
void drawClouds(int c1X, int c2X, int c3X, int c1Y, int c2Y, int c3Y) {
colorMode(RGB, 255, 255, 255, 100);
noStroke();
fill(255, 255, 255, 80);
ellipse(c1X, c1Y, 170, 50);
ellipse(c2X, c2Y, 200, 40);
ellipse(c3X, c3Y, 100, 30);
}
void pikminThrowChecker(){
if (pikminThrown == true) {
if (pikminThrownBall == true) {
drawPikmin();
pikminW--;
pikminH--;
pikminDistance++;
if (pikminDistance >= 30) {
pikminThrownBall = false;
pikminW=80;
pikminH=80;
pikminDistance = -5;
pikminThrownUncurled = true;
}
}
if (pikminThrownUncurled ==true) {
//If the pikmin hits the apple in it's descent, the apple falls
if (pikminX >=70 && pikminX<=110 && pikminY+(pikminDistance*pikminDistance/10) >=30 && pikminY+(pikminDistance*pikminDistance/10) <=70 && pikminColor !=3) {
appleFallCheck = true;
}
pikminDistance++;
drawPikmin();
if (pikminDistance == 60) {
pikminThrownUncurled = false;
pikminThrown = false;
pikminDistance = -30;
pikminCounter++;
print(pikminCounter);
println(" Pikmin sacrificed!");
}
}
}
}
void drawPikmin() {
//Draws the pikmin in motion
noStroke();
//Draws the pikmin as a ball
if (pikminThrownBall == true) {
if (pikminColor>=0 && pikminColor<=2) {
colorMode(HSB, 360, 100, 100);
noStroke();
fill(93, 100, 74);//green leaf
ellipse(pikminX, pikminY+(pikminDistance*pikminDistance/10)-30, pikminW, pikminH);
fill(360 - pikminColor * 158, 100, 100);//body color
arc(pikminX, pikminY+(pikminDistance*pikminDistance/10)-30, pikminW, pikminH, 0-QUARTER_PI, PI + QUARTER_PI);
//If its the rock Pikmin
} else if (pikminColor == 3) {
frameRate(60);
colorMode(HSB, 360, 100, 100);
strokeWeight(1);
noStroke();
fill(0, 0, 58);
ellipse(pikminX, pikminY+((pikminDistance+40)*(pikminDistance+40)/10)+20, pikminW, pikminH);
ellipse(pikminX, pikminY+((pikminDistance+40)*(pikminDistance+40)/10)+20, pikminW+20, pikminH);
ellipse(pikminX, pikminY+((pikminDistance+40)*(pikminDistance+40)/10)+20, pikminW, pikminH+20);
fill(93, 100, 74);//green leaf
}
//Draws the full pikmin after the ball
} else if (pikminThrownUncurled == true) {
if (pikminColor >=0 && pikminColor <=2 ) {
colorMode(HSB, 360, 100, 100);
fill(360 - pikminColor * 158, 100, 100);
ellipseMode(CENTER);
ellipse(pikminX, pikminY+(pikminDistance*pikminDistance/10), 20, 20);
ellipse(pikminX, pikminY+(pikminDistance*pikminDistance/10)+ 20, 20, 30);
strokeWeight(5);
noFill();
stroke(360 - pikminColor * 158, 100, 100);
//The Legs
line(pikminX-5, pikminY +(pikminDistance*pikminDistance/10)+35, pikminX-15, pikminY +(pikminDistance*pikminDistance/10) + 45);
line(pikminX+5, pikminY +(pikminDistance*pikminDistance/10)+35, pikminX+15, pikminY +(pikminDistance*pikminDistance/10) + 45);
line(pikminX-15, pikminY +(pikminDistance*pikminDistance/10)+45, pikminX-20, pikminY +(pikminDistance*pikminDistance/10) + 40);
line(pikminX+15, pikminY +(pikminDistance*pikminDistance/10)+45, pikminX+20, pikminY +(pikminDistance*pikminDistance/10) + 40);
//The Arm
line(pikminX, pikminY +(pikminDistance*pikminDistance/10)+20, pikminX - 20, pikminY +(pikminDistance*pikminDistance/10)+10);
line(pikminX, pikminY +(pikminDistance*pikminDistance/10)+20, pikminX + 20, pikminY +(pikminDistance*pikminDistance/10)+10);
//The Leaf
line(pikminX, pikminY +(pikminDistance*pikminDistance/10) -10, pikminX, pikminY +(pikminDistance*pikminDistance/10)-30);
strokeWeight(8);
stroke(93, 100, 74);
line(pikminX, pikminY +(pikminDistance*pikminDistance/10)-28, pikminX, pikminY +(pikminDistance*pikminDistance/10)-35);
strokeWeight(3);
stroke(0);
point(pikminX - 5, pikminY +(pikminDistance*pikminDistance/10)-2);
point(pikminX + 5, pikminY +(pikminDistance*pikminDistance/10)-2);
} //Doesnt draw the rock Pikmin, because he is too heavy and reaches the ground before he can uncurl (intentional).
}
}
void mousePressed() {
//if the mouse is pressed when on the sun, a pikmin is not thrown. The time of day also changes
if (mouseX >=350 && mouseX <= 400 && mouseY <=90 && mouseY >=0) {
if (daytimeChecker == 0) { //turns day
daytimeChecker = 1;
} else if (daytimeChecker ==1) { //turns night
daytimeChecker = 0;
}
} else {
if (pikminThrown == false) {
pikminThrown = true;
pikminThrownBall = true;
pikminY = mouseY-100;
pikminX = mouseX;
}
}
}
void keyPressed() {
//Uses keypresses on the Left and Right arrow key to move the pikmin color selector, and change the variable that changes the actual color.
if (pikminThrown == false) {
if (keyCode == RIGHT) {
colorSelector++;
pikminColor++;
if (colorSelector >= 4) {
colorSelector = 0;
pikminColor=0;
}
} else if (keyCode == LEFT) {
colorSelector--;
pikminColor--;
if (colorSelector <=-1) {
colorSelector =3;
pikminColor=3;
}
}
}
}