int count = 5;
Dname[] Dname = new Dname[count];



void setup() {
  size(900,800);
  
  for(int i = 0; i < count; i++) {
    Dname[i] = new Dname(100 + 150 * i, height-100, 
      color(random(255),random(255),random(255)));
  }
  
}

void draw() {
  background(150,0,0);
  scene();
  Dname();
}
void scene() {
  fill(200,200,0);
  rect(0,0,width,600);
}

void Dname() {
  for(int i = 0; i < count; i++) {
    Dname[i].display();
  }
  
  line(700,width,700,0);   //// start and finish lines
  stroke(255);
  strokeWeight(2);
  
  line(100,width,100,0);
  stroke(0);
  
}

void keyPressed() {
 //// check which key is pressed.  if space then move y random for all
 if (key == ' ')
 {
  for(int i = 0; i < count; i++) {
    // move all
    Dname[i].move();
  }
 }
 else if (key == 'R') 
  // restart all at bottom
    for(int i = 0; i < count; i++) {
    // move to b
    Dname[i].ypos=  height-100;
  }

}


class Dname {
  float xpos = height/1 ;
  float ypos = width/2;
  color c1;
  Dname(float tempYpos, float tempXpos, int tempC) {
    ypos = tempYpos;
    xpos = tempXpos;
    c1 = tempC;
  }
  void display() {                 // Move the object's (x,y) coordinates.
    fill(c1);
    rect(xpos -100, ypos, 30,50);
  }

  void move() { 
        xpos -= random(20); ///how fast they move
        
  }
}





