回答編集履歴

2

例えばこんな?

2022/05/22 11:06

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -4,6 +4,7 @@
4
4
  ```Processing
5
5
  int N = 2;
6
6
  Ball[] b;
7
+ int fc;
7
8
 
8
9
  void setup() {
9
10
  size(800, 800);
@@ -17,18 +18,24 @@
17
18
  background(255);
18
19
 
19
20
  boolean allClicked = true;
21
+ boolean allHits = true;
20
22
  for (int i = 0; i < b.length; i++) {
21
23
  b[i].move();
22
24
  b[i].display();
23
25
  b[i].judgeClicked();
24
- //b[i].Goal();
25
26
  allClicked = allClicked && b[i].isClicked;
27
+ allHits = allHits && b[i].isHit();
26
28
  }
27
29
 
28
- if (allClicked) {
30
+ if (!allClicked) {
31
+ fc = frameCount;
32
+ }
29
- fill(0);
33
+ fill(0);
30
- textAlign(CENTER);
34
+ textAlign(CENTER);
31
- textSize(40);
35
+ textSize(40);
36
+ text("" + fc, 40, 40, 200, 200);
37
+
38
+ if (allHits) {
32
39
  text("goal", 400, 400, 200, 200);
33
40
  }
34
41
  }
@@ -37,40 +44,37 @@
37
44
  int size = 50;
38
45
  float x = int(random(size / 2, width - size / 2));
39
46
  float y = int(random(size / 2, height - size / 2));
40
- //float a = int(random(size / 2, width - size / 2));
41
- //float b = int(random(size / 2, height - size / 2));
42
-
43
47
  boolean isClicked;
48
+ color c = color(255);
44
49
 
45
50
  void display() {
46
- if (!isClicked) {
51
+ if (isClicked) return;
52
+
47
- fill(255);
53
+ fill(c);
48
- ellipse(x, y, size, size);
54
+ ellipse(x, y, size, size);
49
- }
50
55
  }
51
56
 
52
57
  void move() {
58
+ if (isClicked) return;
59
+
53
60
  x = lerp(x, width / 2, 0.01);
54
61
  y = lerp(y, height / 2, 0.01);
55
62
 
56
63
  if (abs(x - width / 2) < 20 && abs(y - width / 2) < 20) {
57
- size = 0;
64
+ c = color(255, 0, 0);
58
65
  }
59
66
  }
60
67
 
61
- //void Goal() {
62
- // if (isClicked) {
68
+ void judgeClicked() {
63
- // fill(0);
69
+ if (isClicked) return;
64
- // textAlign(CENTER);
65
- // textSize(40);
66
- // text("goal", 400, 400, 200, 200);
67
- // }
68
- //}
69
70
 
70
- void judgeClicked() {
71
71
  if (dist(x, y, mouseX, mouseY) < size / 2 && mousePressed) {
72
72
  isClicked = true;
73
73
  }
74
74
  }
75
+
76
+ boolean isHit() {
77
+ return isClicked && c == color(255);
78
+ }
75
79
  }
76
80
  ```

1

クリックできるエリア制限?

2022/05/22 09:44

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -52,6 +52,10 @@
52
52
  void move() {
53
53
  x = lerp(x, width / 2, 0.01);
54
54
  y = lerp(y, height / 2, 0.01);
55
+
56
+ if (abs(x - width / 2) < 20 && abs(y - width / 2) < 20) {
57
+ size = 0;
58
+ }
55
59
  }
56
60
 
57
61
  //void Goal() {
@@ -64,7 +68,7 @@
64
68
  //}
65
69
 
66
70
  void judgeClicked() {
67
- if (dist(x, y, mouseX, mouseY) <= size / 2 && mousePressed) {
71
+ if (dist(x, y, mouseX, mouseY) < size / 2 && mousePressed) {
68
72
  isClicked = true;
69
73
  }
70
74
  }