Collision

//Car
Car car1;
b1 b1;
o1 o1;
int xx=1000;
int virtualMouseY;
float y1= random(390, 600);
int c1=0;
int d=0;
int speed=1;

PImage bg;

void setup() {
  size(1000, 600);
  bg = loadImage("road.jpg");
  car1= new Car();
  b1= new b1();
  o1= new o1();
  smooth();
}

void draw() {
  println(c1);
  loop();
  noStroke();
  background(bg);
  fill(183, 67, 123);
  car1.cardisplay();
  virtualMouseY = constrain(mouseY, 335, 525);
  fill(128);
  b1.b1();
  o1.o1();
  xx-=speed;
  fill(108);
  textSize(15);
  text("CLICK TO PAUSE", 10, 55);
  fill(255, 169, 88);
  textSize(35);
  text("Score:", 10, 35);
  text(c1*100, 120, 35);
  if (xx<=-20) {
    xx=1000;
    c1+=1;
    y1=(y1*3)+1;
    if (y1>1000) {
      y1=y1%1000;
    }
  }
  if (((y1-15<=virtualMouseY)&&(y1+15>=virtualMouseY))&&(xx-27<=25)) {
    noLoop();
    d=1;
  }
  if (d==1) {
    background(128);
    textSize(42);
    fill(245, 166, 166);
    text("GAME OVER", 400, 240);
    fill(255);
    text("SCORE:", 450, 290);
    text(c1*100, 450, 340);
    fill(166, 214, 245);
    text("CLICK TO RETRY", 350, 390);
  }
  if (c1>=1) {
    speed=(c1/1)+1;
  }
}

class Car {
  void cardisplay() {
    rect(30, virtualMouseY, 100,35);
     rect(40, virtualMouseY-20, 60,20);

    fill(0);
    ellipse(40,virtualMouseY+40,15,15);
    ellipse(120,virtualMouseY+40,15,15);
  }
}
class b1 {
  void b1() {
    beginShape();
    vertex(xx-1000, 216);
    vertex(xx-951, 216);
    vertex(xx-951, 247);
    vertex(xx-931, 228);
    vertex(xx-923, 247);
    vertex(xx-923, 150);
    vertex(xx-908, 135);
    vertex(xx-893, 150);
    vertex(xx-893, 179);
    vertex(xx-882, 167);
    vertex(xx-870, 179);
    vertex(xx-870, 195);
    vertex(xx-826, 195);
    vertex(xx-826, 224); 
    vertex(xx-807, 198);
    vertex(xx-788, 224);
    vertex(xx-768, 198);
    vertex(xx-749, 224);
    vertex(xx-749, 150);
    vertex(xx-734, 135);
    vertex(xx-719, 150);
    vertex(xx-719, 217);
    vertex(xx-671, 217);
    vertex(xx-671, 248);
    vertex(xx-657, 228);
    vertex(xx-642, 248);
    vertex(xx-642, 195);
    vertex(xx-599, 195);
    vertex(xx-599, 224);
    vertex(xx-579, 200);
    vertex(xx-560, 224);
    vertex(xx-560, 179);
    vertex(xx-548, 168);
    vertex(xx-536, 179);
    vertex(xx-536, 233);
    vertex(xx-493, 233);
    vertex(xx-493, 195);
    vertex(xx-449, 195);
    vertex(xx-449, 151);
    vertex(xx-435, 136);
    vertex(xx-420, 151);
    vertex(xx-420, 179);
    vertex(xx-409, 167);
    vertex(xx-397, 179);
    vertex(xx-384, 167);
    vertex(xx-373, 179);
    vertex(xx-373, 223);
    vertex(xx-353, 198);
    vertex(xx-328, 233);
    vertex(xx-292, 233);
    vertex(xx-292, 214);
    vertex(xx-249, 214);
    vertex(xx-249, 179);
    vertex(xx-236, 168);
    vertex(xx-224, 179);
    vertex(xx-224, 225);
    vertex(xx-204, 200);
    vertex(xx-186, 225);
    vertex(xx-186, 151);
    vertex(xx-171, 137);
    vertex(xx-156, 151);
    vertex(xx-156, 197);
    vertex(xx-114, 197);
    vertex(xx-114, 181);
    vertex(xx-101, 169);
    vertex(xx-89, 181);
    vertex(xx-89, 215);
    vertex(xx-48, 215);
    vertex(xx-23, 181);
    vertex(xx, 211);
    vertex(xx, 216);
    vertex(xx, 216); //1st
    vertex(xx, 216);
    vertex(xx+49, 216);
    vertex(xx+49, 247);
    vertex(xx+63, 228);
    vertex(xx+77, 247);
    vertex(xx+77, 150);
    vertex(xx+92, 135);
    vertex(xx+107, 150);
    vertex(xx+107, 179);
    vertex(xx+118, 167);
    vertex(xx+130, 179);
    vertex(xx+130, 195);
    vertex(xx+174, 195);
    vertex(xx+174, 224); 
    vertex(xx+193, 198);
    vertex(xx+212, 224);
    vertex(xx+232, 198);
    vertex(xx+251, 224);
    vertex(xx+251, 150);
    vertex(xx+266, 135);
    vertex(xx+281, 150);
    vertex(xx+281, 217);
    vertex(xx+329, 217);
    vertex(xx+329, 248);
    vertex(xx+343, 228);
    vertex(xx+358, 248);
    vertex(xx+358, 195);
    vertex(xx+401, 195);
    vertex(xx+401, 224);
    vertex(xx+421, 200);
    vertex(xx+440, 224);
    vertex(xx+440, 179);
    vertex(xx+452, 168);
    vertex(xx+464, 179);
    vertex(xx+464, 233);
    vertex(xx+507, 233);
    vertex(xx+507, 195);
    vertex(xx+551, 195);
    vertex(xx+551, 151);
    vertex(xx+565, 136);
    vertex(xx+580, 151);
    vertex(xx+580, 179);
    vertex(xx+591, 167);
    vertex(xx+603, 179);
    vertex(xx+616, 167);
    vertex(xx+627, 179);
    vertex(xx+627, 223);
    vertex(xx+647, 198);
    vertex(xx+672, 233);
    vertex(xx+708, 233);
    vertex(xx+708, 214);
    vertex(xx+751, 214);
    vertex(xx+751, 179);
    vertex(xx+764, 168);
    vertex(xx+776, 179);
    vertex(xx+776, 225);
    vertex(xx+796, 200);
    vertex(xx+814, 225);
    vertex(xx+814, 151);
    vertex(xx+829, 137);
    vertex(xx+844, 151);
    vertex(xx+844, 197);
    vertex(xx+886, 197);
    vertex(xx+886, 181);
    vertex(xx+899, 169);
    vertex(xx+911, 181);
    vertex(xx+911, 215);
    vertex(xx+952, 215);
    vertex(xx+977, 181);
    vertex(xx+1000, 211);
    vertex(xx+1000, 216); //1st
    vertex(xx+1049, 216);
    vertex(xx+1049, 247);
    vertex(xx+1049, 315);
    vertex(xx-1000, 315);
    endShape(CLOSE);
  }
}
class o1 {
  void o1() {
    ellipse(xx+50, y1, 50, 40);
    ellipse(xx+150, y1+3, 40, 30);
    ellipse(xx+200, y1+6, 40, 30);
    ellipse(xx+300, y1+9, 40, 30);
    ellipse(xx+400, y1+12, 40, 30);
    ellipse(xx+500, y1+15, 40, 30);
  }
}
void mousePressed() {
  if (d==1) {
    redraw();
    c1=0;
    speed=1;
    d=0;
    xx=1000;
  }
  if (d==0) {
    noLoop();
    background(110);
    fill(255);
    textSize(42);
    fill(245, 166, 166);
    text("PAUSED", 450, 280);
    fill(166, 214, 245);
    text("CLICK TO RESUME", 350, 330);
    p=1;
  }
  if ((d==0)&&(p==1)) {
    redraw();
    p=0;
  }
}

I need obstacles for this game. So everytime the car hits one obstacle, it's game over. Every time it avoids it, there are points given.

Answers

This discussion has been closed.