class Flying { PVector loc; PVector vel; PVector rand; int counter; float theta; Flying() { loc = new PVector(width/2,height/10); vel = new PVector(2.5,0); } void render() { stroke(255); fill(100); rectMode(CENTER); rect(loc.x,loc.y,40,40); } void fly() { float test = (sin(theta)); theta += 0.05; println(test); rand = new PVector(0,test); // Constrain ---------------------------------- if ((loc.x > width+60) || (loc.x < -60)) { 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(rand); } }