//// Q2 template (3)

Button one, two, three, four;
Witch ruby = new Witch();

float horizon=200;

void setup() { 
  size( 800, 600 );
  horizon= height/3;
  Monster max=    new Monster();
  Witch ruby=    new Witch();
  Animal Sam=  new Animal();
  Tree t1, t2, t3, t4, t5;
  t1=   new Tree();
  t2=   new Tree();
  t3=   new Tree();
  t4=   new Tree();
  t5=   new Tree();
  // +++  FIX THE ABOVE CODE, AND REMOVE THE FOLLOWING CODE:
  one = new Button();
  two = new Button();
  three = new Button();
  four = new Button();
  one.y= 20;
  two.y=    one.y+40; 
  three.y=  two.y+40; 
  four.y=   three.y+40; 
  one.name= "zap";
  two.name="back";
  three.name="Reset";
  four.name="Trees";
}

void draw() {
  scene();
  action();
  trees();
  messages();
}

void scene() {
  background( 120, 150, 200 );  // nite
  fill( 100, 200, 100 );
  rect( 0, horizon, width, height-horizon );    // grass;
  // Moon ???

  // Buttons
  one.show();
  two.show();
  three.show();
  four.show();
}
void trees() {
}

void action() {
  // Monster chases treat.
  // +++  

  // Witch rides broom (right to left).
  ruby.move();
  ruby.show();

  // Rabbit scoots around
  // +++
}

void messages() {
}

//// EVENTS ////
void keyPressed() {
  if (key == 'e') { 
    exit();
  }
  if (key == 'r') { 
    //    reset();
  }
  if (key == 'b') { 
    ruby.reverse();
  }
  if (key == 'z') { 
    //    zap();
  }
  if (key == 't') { 
    //    randomTrees();
  }
}
void mousePressed() {
  if (two.hit() ) {
    ruby.reverse();
  }
}

class Button 
{ 
  // PROPERTIES //
  float x=40, y=40, w=80, h=30;
  String name="Click here";
  color c=color( 255, 200, 200 );  

  // CONSTRUCTORS //
  // +++

  // METHODS //
  void show() {
    fill( c );
    rect( x, y, w, h );
    fill(0);
    textSize(16);
    text( name, x+10, y+20 );
  }
  boolean hit() {
    return( 
      mouseX > x
      && mouseX < x+w
      && mouseY > y
      && mouseY < y+h );
  }
}


class Witch
{
  float x=600, y=100, dx=-1;
  float w=40, h=80, hh=30;           // body w&h, head height
  void show() {
    if (x<=0) return;
    float broom=y+h;                   // broom
    fill(255, 100, 0);
    ellipse( x, y, 25, hh );             // Orange face.
    fill(0);
    rect( x-w/2, y+hh/2, w, h );
    triangle( x-10, y-hh/2, x+10, y-hh/2, x, y-45 );  // hat
    rect( x-20, y-15, 40, 3 );                       // brim
    fill(100, 0, 0);
    rect( x-60, broom, 120, 3 );         // Brown broomstick
    triangle( x+50, broom, x+60, broom-12, x+60, broom+12 );
  }
  void move() {
    x += dx;
  }
  void reverse() {
    background(0);
    dx = -dx;
    ;
  }
}// class Witch //

class Monster
{
  void move() {
  }
  void show() {
  }
}// class Monster //

class Animal
{
  void move() {
  }
  void show() {
  }
}// class Animal //

class Tree
{
  float x, y, w, h;

  Tree() {
    x=  random( 50, width);
    y=  random(horizon, height);
  }
  void show() {
  }
}//class//

