xxxxxxxxxx
int x;//x component of ball
int y;//same
int z;//radius
int s;//vertical speed
int xs;
int xs1=0;
int x1=150;//blank
int y1=335;
int acc1 = 2;
boolean dis1 = false;
int acc2 = 2;
boolean dis2 = false;
int acc3 = 2;
boolean dis3 = false;
boolean lose = false;
boolean die = false;
int score = 0;
void setup() {
fill(0);
size (400, 400);
x = width /2;
y = 200;
z = 30;
if(!lose){
s = 4;}
else{s = 0;}
}
void draw() {
background(0);
PFont font = loadFont ("Arial-Black-48.vlw");
fill(255,0,0);
textFont(font,15);
text("Press 'a' or 'd' to move the board",64,30);
stroke(255, 255, 0);
if(y >= 350){
die = true;
}
line(50, 0, 50, 350);
line(350, 0, 350, 350);
line(50, 0, 350, 0);
line(50, 350, 350, 350);
if(!dis1){
if(acc1==2){
fill(70);}
else{fill(255,0,0);}
rect(50,100,100,30);
}
if(!dis2){
if(acc2==2){
fill(70);}
else{fill(255,0,0);}
rect(150,100,100,30);
}
if(!dis3){
if(acc3==2){
fill(70);}
else{fill(255,0,0);}
rect(250,100,100,30);
}
if ((!dis1)&&((x>50)&&(x<150)&&(y<130)&&(y>70)))
{
score += 1;
s = s * -1;
acc1 -= 1;
if(acc1 == 0)
{dis1 = true;}
if((dis1==true)&&(dis2==true)&&(dis3==true)){
lose = true;
}
}
if ((!dis2)&&((x>150)&&(x<250)&&(y<130)&&(y>70)))
{
score += 1;
s = s * -1;
acc2 -= 1;
if(acc2 == 0)
{dis2 = true;}
if((dis1==true)&&(dis2==true)&&(dis3==true)){
lose = true;
}
}
if ((!dis3)&&((x>250)&&(x<350)&&(y<130)&&(y>70)))
{
score += 1;
s = s * -1;
acc3 -= 1;
if(acc3 == 0)
{dis3 = true;}
if((dis1==true)&&(dis2==true)&&(dis3==true)){
lose = true;
}
}
fill(255);
if((x<70)||(x>330)){
xs1 = xs1 * -1;
}
if((x>x1)&&(x<x1+100)&&(y>325)){
if (x>x1+70){
xs1 = 4;
}
if (x>x1+55){
xs1 = 2;
}
else if (x<x1+55)
{
xs1 = -2;
}
else if (x<x1+30)
{
xs1 = -4;
}
if ((x<x1+55)&&(x>x1+45)){
xs1 = 0;
}
}
x= x+xs1;
y = y + s;
if(lose||die)
{xs1 = 0;
s = 0;}
ellipse(x, y, z, z);
if ((y<15)||((x>x1)&&(x<x1+100)&&(y>325)))
{
s = s * -1;
}
rect(x1, y1, 100, 10);
x1 += xs;
if(lose){
font = loadFont ("Arial-Black-48.vlw");
fill(255,0,0);
textFont(font,40);
text("You win!",100,150);
textFont(font,20);
text("Your score is "+ score,120,230);
}
if(die){
font = loadFont ("Arial-Black-48.vlw");
fill(255,0,0);
textFont(font,40);
text("You lose!",100,150);
textFont(font,20);
text("Your score is "+ score,120,230);
}
if(lose || die){
fill(100);
rect(150,270,100,45);
fill(255,0,0);
textFont(font,30);
text("retry",160,300);
}
}
void keyPressed() {
if(!die&&!lose){
if ((key == 'a')||(key == 'A'))
{
if(x1>=55)
{ xs = -3;}
else{xs=0;}
}
if ((key == 'd')||(key == 'D'))
{
if(x1<=245)
{ xs = 3;}
else{xs=0;}
}
}
}
void keyReleased() {
if ((key == 'a')||(key == 'A'))
{
xs = 0;
}
if ((key == 'd')||(key == 'D'))
{
xs = 0;
}
}
void mousePressed(){
if((mouseX>150)&&(mouseX<250)&&(mouseY>270)&&(mouseY<315)&&((lose)||(die))){ //(150,270,100,45)
x = y = 200;
s = 4;//vertical speed
xs = 0;
xs1=0;
x1=150;//blank
y1=335;
acc1 = 2;
dis1 = false;
acc2 = 2;
dis2 = false;
acc3 = 2;
dis3 = false;
lose = false;
die = false;
score = 0;
}
}