/* Interactive Toy Design: Hungry Bird Ruxandra Gogorici The bird is controlled through mouse click, where it will being to flap it's wings and lift up while the mouse is being held. On release, the bird goes into a glide and begins descending. The bird can catch flies by navigating towards them on Y, as they appear on X. */ //Basic float variables for all transforming objects: bird, flies, clouds. float flyX = 0; float flyY = 200; float cloudX = 0; float cloudY = 100; float cloudX2 = 0; float cloudY2 = 100; float cloudX3 = 0; float cloudY3 = 100; float birdY = 0; float birdX = 0; float wingupY = 0; float wingupX = 0; float wingdownY = 0; float wingdownX = 0; //This sets the speed on X for the clouds and flies. float speedX = 8; float speedX2 = 4; //This sets the basic speed of lift and fall for all objects (which will only be applied to the bird). float gravity = 1; float thrust = -9; //Basic setup function to make everything... y'know, work lol. void setup() { size(400, 400); rectMode(CORNERS); ellipseMode(CORNERS); colorMode(RGB, 255, 255, 255, 100); } //Bird's body structure. void drawBird() { ellipseMode(CENTER); fill(200, 100, 100); ellipse(300, birdY, 20, 20); ellipse(320, birdY+2, 30, 23); ellipse(292, birdY+2, 10, 5); ellipse(329, birdY-3, 40, 8); ellipse(329, birdY+2, 30, 8); fill(255, 255, 255); ellipse(297, birdY-1, 3, 5); } //Bird's "flapping" wings simulated by ellipses of two different colours, rapidly expanding and retracting vertically. void drawWingup() { ellipseMode(CENTER); fill(180, 80, 80); ellipse(320, birdY-5, 20, 37*sin(frameCount*1.3)); } void drawWingdown () { fill(220, 120, 120); ellipse(320, birdY+10, 20, 37*sin(frameCount*1.3)); } //Basic draw function. void draw() { fill(195, 245, 250); noStroke(); rect(0, 0, 400, 400); smooth(); //Sun and moving "glow" effects simulated by three lower opacity ellipses changing in size, alternating between vertically and horizontally, around the 100% opacity center ellipse. ellipseMode(CENTER); noStroke(); fill(255, 240, 85, 30); ellipse(280, 60, 110*sin(frameCount*0.01), 110*sin(frameCount*0.01)); ellipse(280, 60, 110*sin(frameCount*0.015), 110*sin(frameCount*0.012)); ellipse(280, 60, 110*sin(frameCount*0.02), 110*sin(frameCount*0.02)); ellipseMode(CORNERS); fill(255, 230, 80); ellipse(245, 25, 315, 95); //Clouds, which move along X to simulate the bird's flight speed. noStroke(); fill(255, 255, 255, 30); ellipseMode(CENTER); ellipse(cloudX-300, cloudY+80, 100, 50); ellipse(cloudX2, cloudY2-60, 100, 50); ellipse(cloudX3-100, cloudY3-20, 200, 100); cloudX += speedX2; cloudX2 += speedX2; cloudX3 += speedX2; //Flies, which move along X, faster than the clouds to simulate depth as well as the bird's flight speed. fill(0, 0, 0); ellipse(flyX+90, flyY, 3, 3); //This creates the moving "wings" effect simulated by a rapidly expanding and retracting, low opacity, grey ellipse. fill(0, 0, 0, 30); ellipse(flyX+90, flyY, 10*sin(frameCount*0.4), 10*sin(frameCount*0.6)); flyX += speedX; //This places the bird above the background images. drawBird(); //This causes the "flapping" wings to appear on mouse click, simulating the bird's alternation between flapping for lift, and gliding down. if (mousePressed) { drawWingup(); } if (mousePressed) { drawWingdown(); } //This resets the clouds every time they float off screen on X. if (cloudX>800) { resetcloud(); } if (cloudX2>500) { resetcloud2(); } if (cloudX3>700) { resetcloud3(); } //This resets the flies every time they go off screen on X. if (flyX>width) { resetfly(); } //This causes the bird to lift every time the mouse is pressed. if (mousePressed) { birdY= birdY+thrust; } else { birdY = birdY + gravity; //This sets the bird's falling rate, and restrains the bird from continuing to fall off screen. if (birdY > 500) { gravity = 0; } else gravity = 5; } //This creates the text "gulp" every time the bird catches a fly. if (flyY<birdY+25 && flyY>birdY-10 && flyX>200 && flyX<250) { resetfly(); //speedX = 0; println("*gulp*"); } //This causes the fly to immediately reset on collision with the bird. if (flyY<birdY+25 && flyY>birdY-10 && flyX>200 && flyX<250) { flyX = -110; flyY = random(400); } } //These are the functions that reset the clouds and flies. void resetfly() { flyX =-110; flyY =random(400); } void resetcloud() { cloudX = -110; cloudY = random(300); } void resetcloud2() { cloudX2 = -110; cloudY2 = random(300); } void resetcloud3() { cloudX3 = -110; cloudY3 = random(300); } //The end, gg.