Advertisement
MrsMcLead

Diskette

Feb 10th, 2016
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. PImage diskette;
  2. PGraphics magnet;
  3. float rot = 0.0;
  4. float x = 50;
  5. float y = 680;
  6. boolean jump = false;
  7. boolean up = false;
  8. int counter = 0;
  9.  
  10. ArrayList<Integer> platformX = new ArrayList<Integer>();
  11. ArrayList<Integer> platformY = new ArrayList<Integer>();
  12. ArrayList<Integer> platformWidth = new ArrayList<Integer>();
  13.  
  14. void setup()
  15. {
  16.  size(1024,864);
  17.  background(#EBEBEB);
  18.  diskette = loadImage("Diskette.png");
  19.  
  20.  //platform 1
  21.  platformX.add(150);
  22.  platformY.add(625);
  23.  platformWidth.add(100);
  24.  
  25.  //platform 2
  26.  platformX.add(250);
  27.  platformY.add(500);
  28.  platformWidth.add(250);
  29.  
  30.  magnet = createGraphics(50,20);
  31.   magnet.beginDraw();
  32.     magnet.background(200);
  33.     magnet.stroke(0);
  34.     magnet.fill(255,0,0);
  35.     magnet.rect(0,0,25,20);
  36.     magnet.fill(0,0,255);
  37.     magnet.rect(25,0,25,20);
  38.   magnet.endDraw();
  39.  
  40. }
  41.  
  42. void draw()
  43. {
  44.   background(#EBEBEB);
  45.  
  46.  
  47.   image(magnet, 800,200);
  48.   image(magnet, 600,400);
  49.   image(magnet, 400,600);
  50.   image(magnet, 300,450);
  51.  
  52.   fill(#CD5C5C);
  53.   rect(0,750,1023,114);
  54.   platforms();
  55.   updateDiskette();
  56.  
  57. }
  58. void platforms()
  59. {
  60.   for(int i = 0; i<platformX.size(); i++)
  61.   {
  62.    rect(platformX.get(i),platformY.get(i),platformWidth.get(i),40);
  63.   }
  64.  
  65. }
  66. void updateDiskette()
  67. {
  68.   if(jump)
  69.   {
  70.     if(up)
  71.     {
  72.       x+=1.5*(counter+5);
  73.       y-=3*counter*counter;
  74.       counter++;
  75.       if (counter==0)
  76.         {
  77.          up=false;
  78.         }
  79.     }
  80.     else //if(!onPlatform())
  81.     {
  82.       x+=1.5*(counter+5);
  83.       y+=3*counter*counter;
  84.       counter++;
  85.       if(counter==6)
  86.       {
  87.        jump = false;
  88.       }
  89.     }
  90.   }
  91.   // gravity();
  92.   image(diskette,x,y);  
  93. }
  94. void keyPressed()
  95. {
  96.  if (keyCode==RIGHT)
  97.  {
  98.    x+=4;
  99.  }
  100.  else if(keyCode==LEFT)
  101.  {
  102.   x-=4;
  103.  }
  104.  else if(key==' '&&!jump)
  105.  {
  106.   jump = true;
  107.   up = true;
  108.   counter = -5;
  109.  }
  110. }
  111.  
  112. // boolean onPlatform()
  113. // {
  114. //   for(int i = 0; i<platformX.size(); i++)
  115. //   {
  116. //     if((x-80)>platformX.get(i) && x<(platformX.get(i) + platformWidth.get(i))&&y>platformY.get(i)&&(y-80)<(platformY.get(i)+40));
  117. //     {
  118. //      y = platformY.get(i)-80;
  119. //      return true;
  120. //     }
  121. //   }
  122. //   return false;
  123. // }
  124. // void gravity()
  125. // {
  126. //  if(!onPlatform() && !jump && y < 680)
  127. //  {
  128. //   y++;
  129. //  }
  130. // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement