int score=0; int step; float sunX=100, sunY=100; float horizon; float plueX, plueY; float enemyX, enemyY; float enemyStep; float look; float goldX, goldY; float bird1X, bird1Y=20, bomb1Y=1; float bird2X, bird2Y=40, bomb2Y=1; float bird3X, bird3Y=60, bomb3Y=1; float bird4X, bird4Y=80, bomb4Y=1; void setup() { //setup// size(820, 600); horizon= height/2; sunY= horizon/2; plueX=width/2; plueY=height/2; enemyX=30; enemyY=random(horizon, height-60); goldX=width-50; goldY= random(horizon+50, height-50); } void reset() { if (random(1) > 0.5) { plueX= width-30; enemyX=30; } else { enemyX= width-30; plueX=30; } plueY= random( horizon,height-60 ); enemyY= random( horizon,height-60 ); goldX= random( width/4, width*3/4); goldY= random(horizon+20,height-20); mouseY=height; } void draw() { //next frame// scene(); birds(); gold(); hero(); monster(); scoring(); step = step+1; if (step % 15 == 0) enemyStep= random( -15, 15 ); } void scene() { //sky, sun, etc. background(200, 200, 255); fill(255, 255, 0); ellipse(sunX, sunY, 125, 125); fill(200, 255, 200); rectMode(CORNER); rect(0, horizon, width, height*3/4); // sun moves across sky // if (sunX > width) { sunX=0; sunY= random(30, horizon-30); score= score+100; } sunX= sunX+1; fill(0); // text(sunX, sunX, sunY+40); text( "SCORE= " + score, width-200, 50); } void birds() { bird1X += random(3,5); bird2X += random(2,4); bird3X += random(1,2); bird4X += random(2,3); if (bird1X>width+500) { bird1X= 80; bird1Y= random(20,horizon); } if (bird2X>width+500) { bird2X= 80; bird2Y= random(20,horizon); } if (bird3X>width+500) { bird3X= 80; bird3Y= random(20,horizon); } if (bird4X>width+55) { bird4X= 80; bird4Y= random(20,horizon); } // draw birds & bombs // fill( 255,0,0 ); drawBird( bird1X, bird1Y+5-random(5) ); bomb1Y= updateBomb( bomb1Y ); drawBomb( bird1X, bomb1Y ); fill(0,255,0 ); drawBird( bird2X, bird2Y+6-random(6) ); bomb2Y= updateBomb( bomb2Y ); drawBomb( bird2X, bomb2Y ); fill( 255,255,0 ); drawBird( bird3X, bird3Y+5-random(5) ); bomb3Y= updateBomb( bomb3Y ); drawBomb( bird3X, bomb3Y ); fill( 0,255,255 ); drawBird( bird4X, bird4Y+6-random(6) ); bomb4Y= updateBomb( bomb4Y ); drawBomb( bird4X, bomb4Y ); } void drawBird( float x, float y ) { //// draw one bird ///// triangle( x,y, x-60,y-10, x-60,y+10 ); // Make the wings flap (every 1/2 second). float flap; if ( step/30 % 4 == 0 ) flap= 20; else if ( step/30 % 4 == 1 ) flap= -10; else if ( step/30 % 4 == 2 ) flap= -20; else flap= +10; birdWing( x, y, flap ); } void birdWing( float x, float y, float yup ) { // Draw the wing (up or down). triangle( x-20,y, x-40,y, x-40,y-yup ); } float updateBomb( float y ) { if (y<=0 || y>height) return 0; return y + 1 + y/40; } 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); triangle( x,y+3, x-15,y-12, x+15,y-12 ); } void hero() { // move & draw Plue // plueX= plueX + (mouseX-plueX)/30; plueY= mouseY + (mouseY-plueY)/30; //head// fill(0, 255, 0); ellipse(plueX, plueY, 95, 100); //nose// fill(237, 82, 63); rect(plueX-10, plueY-5, 20, 20); //eyes // fill(255); ellipse(plueX-25, plueY-10, 20, 20); ellipse(plueX+25, plueY-10, 20, 20); fill(0, 9, 222); ellipse(plueX+25, plueY-10, 5, 5); ellipse(plueX-25, plueY-10, 5, 5); //mouth// fill(255, 82, 96); ellipse(plueX, plueY+30, 25, 15); //body// fill(167, 9, 257); rectMode(CENTER); rect(plueX, plueY+100, 100, 100); //legs// fill(0, 200, 255); rect(plueX+25, plueY+180, 25, 50); rect(plueX-25, plueY+180, 25, 50); //hands// fill(255, 160, 0); rect(plueX+75, plueY+20, 25, 95); rect(plueX-75, plueY+20, 25, 95); //name// fill(0); text( "PLUE", plueX-10, plueY+100 ); //gold scoring// if ( dist( plueX, plueY, goldX, goldY ) < 50 ) { score += random( 100, 200 ); background(255, 255, 255); reset(); } } void monster() { //move and draw enemy// //chase plue enemyX= enemyX + (plueX-enemyX)/150; enemyY= enemyY + (plueY-enemyY)/150; if (dist(plueX, plueY, enemyX, enemyY) < 105) { eat(); } //draw Enemy// //head// fill(255); ellipse(enemyX, enemyY, 95, 100); //nose// fill(237, 82, 0); rectMode(CENTER); rect(enemyX, enemyY, 20, 20); //eyes // fill(255); ellipse(enemyX-25, enemyY-10, 20, 20); ellipse(enemyX+25, enemyY-10, 20, 20); fill(255, 9, 6); ellipse(enemyX-25, enemyY-10, 5, 5); ellipse(enemyX+25, enemyY-10, 5, 5); //black brows// fill(0); rectMode(CENTER); rect(enemyX, enemyY-25, 70, 5); //mouth// fill(255, 82, 96); ellipse(enemyX, enemyY+30, 25, 15); //body// fill(87, 169, 2); rectMode(CENTER); rect(enemyX, enemyY+100, 100, 100); //legs// fill(0); rect(enemyX+25, enemyY+180, 25, 35); rect(enemyX-25, enemyY+180, 25, 35); //hands// fill(255, 0, 0); rect(enemyX+90, enemyY+75, 55, 25); rect(enemyX-90, enemyY+75, 55, 25); //name// fill(255); text( "ENEMY ", enemyX-10, enemyY+100 ); //gold scoring// if ( dist( goldX, goldY, enemyX, enemyY ) < 50 ) { goldX= 50; goldY= random(horizon, height); } } void gold() { // Draw the gold. // if (goldY>horizon) { fill(random(250), random(200), random(150)); ellipse( goldX, goldY, 40+random(10), 40+random(10) ); fill(random(250), random(200), random(100)); ellipse( goldX, goldY, 30+random(5), 30+random(5) ); fill(255, 255, 0); ellipse( goldX, goldY, 20+random(10), 20+random(10) ); } } void scoring() { } void eat() { //Monster kills hero. Deduct 200 from score.// score= score - 200; background(255, 0, 0); plueX= width/2; plueY= height/2; enemyX= width/2; enemyY= height/2; enemyX=0; } void mousePressed() { // plueX= mouseX; plueY= mouseY; score= score - 50; enemyX=0; } void keyPressed() { if (key == 'q') exit(); if (key == 'r') reset(); if (key == '1') bomb1Y= bird1Y; if (key == '2') bomb2Y= bird2Y; if (key == '3') bomb3Y= bird3Y; if (key == '4') bomb4Y= bird4Y; if (key == '*') { bomb1Y= bird1Y; bomb2Y= bird2Y; bomb3Y= bird3Y; bomb4Y= bird4Y; } }