teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

見直しキャンペーン中

2023/08/14 13:24

投稿

TN8001
TN8001

スコア10114

answer CHANGED
@@ -1,30 +1,30 @@
1
- そんなまどろっこしいことをするくらいなら、x,yをdoubleで持てばよくないですか?
1
+ そんなまどろっこしいことをするくらいなら、`x`・`y``double`で持てばよくないですか?
2
-
2
+
3
- ```Java
3
+ ```Java
4
- class Ball extends JPanel {
4
+ class Ball extends JPanel {
5
- double x = 0;
5
+ double x = 0;
6
- double y = 0;
6
+ double y = 0;
7
- double rad = Math.toRadians(18);
7
+ double rad = Math.toRadians(18);
8
-
8
+
9
- Ball() {
9
+ Ball() {
10
- setBounds((int) x, (int) y, 10, 10);
10
+ setBounds((int) x, (int) y, 10, 10);
11
- setBackground(Color.black);
11
+ setBackground(Color.black);
12
- }
12
+ }
13
-
13
+
14
- void go(int fx, int fy) {
14
+ void go(int fx, int fy) {
15
- if (fx <= x || fy <= y) {
15
+ if (fx <= x || fy <= y) {
16
- x = 0;
16
+ x = 0;
17
- y = 0;
17
+ y = 0;
18
- }
18
+ }
19
-
19
+
20
- x += Math.cos(rad);
20
+ x += Math.cos(rad);
21
- y += Math.sin(rad);
21
+ y += Math.sin(rad);
22
- setLocation((int) x, (int) y);
22
+ setLocation((int) x, (int) y);
23
- }
23
+ }
24
- }
24
+ }
25
- ```
25
+ ```
26
-
26
+
27
- ---
27
+ ---
28
-
28
+
29
- JavaでゲームならProcessingもおすすめです^^
29
+ JavaでゲームならProcessingもおすすめです^^
30
30
  [Welcome to Processing! / Processing.org](https://processing.org/)