top of page

int clicRestant=10;
int [] vitesseX;
int [] vitesseY;
int [] x;
int [] y;
int score=0;
void setup() {
  size(500, 500);
  frameRate(15);
  x=new int [10];
  y=new int [10];
  vitesseX=new int [10];
  vitesseY=new int [10];
  for (int i=0;i<10;i++) {
    x[i]=(int)random(40, 460);
    y[i]=(int)random(40, 460);
    vitesseX[i]=(int)random(6, 12);
    vitesseY[i]=(int)random(4, 10);
  }
}
void draw() {
  background(#E88336);
  button();

  balle();
  viseur();
  score();
  tir();
  for (int i=0; i<clicRestant; i++) {
    rect(450, 300+20*i, 40, 10);
  }
  rect(450, 10, 40, 20);
}

void balle() {
  for (int i=0;i<10;i++) {
    ellipse(x[i], y[i], 30, 30);
    x[i]=vitesseX[i]+x[i];
    y[i]=vitesseY[i]+y[i];


    if (x[i]>470) {
      vitesseX[i] =-vitesseX[i];
    }
    if (y[i]>470) {
      vitesseY[i]=-vitesseY[i];
    }
    if (x[i]<30) {
      vitesseX[i] =-vitesseX[i];
    }
    if (y[i]<30) {
      vitesseY[i] =-vitesseY[i];
    }
  }
}

void button() {
  if (mousePressed) {
    if (mouseX>450) {
      if (mouseX<490) {
        if (mouseY>10) {
          if (mouseY<30) {
            clicRestant =10;
          }
        }
      }
    }
    else
    {
      if (clicRestant>0) {
        clicRestant= clicRestant -1;
      }
      println(clicRestant);
    }
  }
}

void score() {
  textSize(24);
  text("Score= "+ score, 10, 30);
  text("Tirs restants= "+ clicRestant, 10, 60);
  if (score==10) {
    textSize(34);
    text("YOU WIN", 170, 250);
  }
}
void viseur() {
  noCursor();
  noFill();
  line(mouseX-20, mouseY, mouseX+20, mouseY);
  line(mouseX, mouseY-20, mouseX, mouseY+20);
  ellipse(mouseX, mouseY, 17, 17);
  fill(#4E5DDE);
}
void tir() {
  for (int i=0;i<10;i++) {
    if (mousePressed) {
      if (clicRestant>0) {
        if (mouseX<x[i]+30) {
          if (mouseY<y[i]+30) {
            if (mouseX>x[i]-30) {
              if (mouseY>y[i]-30) {
                x[i]=9999;
                y[i]=9999;
                score = score +1;
              }
            }
          }
        }
      }
    }
  }
}


 

JEU DE BALLES

  • Facebook Social Icon
  • Twitter Social Icon
  • Google+ Social Icon
bottom of page