/*
Game name: Catch the block
Created by : Edward(Yuhao) Lu
Date : Sept 30, 2018
How to play:
Click the middle of the block(the color will be changed if
the mouse is in the activable area) when the shrunken frame
is closed to the red line in the white area.
*/
int lengthB=50;
int lengthR=60;
int lengthG=70;
int lengthO=150;
int score=0;
float speed=1;
float centerX=200;
float centerY=200;
void setup() {
size(400, 400);
frameRate(60);
rectMode(CENTER);
ellipseMode(CENTER);
}
void draw () {
background(50);
drawBackground();
drawBlock();
updateBlock();
updateSpeed();
}
//Block
void drawBlock() {
noStroke();
fill(204, 204, 204);
rect(centerX, centerY, lengthG, lengthG);
noFill();
stroke(118, 0, 35);
strokeWeight(2);
rect(centerX, centerY, lengthR, lengthR);
noStroke();
fill(37, 37, 37);
rect(centerX, centerY, lengthB, lengthB);
noFill();
stroke(200, 175, 139);
rect(centerX, centerY, lengthO, lengthO);
}
// updateBlock
void updateBlock() {
if (lengthO<26) {
lengthO=140;
centerX=random(75, 325);
centerY=random(75, 325);
score=0;
speed=1;
} else if (lengthO>25);
{
lengthO-=speed;
}
if (mouseX<centerX+lengthB/2&&mouseX>centerX-lengthB/2
&&mouseY<centerY+lengthB/2&&mouseY>centerY-lengthB/2) {
noStroke();
fill(182, 171, 207);
rect(centerX, centerY, lengthB, lengthB);
noFill();
stroke(254, 101, 37);
rect(centerX, centerY, lengthO, lengthO);
}
}
//backGround
void drawBackground() {
if (score>=20) {
stroke(255, 80);
fill(184, 0, 73, 50+10*sin(PI/30*frameCount));
ellipse(200, 200, 200+50*sin(PI/30*frameCount-PI), 200+50*sin(PI/30*frameCount-PI));
ellipse(200, 200, 280+20*sin(PI/30*frameCount-PI), 280+20*sin(PI/30*frameCount-PI));
fill(79, 77, 177, 60); //translucent white
triangle(200, 200, 200/6.5+1000*cos(PI/100*frameCount*-1), 400/13-2*sin(PI/30*frameCount*-1)+1000*sin(PI/100*frameCount*-1), 580/6.5+1000*cos(PI/100*frameCount*-1+PI/6), 400/13-2*sin(PI/30*frameCount*-1)+1000*sin(PI/100*frameCount*-1+PI/6));
triangle(200, 200, 200/6.5+1000*cos(PI/100*frameCount*-1+2*PI/3), 400/13-2*sin(PI/30*frameCount*-1)+1000*sin(PI/100*frameCount*-1+2*PI/3), 580/6.5+1000*cos(PI/100*frameCount*-1+2*PI/3+PI/6), 400/13-2*sin(PI/30*frameCount*-1)+1000*sin(PI/100*frameCount*-1+2*PI/3+PI/6));
triangle(200, 200, 200/6.5+1000*cos(PI/100*frameCount*-1+4*PI/3), 400/13-2*sin(PI/30*frameCount*-1)+1000*sin(PI/100*frameCount*-1+4*PI/3), 580/6.5+1000*cos(PI/100*frameCount*-1+4*PI/3+PI/6), 400/13-2*sin(PI/30*frameCount*-1)+1000*sin(PI/100*frameCount*-1+4*PI/3+PI/6));
fill(99, 214, 180, 40+20*sin(PI/30*frameCount));
rect(200, 200, width, height);
} else if (score>=12) {
stroke(255, 80);
fill(184, 0, 73, 25+8*sin(PI/30*frameCount));
ellipse(200, 200, 200+50*sin(PI/30*frameCount-PI), 200+50*sin(PI/30*frameCount-PI));
ellipse(200, 200, 280+20*sin(PI/30*frameCount-PI), 280+20*sin(PI/30*frameCount-PI));
fill(79, 77, 177, 35); //translucent white
triangle(200, 200, 200/6.5+1000*cos(PI/100*frameCount*-1), 400/13-2*sin(PI/30*frameCount*-1)+1000*sin(PI/100*frameCount*-1), 580/6.5+1000*cos(PI/100*frameCount*-1+PI/6), 400/13-2*sin(PI/30*frameCount*-1)+1000*sin(PI/100*frameCount*-1+PI/6));
triangle(200, 200, 200/6.5+1000*cos(PI/100*frameCount*-1+2*PI/3), 400/13-2*sin(PI/30*frameCount*-1)+1000*sin(PI/100*frameCount*-1+2*PI/3), 580/6.5+1000*cos(PI/100*frameCount*-1+2*PI/3+PI/6), 400/13-2*sin(PI/30*frameCount*-1)+1000*sin(PI/100*frameCount*-1+2*PI/3+PI/6));
triangle(200, 200, 200/6.5+1000*cos(PI/100*frameCount*-1+4*PI/3), 400/13-2*sin(PI/30*frameCount*-1)+1000*sin(PI/100*frameCount*-1+4*PI/3), 580/6.5+1000*cos(PI/100*frameCount*-1+4*PI/3+PI/6), 400/13-2*sin(PI/30*frameCount*-1)+1000*sin(PI/100*frameCount*-1+4*PI/3+PI/6));
} else if (score>=6) {
stroke(255, 80);
fill(184, 0, 73, 18+6*sin(PI/30*frameCount));
ellipse(200, 200, 200+50*sin(PI/30*frameCount-PI), 200+50*sin(PI/30*frameCount-PI));
ellipse(200, 200, 280+20*sin(PI/30*frameCount-PI), 280+20*sin(PI/30*frameCount-PI));
}
}
//Speed
void updateSpeed() {
if (score>=6&&score<10) {
speed+=.005;
speed= constrain (speed, 0, 1.1);
} else if (score>=10&&score<15) {
speed+=.005;
speed= constrain (speed, 0, 1.35);
} else if (score>=20&&score<25) {
speed+=.005;
speed= constrain (speed, 0, 1.65);
} else if (score>=25) {
speed+=.05;
speed= constrain (speed, 0, 2);
}
}
// mousePressed
void mousePressed() {
while (mouseX<centerX+lengthB/2&&mouseX>centerX-lengthB/2
&&mouseY<centerY+lengthB/2&&mouseY>centerY-lengthB/2
&&lengthO<lengthG&&lengthO>lengthB) {
lengthO=140;
centerX=random(75, 325);
centerY=random(75, 325);
noStroke();
fill(150);
rect(centerX, centerY, lengthG, lengthG);
noFill();
stroke(255, 0, 0);
strokeWeight(2);
rect(centerX, centerY, lengthR, lengthR);
noStroke();
fill(255);
rect(centerX, centerY, lengthB, lengthB);
noFill();
stroke(255);
rect(centerX, centerY, lengthO, lengthO);
lengthO-=speed;
score+=1;
//scoreSystem
if (score>45) {
println(score+" times,THE MASTER OF CATCHER!");
} else if (score>30) {
println(score +" times,YOU ARE INCREDIBLE!");
} else if (score>20) {
println(score+" times,YOU ARE AWESOME!");
} else if (score>8) {
println(score+" times,GOOD JOB!");
} else if (score>0&&score<=8) {
println(score+" times,Try harder!");
}
}
}