xxxxxxxxxx
/*---------------
Ziqi Zhou
ART 3001
Feb 14, 2017
Racing car
-----------------*/
int car_x1 = 0;
int move_x1 =int(random(2,50));
int car_x2 = 0;
int move_x2=int (random(10,50));
int car_x3 = 0;
int move_x3=int (random(5,60));
int car_x4 = 0;
int move_x4=int (random(10,40));
void setup(){
size(500,500);
frameRate(5);
}
void draw(){
background(255);
strokeWeight(3);
line(0,25,500,25);
line(400,0,400,500);
line(0,125,500,125);
line(0,225,500,225);
line(0,325,500,325);
line(0,425,500,425);
fill(#C67A7A);
car( car_x1,50);
fill(#7E8DDB);
car( car_x2,150);
fill(#6FB1D3);
car( car_x3,250);
fill(#9ED1B9);
car( car_x4,350);
car_x1 = car_x1 + move_x1;
car_x2 = car_x2 + move_x2;
car_x3 = car_x3 + move_x3;
car_x4 = car_x4 + move_x4;
if (car_x1>=400){
//car_x1=400;
// move_x1=0;
noLoop();
println("car1 wins");
}
if (car_x2>=400){
//car_x2=400;
noLoop();
println("car2 wins");
}
if (car_x3>=400){
noLoop();
println("car3 wins");
}
if (car_x4>=400){
noLoop();
println("car4 wins");
}
}
void car(int x,int y){
quad(x-15,y+10,x+30,y+10,x+40,y+40,x-20,y+40);
ellipse(x-5,y+40,10,10);
ellipse(x+25,y+40,10,10);
}