Processing Assignment 3
float [] xLine;
float [] yLine;
float [] speed;
int numLine = 60;
int score = 0;
float color1 = 0;
float color2 = 0;
float color3 = 0;
int rectHeight = 10;
int rectWidth = 20;
int health = 1000;
int backMin;
int backMax;
void setup() {
noCursor();
size(1500,1000);
xLine = new float [numLine];
yLine = new float [numLine];
speed = new float[numLine];
mouseX = width;
mouseY = height/2;
backMin = numLine * 3;
backMax = numLine * 6;
}
void draw() {
background(color1,color2,color3);
stroke(255);
strokeWeight(1);
rectMode(CENTER);
fill(255);
text(score,10,20);
text(health,100,20);
text("Health",100,40);
text("Score" ,10,40);
// text(backMin,10,height-20);
//text(backMax,100,height-20);
//text(color1,width-50,height-50);
fill(0,0,255);
health = constrain(health,0,1000);
//main player
rect(mouseX,mouseY,rectWidth,rectHeight);
for(int x = 0;x < numLine; x++) {
xLine[x] = xLine[x]+speed[x];
line(xLine[x],yLine[x],xLine[x]+10,yLine[x]);
//Hitbox and health
if(xLine[x] >= mouseX-rectWidth && xLine[x] <= mouseX+rectWidth && yLine[x] >= mouseY-rectHeight && yLine[x] <= mouseY+rectHeight){
health -= 1000/numLine;
}
if(xLine[x] > width) {
xLine[x] = -10;
yLine[x] = random(0,1000);
score++;
speed[x] = random(5,25);
}
if(speed[x] == 0){
speed[x] = random(5,25);
}
if(score >= backMin && score <= backMax){
color1 = constrain(color1,0,60);
color3 = constrain(color3,0,60);
color1 += 0.001;
color3 += 0.001;
}
else if(score >= backMax){
color1 -= 0.001;
color3 -= 0.001;
}
if(color1 <= 0 && score >= numLine * 4){
backMin += numLine * 3;
backMax += numLine * 8;
}
if(health <= 0){
background(255);
fill(0);
text("Game over",width/2,height/2);
text("Press the R key to play again",width/2-40,height/2+20);
fill(255);
}
}
}
void keyPressed() {
if(key == 'r' && health <= 0){
health = 1000;
score = 0;
}
}
float [] yLine;
float [] speed;
int numLine = 60;
int score = 0;
float color1 = 0;
float color2 = 0;
float color3 = 0;
int rectHeight = 10;
int rectWidth = 20;
int health = 1000;
int backMin;
int backMax;
void setup() {
noCursor();
size(1500,1000);
xLine = new float [numLine];
yLine = new float [numLine];
speed = new float[numLine];
mouseX = width;
mouseY = height/2;
backMin = numLine * 3;
backMax = numLine * 6;
}
void draw() {
background(color1,color2,color3);
stroke(255);
strokeWeight(1);
rectMode(CENTER);
fill(255);
text(score,10,20);
text(health,100,20);
text("Health",100,40);
text("Score" ,10,40);
// text(backMin,10,height-20);
//text(backMax,100,height-20);
//text(color1,width-50,height-50);
fill(0,0,255);
health = constrain(health,0,1000);
//main player
rect(mouseX,mouseY,rectWidth,rectHeight);
for(int x = 0;x < numLine; x++) {
xLine[x] = xLine[x]+speed[x];
line(xLine[x],yLine[x],xLine[x]+10,yLine[x]);
//Hitbox and health
if(xLine[x] >= mouseX-rectWidth && xLine[x] <= mouseX+rectWidth && yLine[x] >= mouseY-rectHeight && yLine[x] <= mouseY+rectHeight){
health -= 1000/numLine;
}
if(xLine[x] > width) {
xLine[x] = -10;
yLine[x] = random(0,1000);
score++;
speed[x] = random(5,25);
}
if(speed[x] == 0){
speed[x] = random(5,25);
}
if(score >= backMin && score <= backMax){
color1 = constrain(color1,0,60);
color3 = constrain(color3,0,60);
color1 += 0.001;
color3 += 0.001;
}
else if(score >= backMax){
color1 -= 0.001;
color3 -= 0.001;
}
if(color1 <= 0 && score >= numLine * 4){
backMin += numLine * 3;
backMax += numLine * 8;
}
if(health <= 0){
background(255);
fill(0);
text("Game over",width/2,height/2);
text("Press the R key to play again",width/2-40,height/2+20);
fill(255);
}
}
}
void keyPressed() {
if(key == 'r' && health <= 0){
health = 1000;
score = 0;
}
}