Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
//Darryl Feniquito
//Corvette model driving 

//Declared to Corvette Z06 movement and size
float playerPositionX=0;
float playerPositionY=0;
float playerSizeX=300;
float playerSizeY=200;

//Assigned to objects on screen
float speed = 3;
float ellipseX1 = 0;
float ellipseX2 =0;

//Declared to keyPressed functions to move Corvette
boolean goleft=false;
boolean goRight=false;
boolean goUp=false;
boolean goDown=false;
boolean stop = false;

//Assigned to random colors when mouseClicked is activated
boolean isClicked = false;
int red = (int) random(0, 256);
int green = (int) random(0, 256);
int blue = (int) random(0, 256);

//Set the size of window
void setup() {
  size(400, 400);
}
//draw background for vehicle
void draw() {

  drawBackground();
  moveCar();
  drawCar();
}

void drawCar() {
  //draw tinted windows
  fill(255, 28, 3);
  ellipseMode(CENTER);
  ellipse(160+playerPositionX, 225-playerPositionY+1*sin(frameCount*1), 10, 20);
  fill(0);
  rectMode(CENTER);
  rect(145+playerPositionX, 220-playerPositionY+1*sin(frameCount*1), 10, 19);
  noStroke();
  fill(0, 0, 0, 124);
  quad(110+playerPositionX, 240-playerPositionY+1*sin(frameCount*1), 110+playerPositionX, 211-playerPositionY+1*sin(frameCount*1), 140+playerPositionX, 210-playerPositionY+1*sin(frameCount*1), 140+playerPositionX, 240-playerPositionY+1*sin(frameCount*1));
  quad(150+playerPositionX, 240-playerPositionY+1*sin(frameCount*1), 150+playerPositionX, 210-playerPositionY+1*sin(frameCount*1), 185+playerPositionX, 210-playerPositionY+1*sin(frameCount*1), 240+playerPositionX, 240-playerPositionY+1*sin(frameCount*1));
  quad(240+playerPositionX, 240-playerPositionY+1*sin(frameCount*1), 185+playerPositionX, 210-playerPositionY+1*sin(frameCount*1), 218+playerPositionX, 210-playerPositionY+1*sin(frameCount*1), 265+playerPositionX, 240-playerPositionY+1*sin(frameCount*1));

  //draw main body of Corvette
  //front & side of Corvette
  noStroke();
  fill(0);
  rect(350+playerPositionX, 275-playerPositionY+1*sin(frameCount*1), 32, 22);
  fill(22, 170, 247);
  rectMode(CENTER);
  rect(150+playerPositionX, 250-playerPositionY+1*sin(frameCount*1), 200, 40);
  quad(150+playerPositionX, 230-playerPositionY+1*sin(frameCount*1), 75+playerPositionX, 270-playerPositionY+1*sin(frameCount*1), 120+playerPositionX, 270-playerPositionY+1*sin(frameCount*1), 120+playerPositionX, 230-playerPositionY+1*sin(frameCount*1));
  ellipse(200+playerPositionX, 230-playerPositionY+1*sin(frameCount*1), 20, 10);

  //front grill
  quad(250+playerPositionX, 268-playerPositionY+1*sin(frameCount*1), 248+playerPositionX, 230-playerPositionY+1*sin(frameCount*1), 367+playerPositionX, 261-playerPositionY+1*sin(frameCount*1), 367+playerPositionX, 268-playerPositionY+1*sin(frameCount*1));
  triangle(316+playerPositionX, 300-playerPositionY+1*sin(frameCount*1), 340+playerPositionX, 284-playerPositionY+1*sin(frameCount*1), 350+playerPositionX, 300-playerPositionY+1*sin(frameCount*1));
  quad(340+playerPositionX, 300-playerPositionY+1*sin(frameCount*1), 340+playerPositionX, 290-playerPositionY+1*sin(frameCount*1), 368+playerPositionX, 290-playerPositionY+1*sin(frameCount*1), 370+playerPositionX, 300-playerPositionY+1*sin(frameCount*1));

  //side door
  triangle(152+playerPositionX, 290-playerPositionY+1*sin(frameCount*1), 216+playerPositionX, 275-playerPositionY+1*sin(frameCount*1), 216+playerPositionX, 290-playerPositionY+1*sin(frameCount*1));
  quad(216+playerPositionX, 290-playerPositionY+1*sin(frameCount*1), 216+playerPositionX, 275-playerPositionY+1*sin(frameCount*1), 235+playerPositionX, 285-playerPositionY+1*sin(frameCount*1), 240+playerPositionX, 290-playerPositionY+1*sin(frameCount*1));
  quad(50+playerPositionX, 240-playerPositionY+1*sin(frameCount*1), 50+playerPositionX, 230-playerPositionY+1*sin(frameCount*1), 115+playerPositionX, 210-playerPositionY+1*sin(frameCount*1), 125+playerPositionX, 240-playerPositionY+1*sin(frameCount*1));
  triangle(120+playerPositionX, 240-playerPositionY+1*sin(frameCount*1), 120+playerPositionX, 225-playerPositionY+1*sin(frameCount*1), 150+playerPositionX, 230-playerPositionY+1*sin(frameCount*1));
  quad(213+playerPositionX, 279-playerPositionY+1*sin(frameCount*1), 216+playerPositionX, 266-playerPositionY+1*sin(frameCount*1), 290+playerPositionX, 253-playerPositionY+1*sin(frameCount*1), 240+playerPositionX, 298-playerPositionY+1*sin(frameCount*1));
  triangle(240+playerPositionX, 298-playerPositionY+1*sin(frameCount*1), 270+playerPositionX, 260-playerPositionY+1*sin(frameCount*1), 270+playerPositionX, 298-playerPositionY+1*sin(frameCount*1));
  quad(130+playerPositionX, 298-playerPositionY+1*sin(frameCount*1), 130+playerPositionX, 240-playerPositionY+1*sin(frameCount*1), 160+playerPositionX, 240-playerPositionY+1*sin(frameCount*1), 160+playerPositionX, 298-playerPositionY+1*sin(frameCount*1));
  quad(72+playerPositionX, 289-playerPositionY+1*sin(frameCount*1), 65+playerPositionX, 260-playerPositionY+1*sin(frameCount*1), 86+playerPositionX, 260-playerPositionY+1*sin(frameCount*1), 82+playerPositionX, 290-playerPositionY+1*sin(frameCount*1));

  //roof of corvette
  fill(22, 170, 247);
  quad(115+playerPositionX, 220-playerPositionY+1*sin(frameCount*1), 115+playerPositionX, 210-playerPositionY+1*sin(frameCount*1), 140+playerPositionX, 207-playerPositionY+1*sin(frameCount*1), 140+playerPositionX, 210-playerPositionY+1*sin(frameCount*1));
  quad(140+playerPositionX, 210-playerPositionY+1*sin(frameCount*1), 140+playerPositionX, 207-playerPositionY+1*sin(frameCount*1), 215+playerPositionX, 207-playerPositionY+1*sin(frameCount*1), 220+playerPositionX, 210-playerPositionY+1*sin(frameCount*1));
  quad(240+playerPositionX, 240-playerPositionY+1*sin(frameCount*1), 185+playerPositionX, 210-playerPositionY+1*sin(frameCount*1), 187+playerPositionX, 210-playerPositionY+1*sin(frameCount*1), 242+playerPositionX, 240-playerPositionY+1*sin(frameCount*1));

  //spoiler fom
  fill(0);
  quad(54+playerPositionX, 230-playerPositionY+1*sin(frameCount*1), 42+playerPositionX, 210-playerPositionY+1*sin(frameCount*1), 47+playerPositionX, 210-playerPositionY+1*sin(frameCount*1), 60+playerPositionX, 228-playerPositionY+1*sin(frameCount*1));
  rectMode(CENTER);
  rect(48+playerPositionX, 213-playerPositionY+1*sin(frameCount*1), 35, 6);
  quad(50+playerPositionX, 283-playerPositionY+1*sin(frameCount*1), 49+playerPositionX, 260-playerPositionY+1*sin(frameCount*1), 65+playerPositionX, 260-playerPositionY+1*sin(frameCount*1), 72+playerPositionX, 288-playerPositionY+1*sin(frameCount*1));
  quad(243+playerPositionX, 280-playerPositionY+1*sin(frameCount*1), 258+playerPositionX, 260-playerPositionY+1*sin(frameCount*1), 263+playerPositionX, 260-playerPositionY+1*sin(frameCount*1), 248+playerPositionX, 280-playerPositionY+1*sin(frameCount*1));

  //carbon fibre trim homie
  noStroke();
  fill(0);
  rectMode(CENTER);
  rect(200+playerPositionX, 300-playerPositionY+1*sin(frameCount*1), 150, 4);
  rect(340+playerPositionX, 300-playerPositionY+1*sin(frameCount*1), 60, 4);

  //details for Corvette
  noStroke();
  fill(8, 136, 198);
  quad(161+playerPositionX, 298-playerPositionY+1*sin(frameCount*1), 155+playerPositionX, 290-playerPositionY+1*sin(frameCount*1), 240+playerPositionX, 290-playerPositionY+1*sin(frameCount*1), 240+playerPositionX, 298-playerPositionY+1*sin(frameCount*1));
  quad(310+playerPositionX, 301-playerPositionY+1*sin(frameCount*1), 315+playerPositionX, 268-playerPositionY+1*sin(frameCount*1), 346+playerPositionX, 268-playerPositionY+1*sin(frameCount*1), 342+playerPositionX, 285-playerPositionY+1*sin(frameCount*1));
  rectMode(CENTER);
  rect(57+playerPositionX, 246-playerPositionY+1*sin(frameCount*1), 16, 29);
  quad(156+playerPositionX, 289-playerPositionY+1*sin(frameCount*1), 151+playerPositionX, 266-playerPositionY+1*sin(frameCount*1), 240+playerPositionX, 266-playerPositionY+1*sin(frameCount*1), 238+playerPositionX, 279-playerPositionY+1*sin(frameCount*1));
  triangle(192+playerPositionX, 237-playerPositionY+1*sin(frameCount*1), 191+playerPositionX, 230-playerPositionY+1*sin(frameCount*1), 210+playerPositionX, 235-playerPositionY+1*sin(frameCount*1));
  ellipseMode(CENTER);

  //front details
  fill(67, 65, 65);
  quad(340+playerPositionX, 285-playerPositionY+1*sin(frameCount*1), 342+playerPositionX, 268-playerPositionY+1*sin(frameCount*1), 347+playerPositionX, 267-playerPositionY+1*sin(frameCount*1), 344+playerPositionX, 285-playerPositionY+1*sin(frameCount*1));
  quad(345+playerPositionX, 290-playerPositionY+1*sin(frameCount*1), 340+playerPositionX, 285-playerPositionY+1*sin(frameCount*1), 367+playerPositionX, 285-playerPositionY+1*sin(frameCount*1), 367+playerPositionX, 290-playerPositionY+1*sin(frameCount*1));

  //wheels
  fill(64, 61, 61);
  ellipse(112+playerPositionX, 280-playerPositionY+1*sin(frameCount*1), 60, 60);
  ellipse(294+playerPositionX, 280-playerPositionY+1*sin(frameCount*1), 60, 60);
  fill(72, 71, 71);
  ellipse(112+playerPositionX, 280-playerPositionY+1*sin(frameCount*1), 45, 45);
  ellipse(294+playerPositionX, 280-playerPositionY+1*sin(frameCount*1), 45, 45);
  fill(24);
  ellipse(112+playerPositionX, 280-playerPositionY+1*sin(frameCount*1), 12, 12);
  ellipse(294+playerPositionX, 280-playerPositionY+1*sin(frameCount*1), 12, 12);

  //headlights & taillights
  fill(255, 255, 255, 200);
  quad(340+playerPositionX, 260-playerPositionY+1*sin(frameCount*1), 320+playerPositionX, 251-playerPositionY+1*sin(frameCount*1), 330+playerPositionX, 251-playerPositionY+1*sin(frameCount*1), 355+playerPositionX, 259-playerPositionY+1*sin(frameCount*1));
  fill(255, 0, 0);
  rectMode(CENTER);
  rect(52+playerPositionX, 240-playerPositionY+1*sin(frameCount*1), 5, 10);
  rect(55+playerPositionX, 267-playerPositionY+1*sin(frameCount*1), 11, 3);
  fill(255, 158, 0);
  rect(78+playerPositionX, 280-playerPositionY+1*sin(frameCount*1), 4, 16);
  rect(328+playerPositionX, 285-playerPositionY+1*sin(frameCount*1), 4, 16);

  if  (isClicked == true) {
    mousePressed();
  } else {
    isClicked = false;
  }
}

void moveCar() {
  if (playerPositionX >= -150) {
    if ( goleft == true) {
      playerPositionX= playerPositionX -speed;
    }
  }
  if (playerPositionX <= 250) {
    if ( goRight == true) {
      playerPositionX= playerPositionX +speed;
    }
  }
  if (playerPositionY <= 50) {
    if ( goUp == true) {
      playerPositionY= playerPositionY +speed;
    }
  }
  if (playerPositionY >=-150 ) {
    if ( goDown == true) {
      playerPositionY= playerPositionY -speed;
    }
  }
}

void drawBackground() {

  //sunset for my baby Corvette
  background(255, 161, 126);
  fill(229, 109, 65, 63);
  stroke(229, 109, 65, 63);
  fill(47, 162, 222, 63);
  rectMode(CENTER);
  rect(200, 50, 400, 100);
  fill(17, 107, 155, 200);
  rectMode(CENTER);
  rect(200, 0, 400, 50);
  fill(247, 225, 22, 100);
  rectMode(CENTER);
  rect(200, 100, 400, 50);

  //sun
  fill(255, 255, 255, 70);
  ellipse(340, 50, 120, 120);
  fill(255, 115, 8, 200);
  ellipse(340, 50, 40, 40);
  fill(229, 104, 7, 70);
  ellipse(340, 50, 60, 60);
  ellipse(340, 50, 85, 85);
  fill(247, 84, 25, 75);
  ellipse(340, 50, 115, 115);

  //clouds
  {
    if (ellipseX1 > -501 && ellipseX1 < 500) {
      ellipseX1 = ellipseX1 - speed;
      if (ellipseX1 < -500) {
        ellipseX1 = 500 - speed;
      }
    }
    fill(255, 255, 255, 150);
    noStroke();
    ellipseMode(CENTER);
    ellipse(-90+ellipseX1, 140, 100, 25);
    ellipse(-90+ellipseX1, 130, 85, 25);
    ellipse(-390+ellipseX1, 130, 85, 25);
    ellipse(-90+ellipseX1, 140, 100, 25);
    ellipse(-225+ellipseX1, 150, 130, 35);
    ellipse(-275+ellipseX1, 140, 130, 30);
    ellipse(-325+ellipseX1, 80, 130, 30);
    ellipse(-330+ellipseX1, 70, 100, 30);
    ellipse(-370+ellipseX1, 40, 100, 30);
    ellipse(-375+ellipseX1, 30, 90, 30);
    ellipse(-380+ellipseX1, 25, 80, 30);
    ellipse(500+ellipseX1, 50, 80, 30);
    ellipse(510+ellipseX1, 60, 90, 35);
    ellipse(550+ellipseX1, 120, 90, 35);
    ellipse(560+ellipseX1, 110, 85, 35);
    ellipse(700+ellipseX1, 110, 140, 35);
    ellipse(710+ellipseX1, 100, 90, 35);
    ellipse(720+ellipseX1, 120, 100, 35);
    ellipse(50+ellipseX1, 180, 150, 30);
    ellipse(40+ellipseX1, 170, 140, 25);
    ellipse(30+ellipseX1, 165, 110, 20);
    ellipse(180+ellipseX1, 80, 140, 20);
    ellipse(190+ellipseX1, 70, 115, 30);
    ellipse(330+ellipseX1, 100, 100, 20);
    ellipse(310+ellipseX1, 90, 90, 20);
    ellipse(350+ellipseX1, 85, 100, 30);
    ellipse(190+ellipseX1, 70, 115, 30);
    ellipse(225+ellipseX1, 150, 130, 40);
    ellipse(225+ellipseX1, 140, 110, 35);
    ellipse(395+ellipseX1, 140, 110, 35);
    ellipse(395+ellipseX1, 130, 95, 35);

    //draw road for Corvette
    fill(200, 204, 206);
    rectMode(CENTER);
    rect(200, 300, 400, 200);
    fill(255);
    rect(50+ellipseX1, 290, 60, 10);
    rect(150+ellipseX1, 290, 60, 10);
    rect(250+ellipseX1, 290, 60, 10);
    rect(350+ellipseX1, 290, 60, 10);
    rect(450+ellipseX1, 290, 60, 10);
    rect(550+ellipseX1, 290, 60, 10);
    rect(650+ellipseX1, 290, 60, 10);
    rect(750+ellipseX1, 290, 60, 10);
    rect(850+ellipseX1, 290, 60, 10);
    rect(-50+ellipseX1, 290, 60, 10);
    rect(-150+ellipseX1, 290, 60, 10);
    rect(-250+ellipseX1, 290, 60, 10);
    rect(-350+ellipseX1, 290, 60, 10);
    rect(-450+ellipseX1, 290, 60, 10);
    rect(-550+ellipseX1, 290, 60, 10);
    //shadow for baby Corvette
    noStroke();
    fill(0, 0, 0, 63);
    ellipseMode(CENTER);
    ellipse(200+playerPositionX, 300-playerPositionY+1*sin(frameCount*1), 335, 55);
  }
}

void keyPressed() {

  if (key == 'a') {
    goleft = true;
  }
  if (key == 'w') {
    goUp = true;
  }
  if (key == 's') {
    goDown = true;
  }
  if (key == 'd') {
    goRight = true;
  }
} 

void keyReleased () {
  if (key == 'a') {
    goleft = false;
  }
  if (key == 'w') {
    goUp = false;
  }
  if (key == 's') {
    goDown = false;
  }
  if (key == 'd') {
    goRight = false;
  }

  //Corvette stay within the frame
  if (playerPositionX >= 450) {
    speed = 0;
  }
}

//left click activates random headlights
void mousePressed() {

  int red = (int) random(0, 256);
  int green = (int) random(0, 256);
  int blue = (int) random(0, 256);
  isClicked = true;
  fill (red, green, blue, 200);
  quad(340+playerPositionX, 259-playerPositionY+1*sin(frameCount*1), 340+playerPositionX, 256-playerPositionY+1*sin(frameCount*1), 520+playerPositionX, 300-playerPositionY+1*sin(frameCount*1), 400+playerPositionX, 300-playerPositionY+1*sin(frameCount*1));
}

void mouseReleased() {
  isClicked = false;
}

void endProgram() {
  if (keyCode == 27) {
    stop = true;
  }
}