colliding bouncing balls with mouse object

edited December 2017 in Questions about Code

Can someone help me with making the balls collide with my mouse image and after that making the time timer stop

// Balls
int Balls = 5;
int BallA[] = new int[Balls];
int BallB[] = new int[Balls];
float MoveA[] = new float[Balls];
float MoveB[] = new float[Balls];
//timer
int t;

//image
PImage img;
void setup() {
  size(500, 500);

// Balls
  for(int x = 0; x < Balls; x++){
    BallA[x] = int(random(50, width));
    MoveA[x] = int(random(5, 8));
    BallB[x] = int(random(50, width));
    MoveB[x] = int(random(5, 8));

//image
   img = loadImage("download.jpg");
   img.resize(img.width/5, img.height/5);
}}

void draw() {
// changing the background when moving your mouse. it is divided in 3 parts
  if (mouseX < width/3) 
  { background (230,220,0);
} else if(mouseX < 2*width/3){
  background (0,0,0);
} else 
  background (255,0,0);
// creating an object to move around with your mouse  
  fill(0);
  rect(mouseX, mouseY, 25, 25);
  noCursor();

//timer
  fill(255);
  t=millis()/1000;
  textSize(20);
  text (t,270,20);
  text("Score:", 210, 20);

//image
image(img,mouseX,mouseY);

//balls
  for(int x = 0; x<Balls; x++){
  ellipse(BallA[x], BallB[x], 20, 20);
  if(BallA[x] > width || BallA[x] < 10){
      MoveA[x] = MoveA[x] * (-1);}
  if(BallB[x] > height || BallB[x] < 10){
      MoveB[x] = MoveB[x] * (-1);}
  BallA[x] += MoveA[x];
  BallB[x] += MoveB[x]; 
}
}
Tagged:

Answers

Sign In or Register to comment.