Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
//Targetz - An Interactive Toy by David Brown//
//Knock down each target as they pop up by shooting them with the mock gun.//
//Use the left and right arrow keys to control the gun and left control to shoot//

float targetOne = 140;
float targetTwo = 140;
float targetThree = 140;
float gunPosition;
float ballY = 245;


void setup() {
  size(400, 400);
  background(130, 200, 225);
  fill(100, 100, 100);
  rect(0, 230, 400, 170);
  gunPosition = 200;
}

void draw() {


  float gunX = constrain(gunPosition, 100, 300);

  //GameStand Base and Supports//

  //BackBoard//
  fill(75, 150, 75);
  rect(90, 80, 220, 120);
  strokeWeight(3);
  stroke(40, 70, 33);
  line(90, 100, 310, 100);
  line(90, 120, 310, 120);
  line(90, 140, 310, 140);
  line(90, 160, 310, 160);
  line(90, 180, 310, 180);

  //Targets//
  target1();
  target2();
  target3();

  //Floor//
  fill(100, 75, 45);
  noStroke();
  rect(52, 259, 300, 100);
  //Backwall//
  fill(135, 85, 20);
  rect(80, 200, 240, 60);
  //Left Sidewall//
  noStroke();
  triangle(80, 200, 80, 260, 50, 260);
  triangle(50, 260, 80, 260, 50, 310);
  triangle(50, 260, 30, 300, 50, 300);
  stroke(0);
  line(30, 300, 80, 200);
  line(80, 260, 58, 300);
  //Right SideWall//
  noStroke();
  triangle(320, 200, 320, 260, 350, 260);
  triangle(320, 260, 350, 260, 350, 310);
  triangle(350, 260, 350, 300, 370, 300);
  stroke(0);
  line(320, 200, 370, 300);
  line(320, 260, 342, 300);
  //FrontWall//
  fill(180, 115, 25);
  rect(30, 300, 340, 100);
  //Support Poles//
  fill(150, 155, 160);
  rect(10, 80, 20, 320);
  rect(370, 80, 20, 320);
  strokeWeight(1);
  fill(100, 112, 115);
  rect(80, 80, 10, 180);
  rect(310, 80, 10, 180);


  //Carnie//
  stroke(0);
  strokeWeight(4);
  line(330, 299, 325, 270);
  line(325, 270, 340, 250);
  line(340, 250, 305, 260);
  line(305, 260, 320, 299);
  line(340, 250, 345, 180);
  strokeWeight(3);
  line(344, 190, 355, 230);
  line(355, 230, 345, 245);
  line(344, 190, 325, 220);
  line(325, 220, 320, 180);
  fill(0);
  ellipse(345, 165, 40, 40);
  strokeWeight(1);
  fill(245, 240, 235);
  rect(318, 173, 15, 5);
  fill(235, 160, 65);
  rect(333, 173, 3, 5);
  noStroke();
  fill(255, 100, 25);
  ellipse(318, 176, 4, 5);

  //Gun Rail//
  stroke(30, 30, 30);
  strokeWeight(4);
  line(70, 280, 70, 300);
  line(330, 280, 330, 300);
  line(70, 280, 330, 280);

  //Gun//
  strokeWeight(2);
  fill(130, 75, 25);
  rect(gunX -5, 270, 10, 20);
  fill(100, 100, 120);
  rect(gunX -5, 255, 10, 15); 
  rect(gunX -3, 250, 6, 5);

  fill(255, 255, 0);

  if (keyPressed) {

    if (keyCode==LEFT) {
      gunPosition -= 5;
    }
    if (keyCode==RIGHT) {
      gunPosition += 5;
    }

    if (keyCode==CONTROL) {
      ellipse(gunX, ballY, 8, 8); 
      ballY -= 20;
      if (100<gunX && gunX<140) {
        targetOne += 10;
      }
      if (180<gunX && gunX<220) {
        targetTwo += 10;
      }
      if (260<gunX && gunX<300) {
        targetThree += 10;
      }
      if (ballY<0) {
        ballY=245;
      }
    }
  }

  //WINNER!//
  if (targetOne > 300 && targetTwo > 300 && targetThree > 300) {
    fill(175, 35, 200);
    //W//
    rect(80, 320, 240, 60);
    line(80, 330, 85, 370);
    line(85, 370, 95, 370);
    line(95, 370, 100, 350);
    line(100, 350, 105, 370);
    line(105, 370, 115, 370);
    line(115, 370, 120, 330);
    line(120, 330, 110, 330);
    line(110, 330, 105, 345);
    line(105, 345, 102, 340);
    line(102, 340, 98, 340);
    line(98, 340, 95, 345);
    line(95, 345, 90, 330);
    line(90, 330, 80, 330);
    //I//
    line(120, 330, 150, 330);
    line(150, 330, 150, 340);
    line(150, 340, 140, 340);
    line(140, 340, 140, 360);
    line(140, 360, 150, 360);
    line(150, 360, 150, 370);
    line(150, 370, 120, 370);
    line(120, 370, 120, 360);
    line(120, 360, 130, 360);
    line(130, 360, 130, 340);
    line(130, 340, 120, 340);
    line(120, 340, 120, 330);
    //N//
    line(150, 370, 150, 330);
    line(150, 330, 165, 330);
    line(165, 330, 175, 360);
    line(175, 360, 175, 330);
    line(175, 330, 185, 330);
    line(185, 330, 185, 370);
    line(185, 370, 170, 370);
    line(170, 370, 160, 340);
    line(160, 340, 160, 370);
    line(160, 370, 150, 370);
    //N2//
    line(185, 370, 185, 330);
    line(185, 330, 200, 330);
    line(200, 330, 210, 360);
    line(210, 360, 210, 330);
    line(210, 330, 220, 330);
    line(220, 330, 220, 370);
    line(220, 370, 205, 370);
    line(205, 370, 195, 340);
    line(195, 340, 195, 370);
    line(195, 370, 185, 370);
    //E//
    line(220, 370, 220, 330);
    line(220, 330, 245, 330);
    line(245, 330, 245, 340);
    line(245, 340, 230, 340);
    line(230, 340, 230, 345);
    line(230, 345, 240, 345);
    line(240, 345, 240, 355);
    line(240, 355, 230, 355);
    line(230, 355, 230, 360);
    line(230, 360, 245, 360);
    line(245, 360, 245, 370);
    line(245, 370, 220, 370);
    //R//
    line(250, 370, 250, 330);
    line(250, 330, 270, 330);
    line(270, 330, 275, 335);
    line(275, 335, 275, 345);
    line(275, 345, 270, 350);
    line(270, 350, 280, 370);
    line(280, 370, 270, 370);
    line(270, 370, 260, 350);
    line(260, 350, 260, 370);
    line(260, 370, 250, 370);
    line(260, 337, 260, 343);
    line(260, 343, 264, 343);
    line(264, 343, 266, 340);
    line(266, 340, 264, 337);
    line(264, 337, 260, 337);
    //!//
    line(295, 330, 305, 330);
    line(305, 330, 305, 360);
    line(305, 360, 295, 360);
    line(295, 360, 295, 330);
    noFill();
    ellipse(300, 370, 10, 10);
  }

  //Canvas Roof//
  strokeWeight(1);
  fill(200, 0, 0);
  triangle(100, 0, 100, 80, 0, 80);
  triangle(300, 0, 300, 80, 400, 80);
  noStroke();
  rect(100, 0, 201, 80); 
  stroke(0);
  line(100, 80, 300, 80);
  line(100, 0, 300, 0);
  fill(255);
  rect(220, 0, 20, 80);
  rect(160, 0, 20, 80);
  rect(100, 0, 20, 80);
  rect(280, 0, 20, 80);
  
}

void target1() {
  //TargetOne//
  strokeWeight(2);
  stroke(0);
  line(120, targetOne, 120, targetOne+60);
  fill(255, 0, 0);
  ellipse(120, targetOne, 40, 40);
  fill(255);
  ellipse(120, targetOne, 30, 30);
  fill(255, 0, 0);
  ellipse(120, targetOne, 20, 20);
  fill(255);
  ellipse(120, targetOne, 10, 10);
}

void target2() {
  //TargetTwo//
  strokeWeight(2);
  stroke(0);
  line(200, targetTwo, 200, targetTwo+60);
  fill(255, 0, 0);
  ellipse(200, targetTwo, 40, 40);
  fill(255);
  ellipse(200, targetTwo, 30, 30);
  fill(255, 0, 0);
  ellipse(200, targetTwo, 20, 20);
  fill(255);
  ellipse(200, targetTwo, 10, 10);
}

void target3() {

  //TargetThree//
  strokeWeight(2);
  stroke(0);
  line(280, targetThree, 280, targetThree+60);
  fill(255, 0, 0);
  ellipse(280, targetThree, 40, 40);
  fill(255);
  ellipse(280, targetThree, 30, 30);
  fill(255, 0, 0);
  ellipse(280, targetThree, 20, 20);
  fill(255);
  ellipse(280, targetThree, 10, 10);
}