回答編集履歴

1

見直しキャンペーン中

2023/08/14 13:24

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -1,59 +1,30 @@
1
- そんなまどろっこしいことをするくらいなら、x,yをdoubleで持てばよくないですか?
1
+ そんなまどろっこしいことをするくらいなら、`x`・`y``double`で持てばよくないですか?
2
-
3
-
4
2
 
5
3
  ```Java
6
-
7
4
  class Ball extends JPanel {
8
-
9
5
  double x = 0;
10
-
11
6
  double y = 0;
12
-
13
7
  double rad = Math.toRadians(18);
14
8
 
15
-
16
-
17
9
  Ball() {
18
-
19
10
  setBounds((int) x, (int) y, 10, 10);
20
-
21
11
  setBackground(Color.black);
22
-
23
12
  }
24
13
 
25
-
26
-
27
14
  void go(int fx, int fy) {
28
-
29
15
  if (fx <= x || fy <= y) {
30
-
31
16
  x = 0;
32
-
33
17
  y = 0;
34
-
35
18
  }
36
19
 
37
-
38
-
39
20
  x += Math.cos(rad);
40
-
41
21
  y += Math.sin(rad);
42
-
43
22
  setLocation((int) x, (int) y);
44
-
45
23
  }
46
-
47
24
  }
48
-
49
25
  ```
50
-
51
-
52
26
 
53
27
  ---
54
28
 
55
-
56
-
57
29
  JavaでゲームならProcessingもおすすめです^^
58
-
59
30
  [Welcome to Processing! / Processing.org](https://processing.org/)