-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathball.py
More file actions
37 lines (29 loc) · 879 Bytes
/
ball.py
File metadata and controls
37 lines (29 loc) · 879 Bytes
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
from turtle import Turtle,Screen
screen = Screen()
class Ball(Turtle):
def __init__(self):
super().__init__()
self.color("white")
self.penup()
self.speed(0)
self.shape("circle")
self.x_mov = 10
self.y_mov = 10
self.ball_speed = 0.1
def move(self):
new_x = self.xcor() + self.x_mov
new_y = self.ycor() + self.y_mov
self.goto(new_x, new_y)
def bounce(self):
self.y_mov *= -1
def bounce_back(self):
self.x_mov *= -1
def detect_coli_wall(self):
if self.xcor() > 650 or self.xcor() < -650 or self.ycor() > 360 or self.ycor() < -300:
return True
def reset(self):
self.goto(0, 0)
self.bounce_back()
self.bounce()
def speed_up(self):
self.ball_speed *= 0.09