joemckay

plane drop

Jan 27th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. int charX = 10;// catcher
  2. int plnx = 30;// dropper
  3. int plnSpeed = 2; // plane speed
  4. float fr1x, fr1y, fr2x, fr2y, fr3x, fr3y; // fruit location variables
  5. float fr1SpeedY, fr2SpeedY, fr3SpeedY, fr1SpeedX, fr2SpeedX, fr3SpeedX; // fruit speeds
  6. int fruitDropCounter; // a timer for the fruit drop
  7. float fruitDropRandomizer = random(50, 100); // a random number to make the drop more fun.
  8. boolean plndir, fr1gate, fr2gate, fr3gate; // booleans instead of ints for your gates.
  9.  
  10. void setup() {
  11. size(900, 640);
  12. }
  13. void draw() {
  14. background(200);
  15. // move the plane ///////////////////
  16. if (plndir == false) {
  17. plnx += plnSpeed;
  18. } else {
  19. plnx -= plnSpeed;
  20. }
  21. if (plnx > width || plnx < 0) {
  22. plndir = !plndir; // this flops the boolean from true to false or false to true
  23. }
  24. fill(100);
  25. rect(plnx, 20, 30, 10); // draw "plane"
  26.  
  27. // drop fruit /////////////////////////
  28. fruitDropCounter ++;
  29. if (fruitDropCounter > fruitDropRandomizer) { // if the timer is up
  30. fruitDropRandomizer = random(50, 100);
  31. fruitDropCounter = 0;
  32. if (fr1gate == false) { // if fruit 1 hasn't dropped then drop it
  33. fr1gate = true;
  34. fr1SpeedY = random(.5, 2); // set a random drop speed
  35. fr1x = plnx;
  36. fr1y = 20;
  37. fr1SpeedX = 0; // you could give it a little sideways movement here, based on the plane
  38. } else if (fr2gate == false) { // if fruit 1 has dropped then drop fruit 2
  39. fr2gate = true;
  40. fr2SpeedY = random(.5, 2); // set a random drop speed
  41. fr2x = plnx;
  42. fr2y = 20;
  43. fr2SpeedX = 0; // you could give it a little sideways movement here, based on the plane
  44. } else if (fr3gate == false) { // if fruit 1 has dropped and fruit 2 has dropped then drop fruit 3
  45. fr3gate = true;
  46. fr3SpeedY = random(.5, 2); // set a random drop speed
  47. fr3x = plnx;
  48. fr3y = 20;
  49. fr3SpeedX = 0; // you could give it a little sideways movement here, based on the plane
  50. }
  51. }
  52. // move fruit ////////////////////
  53. if ( fr1gate == true) { // checking the boolean to see if fruit 1 is dropping
  54. fill(255, 0, 0);
  55. fr1x += fr1SpeedX; // add the speedx to the x location of the fruit
  56. fr1y += fr1SpeedY; // add the speedY to the y location of the fruit
  57. ellipse(fr1x, fr1y, 10, 10); // draw the fruit
  58. if (fr1y > height) { // if it's off the bottom
  59. fr1gate = false; // turn the fruit gate off.
  60. }
  61. }
  62. if ( fr2gate == true) {
  63. fill(255, 255, 0);
  64. fr2x += fr2SpeedX;
  65. fr2y += fr2SpeedY;
  66. ellipse(fr2x, fr2y, 10, 10);
  67. if (fr2y > height) {
  68. fr2gate = false;
  69. }
  70. }
  71.  
  72. if ( fr3gate == true) {
  73. fill(0, 255, 255);
  74. fr3x += fr2SpeedX;
  75. fr3y += fr2SpeedY;
  76. ellipse(fr3x, fr3y, 10, 10);
  77. if (fr3y > height) {
  78. fr3gate = false;
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment