class Bob {
float x, y;
Bob (float x, float y) {
this.x = x;
this.y = y;
}
void display() {
fill(y - x, x, y);
ellipse(x, y, 24, 24);
}
void move() {
x+=5;
}
void finish(String name1) {
textSize(69);
fill(random(1, 255), random(1, 255), random(1, 255));
text("YAY! " + name1 + " wins!", 100, 400);
textSize(30);
}
void rematch() {
fill(random(1, 255), random(1, 255), random(1, 255));
rect(350, 550, 100, 100);
fill(204, 200, 255);
textSize(20);
text("Rematch?", 356, 603);
}
}
Bob bob1;
Bob bob2;
void setup() {
size(800, 800);
bob1 = new Bob(51, 300);
bob2 = new Bob(51, 500);
}
void draw() {
if (bob1.x < 788 && bob2.x < 788){
background(0);
fill(255, 0, 0);
rect(63, 0, 24, 800);
bob1.display();
bob2.display();
}
else if (bob1.x >= 788 && bob2.x < 788) {
bob1.finish("Player 1");
bob1.rematch();
}
else if (bob2.x >= 788) {
bob2.finish("Player 2");
bob2.rematch();
}
}
void keyPressed() {
if (key == 'd') {
bob1.move();
}
if (key == 'a') {
bob1.move();
}
if (keyCode == RIGHT) {
bob2.move();
}
if (keyCode == LEFT) {
bob2.move();
}
}
void mouseClicked() {
if (mouseX >= 350 && mouseX <= 450 && mouseY >= 550 && mouseY <= 650) {
bob1.x = 51;
bob2.x = 51;
}
}