Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int k = (int) random( 50, 100);
- int [] xpunkty = new int[k];
- int [] ypunkty = new int[k];
- boolean [] zjedzone = new boolean[k];
- int a=50;
- int b=height/2;
- int radius = 30;
- int up = 0; //-1 down 0 state 1 up
- int left = 0; //-1 rigth state 1 left
- boolean isOpen = false;
- int y = 0;
- int licznik = 0;
- void setup() {
- size(500, 500);
- background(0);
- noStroke();
- ellipseMode(RADIUS);
- textSize(32);
- frameRate(60);
- for (int i=0; i<xpunkty.length; i++) {
- ypunkty[i] = (int)random(50, 500);
- xpunkty[i] = (int)random(50, 500);
- }
- }
- void draw() {
- background(0);
- text("punkty " + licznik, 10, 30);
- for (int i=0; i<xpunkty.length; i++) {
- fill(255);
- if (!zjedzone[i]) {
- ellipse(xpunkty[i], ypunkty[i], 5, 5);
- }
- if (dist(a, b, xpunkty[i], ypunkty[i])<radius) {
- if (!zjedzone[i]) {
- licznik++;
- zjedzone[i]= true;
- }
- isOpen = true;
- }
- if (isOpen) {
- //po dwoch sekunadach bo framerate 60
- y++;
- if (y>=1200) {
- isOpen=false;
- y = 0;
- }
- }
- }
- println(isOpen);
- a=a+left;
- b=b+up;
- pushMatrix();
- translate(a, b);
- if (!isOpen) {
- drawOpenPacman();
- } else {
- drawClosePacman();
- }
- popMatrix();
- }
- void drawOpenPacman() {
- fill(#F7F000);
- arc(0, 0, radius, radius, .51, 5.9);
- }
- void drawClosePacman() {
- fill(#F7F000);
- arc(0, 0, radius, radius, .2, 6.2);
- }
- void keyPressed() {
- if (key == CODED) {
- if (keyCode == LEFT) {
- up = 0;
- left=-1;
- } else if (keyCode == RIGHT) {
- up = 0;
- left=1;
- } else if (keyCode == UP) {
- left = 0;
- up=-1;
- } else if (keyCode == DOWN) {
- left = 0;
- up=1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement