วันพุธที่ 12 พฤศจิกายน พ.ศ. 2557

Class House And Move Up

House h;
void setup() {
  size (500, 500);
  h = new House(100, 150, 300, 250);
  h.setDoor(new Door(200, 200, 100, 200));
  h.setWindowLeft(new Window(125, 180, 50, 50));
  h.setWindowRight(new Window (325, 180, 50, 50));
}

void draw () {
  smooth();
  background(0);
  h.display();
  h.move_up();
}
////////////////////////////////////////////
class Door { //class of Door
  int x; //Attribute of class Door //x mean x position
  int y; //y mean y position
  int w; //w mean width
  int hi; //hi mean height

  Door (int x, int y, int w, int hi) { //Constructor of class Door
    this.x = x;
    this.y = y;
    this.w = w;
    this.hi = hi;
  }
  void display1() { //method of class Door
    rect(this.x, this.y, this.w, this.hi);
  }
  void move_up1 () {
    this.y = this.y -  1;
    if (this.y<=50) {
      this.y = height+50;
    }
  }
}
//////////////////////////////////

class Window { //class of Window
  int x; //Attribute of calss Window
  int y;
  int w;
  int hi;

  Window (int x, int y, int w, int hi) {
    this.x = x; //constructor of Class Window
    this.y = y;
    this.w =w;
    this.hi = hi;
  }

  void display2() { //method of class Window
    rect (this.x, this.y, this.w, this.hi);
  }
  void move_up2 () {
    this.y = this.y - 1;
    if (this.y<=35) {
      this.y = height+35;
    }
  }
}
////////////////////////////////////

class House { //class of House
  int x; //Attribute of class House
  int y;
  int w;
  int hi;
  Door door; //defined obj. of class Door in Class House
  Window left_window;
  Window right_window;

  House (int x, int y, int w, int hi) { //constructer of class House
    this.x =x;
    this.y =y;
    this.w =w;
    this.hi =hi;
  }
  void setDoor (Door d) { //method of Class House that have parameter from Class Door
    this.door = d;
  }
  void setWindowLeft (Window a) { //method of claa House that have parameter from Class Window
    this.left_window = a;
  }
  void setWindowRight (Window b) {
    this.right_window = b;
  }
  void display() {
    rect(this.x, this.y, this.w, this.hi);
    triangle(this.x, this.y, this.x+(this.w/2), this.y-(this.hi/2), (this.x)+(this.w), this.y);
    this.door.display1(); //defined obj. for call method display in Class Door
    this.left_window.display2();
    this.right_window.display2();
  }
  void move_up () {
    this.y = this.y - 1;
    this.door.move_up1();
    this.left_window.move_up2();
    this.right_window.move_up2();
    if (this.y<=0) {
      this.y= height;
    }
  }
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น