Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
//Nick Battista
//Mr. Hessler
//Burger Thyme
//Apply the correct condiments on the correct burgers. 
//Hover over a condiment to select it. 
//Than hover over a burger to dress it and the top bun will be put on automatically.

//Initiallize all sub classes
Burger burgerAssembly = new Burger();
AssemblyLine conveytorBelt = new AssemblyLine();
Condiments condiments = new Condiments();

//create variables for the burgers locations
PVector b1location;
PVector b2location;
PVector b3location;
PVector b4location;

//create variables for the speeds of the burgers
PVector b1velocity;
PVector b2velocity;
PVector b3velocity;
PVector b4velocity;

//set a random amount of time to delay the next burger after the first one leaves the screen.
float burgerSpawnRandomizer;
boolean Burger1IsReady = false;
boolean Burger2IsReady = false;
boolean Burger3IsReady = false;
boolean Burger4IsReady = false;

//set an array for the heights of the conveytor belts to make setting the burgers location easier
int[] conveytorHeights = { 60, 130, 200, 270};


//set the size of the window
void setup() {
  size (400, 400);
  b1location=new PVector();
  b2location=new PVector();
  b3location=new PVector();
  b4location=new PVector();

  b1velocity=new PVector();
  b2velocity=new PVector();
  b3velocity=new PVector();
  b4velocity=new PVector();

  //set the velocities of the individual burgers at a random value, but not too fast
  b1velocity.x = random(0.7, 2);
  b2velocity.x = random(0.7, 2);
  b3velocity.x = random(0.7, 2);
  b4velocity.x = random(0.7, 2);
}

//initialize every function in the other classes
void draw() {
  background(255);
  stroke(0);
  conveytorBelt.conveytor();
  burgerAssembly.makeBurger1();
  burgerAssembly.makeBurger2();
  burgerAssembly.makeBurger3();
  burgerAssembly.makeBurger4();
  conveytorBelt.conveytorSpeed1();
  conveytorBelt.conveytorSpeed2();
  conveytorBelt.conveytorSpeed3();
  conveytorBelt.conveytorSpeed4();
  condiments.ketchup();
  condiments.mustard();
  condiments.relish();
  condiments.whichCondiment();
  condiments.isBurgerReady();
  condiments.matchTheCondiment();
}
class AssemblyLine {

  AssemblyLine() {
  }

//use loops to create the design of the conveytors (pattern)
  void conveytor() {
    rectMode(CORNERS);
    for (int i = 20; i < 400; i += 40) {
      for (int j = 60; j < 300; j += 70) {
        fill(0);
        rectMode(CORNERS);
        rect(i - 20, j - 20, i + 15, j + 20);
        fill(100);
        rect(i + 20, j - 20, i + 15, j + 20);
      }
    }
  }

//Set the speed of the burger as its moving across the conveytor
  void conveytorSpeed1() {
    b1location.add(b1velocity);
  }
  void conveytorSpeed2() {
    b2location.add(b2velocity);
  }
  void conveytorSpeed3() {
    b3location.add(b3velocity);
  }
  void conveytorSpeed4() {
    b4location.add(b4velocity);
  }
}
class Burger {

  Burger() {
    //set the original location of the individual burgers
    b1location = new PVector(-100, 200);
    b2location = new PVector(-100, 200);
    b3location = new PVector(-100, 200);
    b4location = new PVector(-100, 200);
    //set the starting velocity
    b1velocity = new PVector(0, 0);
    b2velocity = new PVector(0, 0);
    b3velocity = new PVector(0, 0);
    b4velocity = new PVector(0, 0);
  }

//print the ellipses made to look like the top-down perspective of the burgers
//while also checking if they went to far, 
//and if the player succesfully applied the right condiment
  void makeBurger1() {
    burgerSpawnRandomizer = random(500, 15000);
    if (b1location.x > 500) {
      b1location.x = -100;
      Burger1IsReady = false;
    }
    fill(255, 207, 17);
    ellipse(b1location.x, conveytorHeights[0], 35, 35);
    fill(60, 50, 40);
    ellipse(b1location.x, conveytorHeights[0], 30, 30);
    if (Burger1IsReady) {
      fill(255, 207, 17);
      ellipse(b1location.x, conveytorHeights[0], 25, 25);
    }
  }

  void makeBurger2() {
    burgerSpawnRandomizer = random(500, 5000);
    if (b2location.x > 500) {
      b2location.x = -100;
      Burger2IsReady = false;
    }
    fill(255, 207, 17);
    ellipse(b2location.x, conveytorHeights[1], 35, 35);
    fill(60, 50, 40);
    ellipse(b2location.x, conveytorHeights[1], 30, 30);
    if (Burger2IsReady) {
      fill(255, 207, 17);
      ellipse(b2location.x, conveytorHeights[1], 25, 25);
    }
  }

  void makeBurger3() {
    burgerSpawnRandomizer = random(500, 15000);
    if (b3location.x > 500) {
      b3location.x = -100;
      Burger3IsReady = false;
    }
    fill(255, 207, 17);
    ellipse(b3location.x, conveytorHeights[2], 35, 35);
    fill(60, 50, 40);
    ellipse(b3location.x, conveytorHeights[2], 30, 30);
    if (Burger3IsReady) {
      fill(255, 207, 17);
      ellipse(b3location.x, conveytorHeights[2], 25, 25);
    }
  }

  void makeBurger4() {
    burgerSpawnRandomizer = random(500, 15000);
    if (b4location.x > 500) {
      b4location.x = -100;
      Burger4IsReady = false;
    }
    fill(255, 207, 17);
    ellipse(b4location.x, conveytorHeights[3], 35, 35);
    fill(60, 50, 40);
    ellipse(b4location.x, conveytorHeights[3], 30, 30);
    if (Burger4IsReady) {
      fill(255, 207, 17);
      ellipse(b4location.x, conveytorHeights[3], 25, 25);
    }
  }
}
class Condiments {
//keep track of the current condiment selected by the player
  int currentCondiment;
//keep track of the needed condiments by each conveytor belt
  int neededCondiment1;
  int neededCondiment2;
  int neededCondiment3;
  int neededCondiment4;
//randomize the condiments each conveytor needs everytime the program is run
  int neededCondimentRandomizer1 = (int) random(1, 4); 
  int neededCondimentRandomizer2 = (int) random(1, 4);
  int neededCondimentRandomizer3 = (int) random(1, 4);
  int neededCondimentRandomizer4 = (int) random(1, 4);

  Condiments() {
  }
//check if ketchup was applied
  void ketchup() {
    fill(240, 20, 20);
    rectMode(CENTER);
    rect(350, 350, 15, 30);
    rect(350, 367, 10, 4);
    triangle(350, 376, 353, 369, 347, 369);
    if (currentCondiment == 1) {
      fill(240, 20, 20);
      rectMode(CENTER);
      rect(mouseX, mouseY, 15, 30);
      rect(mouseX, mouseY+17, 10, 4);
      triangle(mouseX, mouseY+26, mouseX+3, mouseY+19, mouseX-3, mouseY +19);
    }
  }

// check if mustard was applied
  void mustard() {
    fill(255, 245, 50);
    rectMode(CENTER);
    rect(320, 350, 15, 30);
    rect(320, 367, 10, 4);
    triangle(320, 376, 323, 369, 317, 369);
    if (currentCondiment == 2) {
      fill(255, 245, 50);
      rectMode(CENTER);
      rect(mouseX, mouseY, 15, 30);
      rect(mouseX, mouseY+17, 10, 4);
      triangle(mouseX, mouseY+26, mouseX+3, mouseY+19, mouseX-3, mouseY +19);
    }
  }

//check if relish was applied
  void relish() {
    fill(50, 170, 50);
    rectMode(CENTER);
    rect(290, 350, 15, 30);
    rect(290, 367, 10, 4);
    triangle(290, 376, 293, 369, 287, 369);
    if (currentCondiment == 3) {
      fill(50, 170, 50);
      rectMode(CENTER);
      rect(mouseX, mouseY, 15, 30);
      rect(mouseX, mouseY+17, 10, 4);
      triangle(mouseX, mouseY+26, mouseX+3, mouseY+19, mouseX-3, mouseY +19);
    }
  }

//set which condiment is currently selected
  void whichCondiment() {
    if (mouseX > 343 && mouseX < 357 && mouseY > 335 && mouseY < 365) {
      currentCondiment = 1;
    }
    if (mouseX > 313 && mouseX < 327 && mouseY > 335 && mouseY < 365) {
      currentCondiment = 2;
    }
    if (mouseX > 283 && mouseX < 297 && mouseY > 335 && mouseY < 365) {
      currentCondiment = 3;
    }
  }

// check if the player added the right condiment, and than sets the burger to ready
// this adds a top bun
  void isBurgerReady() {
    if (mouseX > b1location.x-30 && mouseX < b1location.x+30 && mouseY > 30 && mouseY < 90 && currentCondiment == neededCondiment1) {
      Burger1IsReady = true;
    }
    if (mouseX > b2location.x-30 && mouseX < b2location.x+30 && mouseY > 100 && mouseY < 160 && currentCondiment == neededCondiment2) {
      Burger2IsReady = true;
    }
    if (mouseX > b3location.x-30 && mouseX < b3location.x+30 && mouseY > 170 && mouseY < 230 && currentCondiment == neededCondiment3) {
      Burger3IsReady = true;
    }
    if (mouseX > b4location.x-30 && mouseX < b4location.x+30 && mouseY > 240 && mouseY < 300 && currentCondiment == neededCondiment4) {
      Burger4IsReady = true;
    }
  }

// check for every case scenario
  void matchTheCondiment() {
    if (neededCondimentRandomizer1 == 1) {
      neededCondiment1 = 1;
      fill(240, 20, 20);
      rectMode(CORNERS);
      rect(20, 85, 40, 105);
    }
    if (neededCondimentRandomizer1 == 2) {
      neededCondiment1 = 2;
      fill(255, 245, 50);
      rectMode(CORNERS);
      rect(20, 85, 40, 105);
    }
    if (neededCondimentRandomizer1 == 3) {
      neededCondiment1 = 3;
      fill(50, 170, 50);
      rectMode(CORNERS);
      rect(20, 85, 40, 105);
    }
    if (neededCondimentRandomizer2 == 1) {
      neededCondiment2 = 1;
      fill(240, 20, 20);
      rectMode(CORNERS);
      rect(20, 155, 40, 175);
    }
    if (neededCondimentRandomizer2 == 2) {
      neededCondiment2 = 2;
      fill(255, 245, 50);
      rectMode(CORNERS);
      rect(20, 155, 40, 175);
    }
    if (neededCondimentRandomizer2 == 3) {
      neededCondiment2 = 3;
      fill(50, 170, 50);
      rectMode(CORNERS);
      rect(20, 155, 40, 175);
    }
    if (neededCondimentRandomizer3 == 1) {
      neededCondiment3 = 1;
      fill(240, 20, 20);
      rectMode(CORNERS);
      rect(20, 225, 40, 245);
    }
    if (neededCondimentRandomizer3 == 2) {
      neededCondiment3 = 2;
      fill(255, 245, 50);
      rectMode(CORNERS);
      rect(20, 225, 40, 245);
    }
    if (neededCondimentRandomizer3 == 3) {
      neededCondiment3 = 3;
      fill(50, 170, 50);
      rectMode(CORNERS);
      rect(20, 225, 40, 245);
    }
    if (neededCondimentRandomizer4 == 1) {
      neededCondiment4 = 1;
      fill(240, 20, 20);
      rectMode(CORNERS);
      rect(20, 295, 40, 315);
    }
    if (neededCondimentRandomizer4 == 2) {
      neededCondiment4 = 2;
      fill(255, 245, 50);
      rectMode(CORNERS);
      rect(20, 295, 40, 315);
    }
    if (neededCondimentRandomizer4 == 3) {
      neededCondiment4 = 3;
      fill(50, 170, 50);
      rectMode(CORNERS);
      rect(20, 295, 40, 315);
    }
  }
}