xxxxxxxxxx
/*
Duck Race
The ducks race each other and a random one wins
every time. The loop freezes on the winner, and pressing
any key will pause the race.
02 14 2017
Jayne Kennedy
*/
void setup(){
size(500,500);
noStroke();
smooth();
}
int xPos = 0;
int xPos2 = 0;
int xPos3 = 0;
int xPos4 = 0;
void draw(){
background(100,200,200);
fill(255,0,100);
rect(450,0,20,500);
duck(xPos,100,50,25,255,200,100);
duck(xPos2,200,50,25,200,100,255);
duck(xPos3,300,50,25,100,200,255);
duck(xPos4,400,50,25,0,0,0);
xPos += int(random(-2,5));
if(xPos>width){
xPos = 0;
}
if(xPos > width-50){
noLoop();
textSize(20);
text("Gold Wing won!",200,250);
print("Goldwing won!");
}
xPos2 += int(random(-2,5));
if(xPos2>width){
xPos2 = 0;
}
if(xPos2 > width-50){
noLoop();
textSize(20);
text("Purple Wing won!",200,250);
print("Purplewing won!");
}
xPos3 += int(random(-2,5));
if(xPos3>width){
xPos3 = 0;
}
if(xPos3 > width-50){
noLoop();
textSize(20);
text("Blue Wing won!",200,250);
print("Bluewing won!");
}
xPos4 += int(random(-2,5));
if(xPos4>width){
xPos4 = 0;
}
if(xPos4 > width-50){
noLoop();
textSize(20);
text("Black Wing won!",200,250);
print("Blacking won!");
}
}
void duck(float x, float y, int sizeX, int sizeY, int r, int g, int b){
fill(255);
noStroke();
ellipse(x,y,sizeX,sizeY);
ellipse(x+20,y-15,sizeX-25,sizeY);
fill(255,200,50);
ellipse(x+30,y-10,sizeX-35,sizeY-18);
fill(0);
ellipse(x+20,y-17,sizeX-45,sizeY-20);
fill(r,g,b);
ellipse(x,y,sizeX-30,sizeY-5);
}
void keyPressed(){
noLoop();
}
void keyReleased(){
loop();
}