Advertisement
MrsMcLead

Untitled

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