Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int charX = 10;// catcher
- int plnx = 30;// dropper
- int plnSpeed = 2; // plane speed
- float fr1x, fr1y, fr2x, fr2y, fr3x, fr3y; // fruit location variables
- float fr1SpeedY, fr2SpeedY, fr3SpeedY, fr1SpeedX, fr2SpeedX, fr3SpeedX; // fruit speeds
- int fruitDropCounter; // a timer for the fruit drop
- float fruitDropRandomizer = random(50, 100); // a random number to make the drop more fun.
- boolean plndir, fr1gate, fr2gate, fr3gate; // booleans instead of ints for your gates.
- void setup() {
- size(900, 640);
- }
- void draw() {
- background(200);
- // move the plane ///////////////////
- if (plndir == false) {
- plnx += plnSpeed;
- } else {
- plnx -= plnSpeed;
- }
- if (plnx > width || plnx < 0) {
- plndir = !plndir; // this flops the boolean from true to false or false to true
- }
- fill(100);
- rect(plnx, 20, 30, 10); // draw "plane"
- // drop fruit /////////////////////////
- fruitDropCounter ++;
- if (fruitDropCounter > fruitDropRandomizer) { // if the timer is up
- fruitDropRandomizer = random(50, 100);
- fruitDropCounter = 0;
- if (fr1gate == false) { // if fruit 1 hasn't dropped then drop it
- fr1gate = true;
- fr1SpeedY = random(.5, 2); // set a random drop speed
- fr1x = plnx;
- fr1y = 20;
- fr1SpeedX = 0; // you could give it a little sideways movement here, based on the plane
- } else if (fr2gate == false) { // if fruit 1 has dropped then drop fruit 2
- fr2gate = true;
- fr2SpeedY = random(.5, 2); // set a random drop speed
- fr2x = plnx;
- fr2y = 20;
- fr2SpeedX = 0; // you could give it a little sideways movement here, based on the plane
- } else if (fr3gate == false) { // if fruit 1 has dropped and fruit 2 has dropped then drop fruit 3
- fr3gate = true;
- fr3SpeedY = random(.5, 2); // set a random drop speed
- fr3x = plnx;
- fr3y = 20;
- fr3SpeedX = 0; // you could give it a little sideways movement here, based on the plane
- }
- }
- // move fruit ////////////////////
- if ( fr1gate == true) { // checking the boolean to see if fruit 1 is dropping
- fill(255, 0, 0);
- fr1x += fr1SpeedX; // add the speedx to the x location of the fruit
- fr1y += fr1SpeedY; // add the speedY to the y location of the fruit
- ellipse(fr1x, fr1y, 10, 10); // draw the fruit
- if (fr1y > height) { // if it's off the bottom
- fr1gate = false; // turn the fruit gate off.
- }
- }
- if ( fr2gate == true) {
- fill(255, 255, 0);
- fr2x += fr2SpeedX;
- fr2y += fr2SpeedY;
- ellipse(fr2x, fr2y, 10, 10);
- if (fr2y > height) {
- fr2gate = false;
- }
- }
- if ( fr3gate == true) {
- fill(0, 255, 255);
- fr3x += fr2SpeedX;
- fr3y += fr2SpeedY;
- ellipse(fr3x, fr3y, 10, 10);
- if (fr3y > height) {
- fr3gate = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment