class Flying { PVector loc; PVector vel; PVector oscil; int counter; float theta; Flying() { loc = new PVector(width/2,height/10); vel = new PVector(2.5,0); } void render() { if (counter == 2 && loc.x >= width/4 && loc.x <= (width/2)) { image(birdDiveL,loc.x,loc.y); } if (counter == 2 && loc.x >= width/2 && loc.x <= (width/4)*3) { image(birdDiveR,loc.x,loc.y); } if (counter != 2 && vel.x >= 0) { image(birdFlyL,loc.x,loc.y); } if (counter != 2 && vel.x < 0) { image(birdFlyR,loc.x,loc.y); } if (counter == 2 && loc.x <= width/4 ) { image(birdFlyL,loc.x,loc.y); } if (counter == 2 && loc.x > (width/4)*3) { image(birdFlyL,loc.x,loc.y); } image(water,0,height-40); } void fly() { float test = (sin(theta)); theta += 0.05; oscil = new PVector(0,test); // Constrain ---------------------------------- if ((loc.x > width+100) || (loc.x < -100)) { vel.x = vel.x * -1; counter = counter + 1; } if ((loc.y > height) || (loc.y < 10)) { vel.y = vel.y * - 1; } if (loc.y < 20) { loc.y = loc.y + 10; vel.y = 0; } // Dive -------------------------------------- if (counter == 2 && loc.x >= width/4 && loc.x <= width/2) { vel.y = 20; } if (counter == 2 && loc.x >= width/2) { vel.y = -20; } if (counter == 2 && loc.x >= (width/4)*3) { vel.y = 0; } if (counter == 5) { counter = 1; } // ------------------------------------------- loc.add(vel); loc.add(oscil); } }