如何用圆形处理创建点评分系统?

时间:2018-05-30 02:22:00

标签: processing

所以目标是每次锤子或水桶掉落时都会添加一个黑色圆圈而不会撞到人,然后每次进入门内时再添加4个圆圈,当第一个圆圈被填满时它会进入第二行,直到整个屏幕被填满,然后重置。此外,当人被锤子或桶击中时,将出现整排红色圆圈。我不知道该怎么做,谢谢。

// all the variables I need for two tools
int hammerPos = 0; 
int hammerVel = 1; 
int hammerPending = 0;
int bucketPos = 0; 
int bucketVel = 2; 
int bucketPending = 0;

int mrPos;
int jump = 60;
boolean doorOpen = true;

long timeAt;    // the time at which the door was last opened or closed
long waitTime; // the time to wait (in total) until the door opens next

void setup() {
  size(512, 348);
  mrPos = width/8;
  frameRate(30);
  waitTime = int(random(3000, 8000));
}

void draw() {
  if (millis() > timeAt + waitTime) {  // calculation will tell me if current time (millis) has gone past the last time the door opened plus waitTime
    doorOpen = !doorOpen;
    timeAt = millis();                // reset last opening time to now
    waitTime = int(random(3000, 8000));// choose new waiting time
  }

  background(159, 172, 173);
  rectMode(CORNERS);
  ellipseMode(CORNERS);
  noStroke();

  house();
  mrg();
  hazard();
  score();
}

void hazard() { 
  fill(0);
  stroke(0);
  strokeWeight(6);
  line(128, hammerPos+10, 148, hammerPos-12);
  strokeWeight(4);
  line(125, hammerPos+13, 129, hammerPos+11);
  strokeWeight(8);
  line(115, hammerPos+5, 130, hammerPos+20);

  // draw bucket
  fill(0);
  noStroke();
  triangle(167, bucketPos-5, 187, bucketPos-12, 188, bucketPos+12);
  triangle(167, bucketPos-5, 187, bucketPos+12, 169, bucketPos+14);
  noFill();
  stroke(0);
  strokeWeight(4);
  ellipse(183, bucketPos-11, 195, bucketPos+10);

  if (bucketPos >height) {
    bucketPos=0;
  }

  if (hammerPos>height) {
    hammerPos=0;
  }


  if (hammerPos > 240 && hammerPos < 300 && mrPos == width/4) {
    mrPos = width/8;
  }
  if (bucketPos > 240 && bucketPos < 300 && mrPos == 3*width/8) {
    mrPos = width/8;
  }


  // animate all automatically moving objects.. first update pending then decide if there is a jump this frame
  hammerPending = hammerPending + hammerVel;
  bucketPending = bucketPending + bucketVel;
  if (hammerPending > jump) {
    hammerPos = hammerPos + hammerPending;
    hammerPending = 0;
  }
  if (bucketPending > jump) {
    bucketPos = bucketPos + bucketPending;
    bucketPending = 0;
  }
}


void score() {
  if (hammerPos>height) {
    ellipse(40, 40, 40, 40);
  }
}




//draw house
void house() {
  strokeWeight(20);
  stroke(0);
  line(402, 206, 490, 169);
  line(490, 169, 512, 179);
  strokeWeight(2);
  noFill();
  line(411, 213, 411, 305);
  rect(419, 210, 468, 295);

  if (doorOpen) {
    line(479, 206, 499, 199);
    line(499, 199, 499, 314);
    line(499, 314, 478, 302);
    fill(0);
    noStroke();
    triangle(476, 225, 493, 219, 493, 243);
    triangle(476, 225, 493, 243, 476, 240);

    ellipse(487, 255, 493, 263);
    arc(499, 255, 507, 262, 3*HALF_PI, HALF_PI, CHORD);
  } else {
    fill(0);
    noStroke();
    rect(432, 225, 453, 243, 2);
    ellipse(425, 255, 431, 263);
  }
}



// draw MrGW
void mrg() {
  noStroke();
  fill(0);
  ellipse(mrPos-13, 232, mrPos+17, 263);
  fill(159, 172, 173);
  ellipse(mrPos+3, 250, mrPos+17, 260);
  fill(0);
  triangle(mrPos+2, 258, mrPos-11, 278, mrPos+1, 285);
}

void keyPressed() {
  if (keyCode == RIGHT && (mrPos < 7*(width/8)) && doorOpen) { // mr gw is moving right and the door is open
    mrPos = mrPos + width/8;
  } else if (keyCode == RIGHT && (mrPos < 6*(width/8))) {      // mr gw is moving right not including last slot
    mrPos = mrPos + width/8;
  } else if (keyCode == LEFT && (mrPos > width/8)) {           // mr gw is moving left.
    mrPos = mrPos - width/8;
  }
}

1 个答案:

答案 0 :(得分:0)

基本上,您需要一个变量来表示点数/圈数:points。圆圈本身应该在空隙循环中绘制,可能有两个for循环(见下文)。

此外,您需要定义哪个圆圈应为红色。在下面的例子中,我使用一个布尔数组,它定义每个圆圈是否应该是红色。因此,如果第一个圆圈必须为红色,则必须将redPoint[0]设置为true ...

int i=0;
for(int y=10; y<height-10; y+=20) {
  for(int x=10; x<width-10; x+=20) {
    if(redPoint[i] == true) {
      fill(255,0,0);
    } else {
      fill(0);
    }
    if(i<points) {
      ellipse(x,y,15,15);
    }
    i++;
  }
}