SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int k = (int) random( 50, 100);
  2. int [] xpunkty =  new int[k];
  3. int [] ypunkty =  new int[k];
  4. boolean [] zjedzone = new boolean[k];
  5. int a=50;
  6. int b=height/2;
  7. int radius = 30;
  8. int up = 0; //-1 down 0 state 1 up
  9. int left = 0;  //-1 rigth state 1 left
  10. boolean isOpen = false;
  11. int y = 0;
  12. int licznik = 0;
  13. void setup() {
  14.   size(500, 500);
  15.   background(0);
  16.   noStroke();
  17.   ellipseMode(RADIUS);
  18.   textSize(32);
  19.   frameRate(60);
  20.  
  21.   for (int i=0; i<xpunkty.length; i++) {
  22.     ypunkty[i] = (int)random(50, 500);
  23.     xpunkty[i] = (int)random(50, 500);
  24.   }
  25. }
  26.  
  27. void draw() {
  28.   background(0);
  29.   text("punkty " + licznik, 10, 30);
  30.   for (int i=0; i<xpunkty.length; i++) {
  31.     fill(255);
  32.     if (!zjedzone[i]) {
  33.       ellipse(xpunkty[i], ypunkty[i], 5, 5);
  34.     }
  35.  
  36.     if (dist(a, b, xpunkty[i], ypunkty[i])<radius) {
  37.       if (!zjedzone[i]) {
  38.         licznik++;
  39.         zjedzone[i]= true;
  40.       }
  41.       isOpen = true;
  42.     }
  43.     if (isOpen) {
  44.       //po dwoch sekunadach bo framerate 60
  45.       y++;
  46.       if (y>=1200) {
  47.         isOpen=false;
  48.         y = 0;
  49.       }
  50.     }
  51.   }
  52.  
  53.   println(isOpen);
  54.  
  55.   a=a+left;
  56.   b=b+up;
  57.  
  58.   pushMatrix();
  59.   translate(a, b);
  60.   if (!isOpen) {
  61.     drawOpenPacman();
  62.   } else {
  63.     drawClosePacman();
  64.   }
  65.  
  66.   popMatrix();
  67. }
  68.  
  69. void drawOpenPacman() {
  70.   fill(#F7F000);
  71.   arc(0, 0, radius, radius, .51, 5.9);
  72. }
  73.  
  74. void drawClosePacman() {
  75.   fill(#F7F000);
  76.   arc(0, 0, radius, radius, .2, 6.2);
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. void keyPressed() {
  87.   if (key == CODED) {
  88.     if (keyCode == LEFT) {
  89.       up = 0;
  90.       left=-1;
  91.     } else if (keyCode == RIGHT) {  
  92.       up = 0;
  93.       left=1;
  94.     } else if (keyCode == UP) {
  95.       left = 0;
  96.       up=-1;
  97.     } else if (keyCode == DOWN) {
  98.       left = 0;
  99.       up=1;
  100.     }
  101.   }
  102. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top