Wednesday, 5 November 2014

Lab 5 cont House Window Door

class House{
 int house_x;
 int house_y;
 int house_w;
 int house_h;
 Door door;
 Window window_left;
 Window window_right;
 int Door_Set;
 int Window_Set;
  House(int house_x, int house_y, int house_w, int house_h){
    this.house_x = house_x;
    this.house_y = house_y;
    this.house_w = house_w;
    this.house_h = house_h;
    this.Window_Set = 0;
    this.Door_Set = 0;
  }
void drawWindow(Window w_l, Window w_r){
  this.window_left = w_l;
  this.window_right = w_r;
  this.Window_Set = 1;
}
void drawDoor(Door d){
  this.door = d;
  this.Door_Set = 1;
}
void display(){
 rect(this.house_x, this.house_y, this.house_w, this.house_h);
 triangle(this.house_x, this.house_y, this.house_x+this.house_w, this.house_y, this.house_x+(this.house_w/2),this.house_y-(this.house_h/2));
 if( this.Door_Set == 1){
 this.door.display();
 }
 if( this.Window_Set == 1){
 this.window_left.display();
 this.window_right.display();
 }
}
void move_left(){
 this.house_x += 1;
  if(this.house_x > width+150){this.house_x = -150;}
 if( this.Door_Set == 1){
 this.door.move_left();
 }
 if( this.Window_Set == 1){
 this.window_left.move_left();
 this.window_right.move_left();
}
}
}

class Door{
 int door_x;
 int door_y;
 int door_w;
 int door_h;

  Door(int door_x, int door_y, int door_w, int door_h){
    this.door_x = door_x;
    this.door_y = door_y;
    this.door_w = door_w;
    this.door_h = door_h;
  }
  Door(){
    this.door_x = 0;
    this.door_y = 0;
    this.door_w = 0;
    this.door_h = 0;
  }
void display(){
 rect(this.door_x, this.door_y, this.door_w, this.door_h);
}
 void move_left(){
   this.door_x +=1;
   if(this.door_x > width+150){ this.door_x = -150;}
 }
}
class Window{
  int window_x;
  int window_y;
  int window_w;
  int window_h;
 Window(int window_x, int window_y, int window_w, int window_h){
   this.window_x = window_x;
   this.window_y = window_y;
   this.window_w = window_w;
   this.window_h = window_h;
 }
 Window(){
   this.window_x = 0;
   this.window_y = 0;
   this.window_w = 0;
   this.window_h = 0;
 }
void display(){
   rect(this.window_x, this.window_y, this.window_w, this.window_h);
 }
 void move_left(){
   this.window_x +=1;
   if(this.window_x > width+150){ this.window_x = -150;}
 }
}
House h;
Door d;
Window window_left;
Window window_right;
Window no_window = new Window(0,0,0,0);
House k;
void setup(){
  size(300, 300);
  h = new House(100,100,100,50);
  k = new House(100,200,100,50);
  d = new Door(130,125,40,25);
  window_left = new Window(110, 110, 10, 10);
  window_right = new Window(180, 110, 10, 10);
  h.drawDoor(d);
  h.drawWindow(window_left, window_right);
  //h.drawWindow(window_left, no_window);
}
void draw(){
 background(255);
 h.display();
 k.display();
 k.move_left();
 h.move_left();
}

No comments:

Post a Comment