-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathball.py
More file actions
50 lines (40 loc) · 1.22 KB
/
ball.py
File metadata and controls
50 lines (40 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from turtle import Turtle
import sound
MOVE_SPEED = 4
class Ball(Turtle):
def __init__(self):
super().__init__()
self.playing = False
self.shape("circle")
self.color("cyan")
self.penup()
self.reset_position()
def move(self):
self.forward(MOVE_SPEED)
def bounce_from_brick(self):
self.setheading(-1 * self.heading() + 360)
if self.playing:
sound.play_bounce_sound()
def bounce_from_wall(self):
self.setheading(180 - self.heading())
if self.playing:
sound.play_bounce_sound()
def bounce_steep_from_paddle_right(self):
self.setheading(30)
if self.playing:
sound.play_bounce_sound()
def bounce_steep_from_paddle_left(self):
self.setheading(150)
if self.playing:
sound.play_bounce_sound()
def bounce_shallow_from_paddle_right(self):
self.setheading(60)
if self.playing:
sound.play_bounce_sound()
def bounce_shallow_from_paddle_left(self):
self.setheading(120)
if self.playing:
sound.play_bounce_sound()
def reset_position(self):
self.teleport(0, -253)
self.setheading(60)