// Poject 2 // Yennifer Tejada int score = 0; float horizon; float sunX= 100; float sunY = 100; // float birds float bird1X, bird1Y = 10; float bird2X, bird2Y = 20; float bird3X, bird3Y = 35; float bird4X, bird4Y = 50; float bird5X, bird5Y = 60; //float fritoX= 300, fritoY=300; // monster //PFont f; float goldX; float goldY; float platanoX; float platanoY; float fritoX; float fritoY; void setup() //setup { size(900, 600); horizon = height/2; sunY= horizon/2; platanoX = width/2; platanoY = height/2; fritoX = 40; fritoY= random(horizon, height - 60); goldX=width-40; goldY= random(horizon+40, height-40); } void draw() { scene(); hero(); monster(); gold(); birds(); textSize(15); fill(0); text( " Please don't hurt me ", platanoX, platanoY-65); text("Score= "+score, 50, 50); text("Frito chases hero Platano", 350, 25); text("Author: Yennifer Tejada", 30, 590); } void scene() { background(65, 142, 247); fill(50, 165, 25); rectMode(CORNER); rect(0, horizon, width, height* 3/4); if (sunX > width) { sunX = 0; sunY = random (20, horizon-20); } fill(255, 255, 0); ellipse(sunX, sunY, 55, 55); sunX = sunX + 1.5; } void birds() { bird1X += random(4, 6); bird2X += random(1, 3); bird3X += random(3, 5); bird4X += random(2, 5); bird5X += random(1, 2); if (bird1X > width - 20) { bird1X = 60; bird1Y = random (20, horizon); } //+++++ 2??? if (bird2X > width - 20) { bird2X = 60; bird2Y = random (20, horizon); } if (bird3X > width - 20) { bird3X = 60; bird3Y = random (20, horizon); } if (bird4X > width - 20) { bird4X = 60; bird4Y = random (20, horizon); } if (bird5X > width - 20) { bird5X = 60; bird5Y = random (20, horizon); } fill(26, 139, 198); drawBird(bird1X, bird1Y+5+random(5) ); // bomb1Y= updateBomb(bomb1Y); // drawBomb(bird1X,bomb1Y); fill(41, 214, 103); drawBird(bird2X, bird2Y); // bomb2Y= updateBomb( bomb2Y ); // drawBomb(bird2X, bomb2Y); fill(169, 203, 66); drawBird(bird3X, bird3Y); //bomb3Y= updateBomb( bomb3Y ); //drawBomb(bird3X, bomb3Y); fill(27, 82, 219); drawBird(bird4X, bird4Y); /* bomb4Y= updateBomb( bomb4Y); drawBomb(bird4X, bomb4Y); */ fill(30, 70, 200); drawBird(bird5X, bird5Y); } // draw the 5 birds void drawBird( float x, float y ) { triangle( x, y, x-60, y-10, x-60, y+10 ); // float flap; //// if ( step/30 % 4 == 0 ) flap= 20; // else if ( step/40 % 4 == 1 ) flap= -15; // else if ( step/40 % 4 == 2 ) flap= -25; // else flap= +10; // birdWing( x, y, flap ); } // the wings for the birds void birdWing( float x, float y, float yup ) { triangle( x-25, y, x-45, y, x-45, y-yup ); } float updateBomb( float y ) { if (y<=0 || y>height) return 0; return y + 1 + y/50; } //// the bombs the birds throw void drawBomb( float x, float y ) { // if (y<=0) return; // ellipse( x,y, 20,30 ); // stroke(255,0,0); // fill( 255,0,0, 50 ); // ellipse( x,y, 50,50 ); // stroke(0); // fill(0,45,60); // triangle( x,y+3, x-15,y-12, x+15,y-12 ); } void hero() // move and draw platano { platanoX = platanoX +(goldX-platanoX)/90; platanoY = platanoY + (goldY-platanoY)/90; fill(250, 10, 14); rectMode(CENTER); // platano's legs fill(0); rect(platanoX-15, platanoY+50, 15, 55);// left leg rect(platanoX+15, platanoY+50, 15, 55);//right leg fill(255); rect(platanoX, platanoY, 50, 80); // body // platano's arms rect(platanoX-35, platanoY-10, 20, 60);// left arm rect(platanoX+35, platanoY-10, 20, 60);//right arm if (dist( platanoX, platanoY, goldX, goldY) <50) { score += 200; background (0, 0, 255); reset(); } fill(232, 234, 117); ellipse(platanoX, platanoY-40, 40, 50); //head fill(82, 185, 247); ellipse(platanoX-10, platanoY-50, 10, 15); // left eye ellipse(platanoX+10, platanoY-50, 10, 15); // right eye fill(0); ellipse(platanoX, platanoY-30, 10, 15); // mouth } void monster() { // chase platano fritoX= fritoX + (platanoX - fritoX)/150; fritoY= fritoY + (platanoY - fritoY)/150; //monster gets hero if (dist(platanoX, platanoY, fritoX, fritoY) < 50 ) { eat(); } fill(234, 25, 17); rectMode (CENTER); fill(0, 255, 0); ellipse(fritoX, fritoY, 70, 90); // body fill(125, 126, 115); ellipse(fritoX-45, fritoY-10, 25, 50);// left arm ellipse(fritoX+45, fritoY-10, 25, 50);//right arm fill(234, 225, 117); ellipse(fritoX, fritoY-40, 50, 60);// head // eyes,eyebrows and mouth of the monster fill(0, 15, 20); ellipse(fritoX-10, fritoY-50, 10, 15); // left eye ellipse(fritoX+10, fritoY-50, 5, 10); // right eye ellipse(fritoX, fritoY-20, 20, 5); // mouth rect(fritoX, fritoY-60, 30, 5); //eyesbrows ellipse(fritoX-20, fritoY+55, 25, 60);//right leg ellipse(fritoX+20, fritoY+55, 25, 60);//right leg // monster gets gold if ( dist( goldX, goldY, fritoX, fritoY ) < 50 ) { goldX= 50; goldY= random(horizon, height); } } void eat() { // monster eats hero! deduct 20 from score score= score - 20; background(0); reset(); } void mousePressed() { goldX = mouseX; goldY = mouseY; score = score -50; fritoX=0; fritoY=horizon; } void gold() { if (goldY>horizon) { fill(201, 172, 24); rect(goldX, goldY, 20, 20); rect(goldX, goldY, 40, 20); rect(goldX, goldY, 40+random(5), 20+random(5)); } } void reset() { goldX= random(width/2, width*3/4); goldY= random(horizon+10, height-10); platanoX= width; platanoY= height; fritoX=0; fritoY=horizon; }