Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/////////////////////// //<>//
///BOMB DIFFUSE TIME///
////Michael Guattery///
///////////////////////

/* Purpose and Functionality: Volatile multi-colored bombs are on the conveyor belt. Clicking them will diffuse/destroy them. Try not to miss! */

//bomb movement variables
float bombX;
float bombY;

//bombSpeed
float bombSpeedX;
//color variables
color bombColor;


void setup() {
  size(400, 400);
}

void draw() {
  /* This part took awhile for me to organize, keeping everything in the perfect order was a challenge in itself, but paid off in the end.*/
  background(100, 150, 250);
  backDrop();
  conveyorBelt();
  drawWheels();
  drawBind();
  moveBomb();
  drawBomb();
  //cursor that looks like a finger
  noStroke();
  rectMode(CORNER);
  fill(255);
  rect(mouseX+3, mouseY+4, 6, 6, 3, 0, 2, 0);
  rect(mouseX+3, mouseY, 2, 6, 3, 0, 2, 0);
  rect(mouseX, mouseY+6, 6, 2, 6, 0, 2, 0);
  noCursor();
}
/*This was the random function for the colors of the bomb to change, they were fun to code but challenging to find out the order they needed to switch in.*/
void typebombColor() {
  bombColor=color(random(240), random(230), random(230));
}
/*The actual movement of the bomb was a challenge to loop, yet was possible with the if statement.*/
void moveBomb() {
  if (bombX<width+20) {
    bombX+=random(6, 15);
  }
  if (bombX>width) {
    bombX=0;
    bombY=250;
    typebombColor();
  }
}
//Back Drop
void backDrop() {
  noStroke();
  rectMode(CORNERS);
  fill(100, 150, 250);
  rect(0, 0, 400, 400);
  fill(80, 130, 220);
  rect(0, 0, 400, 350);
  fill(50, 110, 190);
  rect(0, 0, 400, 300);
  fill(40, 90, 170);
  rect(0, 0, 400, 280);
  fill(30, 80, 150);
  rect(0, 0, 400, 200);
  fill(20, 60, 130);
  rect(0, 0, 400, 110);
  //Science lab
  fill(20, 40, 80);
  rect(0, 220, 230, 230);
  rect(10, 230, 20, 290);
  rect(210, 230, 220, 290);
  triangle(40, 220, 60, 190, 80, 220);
  rect(55, random(160, 170), 65, 210);
  ellipse(125, 210, 40, 40);
  rect(160, 180, 170, 220);
  rect(190, 150, 200, 220);
  fill(0);
  ellipse(300, 100, 80, 80);
  fill(255);
  ellipse(300, 100, 70, 70);
  fill(0);
  rect(297, 70, 303, 130);
}

//Conveyor Belt
void conveyorBelt() {
  noStroke();
  //belt
  fill(5, 26, 53);
  rect(0, 255, 400, 270);
  //table and legs
  fill(100, 150, 180);
  rect(5, 315, 30, 400);
  rect(165, 315, 190, 400);
  rect(325, 315, 350, 400);
  fill(170, 190, 220);
  rect(10, 315, 25, 400);
  rect(170, 315, 185, 400);
  rect(330, 315, 345, 400);
  rect(0, 270, 400, 315);
  fill(100, 150, 180);
  rect(5, 275, 395, 310);
}
//wheels
/* I wanted moving wheels for my conveyor belt, so to simulate the movement of wheels I added the random function to change the size.*/
void drawWheels() {
  strokeWeight(random(20, 25));
  stroke(20, 40, 120);
  point(20, 292.5);
  point(55, 292.5);
  point(90, 292.5);
  point(125, 292.5);
  point(160, 292.5);
  point(195, 292.5);
  point(230, 292.5);
  point(265, 292.5);
  point(300, 292.5);
  point(335, 292.5);
  point(370, 292.5);
}

//wheelbind
void drawBind() {
  noStroke();
  fill(0);
  rect(random(2, 5), 290.5, random(395, 398), 294.5);
  strokeWeight(10);
  stroke(255);
  point(20, 292.5);
  point(55, 292.5);
  point(90, 292.5);
  point(125, 292.5);
  point(160, 292.5);
  point(195, 292.5);
  point(230, 292.5);
  point(265, 292.5);
  point(300, 292.5);
  point(335, 292.5);
  point(370, 292.5);
}

//Bombs
void drawBomb() {
  //Lit Fuse
  rectMode(CORNERS);
  noStroke();
  fill(random (255), random (120), random (80));
  ellipse(bombX+35, 173, random(10, 20), random(14, 23));
  //actual bomb part
  fill(0);
  rect(bombX+20, 195, bombX+50, 205);
  fill(bombColor);
  rect(bombX, 215, bombX+70, 255);
  rect(bombX+10, 205, bombX+60, 265);
  rect(bombX+10, 185, bombX+60, 195);
  fill(255);
  rect(bombX+30, 175, bombX+40, 185);
  rect(bombX+15, 230, bombX+25, 240);
  rect(bombX+35, 230, bombX+45, 240);
}

//mousePressed
/* This is what I used to create the clickable bombs, clicking resets the bomb location.*/
void mousePressed() {
  //diffuse bomb
  if (mousePressed=true && bombX>=mouseX-30 && bombX<=mouseX+30 && bombY>=mouseY-30 && bombY<=mouseY+30) {
    bombX=-70;
    bombY=250;
  }
}