// Yennifer Tejada // project 3 int score = 0; float horizon; float sunX= 100; float sunY = 100; float dayNight = 2; // float birds float bird1X, bird1Y = 10; float bird2X, bird2Y = 20; float bird3X, bird3Y = 35; float bird4X, bird4Y = 50; float bird5X, bird5Y = 60; float goldX; float goldY; float platanoX; float platanoY; float fritoX; float fritoY; float monoX; float monoY; float monoXX; float monoYY; 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); monoX = 795; monoY = 580; monoXX= 55; monoYY = 55; } void draw() { scene(); sun(); hero(); monster(); gold(); birds(); ladder(); mono(); 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); } void sun() { // sun/moon goes accross screen if (dayNight % 2 == 0) { noStroke(); ellipseMode(CENTER); fill(255, 255, 0);// color of the sun ellipse (sunX, sunY, 60, 60);// size of the sun // speed of the sun/ moon sunX = sunX + 1.5; } else { //fill(255); // color of the moon background(100, 99, 96); fill(50, 164, 25); noStroke(); rectMode(CORNER); rect(0, horizon, width, height* 3/4); // moon fill(255); ellipseMode( CENTER); ellipse(sunX, sunY, 60, 60); } // speed of the moon sunX = sunX + 1; if (sunX > width + 20) { sunX = 0; dayNight = dayNight + 1; } } void birds() { stroke(3); 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); } 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) ); fill(41, 214, 103); drawBird(bird2X, bird2Y); fill(169, 203, 66); drawBird(bird3X, bird3Y); fill(27, 82, 219); drawBird(bird4X, bird4Y); 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 ); } // 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; } void hero() // move and draw platano { platanoX = platanoX +(goldX-platanoX)/90; platanoY = platanoY + (goldY-platanoY)/90; fill(250, 10, 14); rectMode(CENTER); stroke(2); // 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 ellipse(platanoX+35, platanoY+25, 15, 20);// hand ellipse(platanoX-35, platanoY+25, 15, 20);//hand 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(20)); } } void reset() { /* monoX = 795; monoY = 580; monoXX= 55; monoYY = 55; */ goldX= random(width/2, width*3/4); goldY= random(horizon+10, height-10); platanoX= width; platanoY= height; fritoX=0; fritoY=horizon; } void ladder() { fill(15, 123, 123); for (int i = 2; i < 35; i += 2) { rect(800, i * 25, 100, 20, 60); } rect(845, 40, 20, 2000, 900); rect(745, 100, 20, 2000, 80); } void mono() { fill(125, 12, 45); ellipseMode(CENTER); noStroke(); ellipse(monoX, monoY, monoXX, monoYY); ellipse(monoX, monoY-30, monoXX-20, monoYY-20); rect(monoX, monoY + 40, monoXX - 70, monoYY); rect(monoX-30, monoY-20, monoXX -20, monoYY-50); rect(monoX+30, monoY-20, monoXX- 20, monoYY-50); rect(monoX+30, monoY+23, monoXX-20, monoYY-50); rect(monoX-30, monoY+23, monoXX-20, monoYY-50); } void keyPressed() { if (key == 'u') { monoY = monoY - 15; } if ( key == 'd') { monoY = monoY + 15; } // quit key if (key == 'q') exit(); }