質問編集履歴
2
実行結果の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -49,6 +49,9 @@
|
|
49
49
|
FPSCLOCK.tick(30)
|
50
50
|
コード
|
51
51
|
```
|
52
|
+
line 45, in <module>
|
53
|
+
ball.move()
|
54
|
+
line 32, in move
|
52
55
|
self.rect.centerx += math.cos(math.radians(dir))*speed
|
53
56
|
UnboundLocalError: local variable 'dir' referenced before assignment
|
54
|
-
直しました。
|
57
|
+
直しました。がエラーメッセージです
|
1
実行結果の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,14 +16,14 @@
|
|
16
16
|
class Ball:
|
17
17
|
def __init__(self, color, rect):
|
18
18
|
self.color = color
|
19
|
-
self.rect = rect
|
19
|
+
self.rect = rect
|
20
|
-
|
20
|
+
self.dir = 320
|
21
21
|
def draw(self):
|
22
22
|
pygame.draw.ellipse(SURFACE, self.color, self.rect)
|
23
23
|
|
24
24
|
def move(self):
|
25
25
|
speed = 10
|
26
|
-
|
26
|
+
|
27
27
|
if rect.centerx < 0 or rect.centerx > 400:
|
28
28
|
dir = 180-dir
|
29
29
|
if rect.centery < 0 or rect.centery > 300:
|
@@ -48,4 +48,7 @@
|
|
48
48
|
|
49
49
|
FPSCLOCK.tick(30)
|
50
50
|
コード
|
51
|
-
```
|
51
|
+
```
|
52
|
+
self.rect.centerx += math.cos(math.radians(dir))*speed
|
53
|
+
UnboundLocalError: local variable 'dir' referenced before assignment
|
54
|
+
直しました。
|