-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathball.py
More file actions
37 lines (32 loc) · 854 Bytes
/
ball.py
File metadata and controls
37 lines (32 loc) · 854 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
from random import choice
class Ball(Turtle):
def __init__(self):
super().__init__()
self.shape('circle')
self.color('white')
self.penup()
# self.sign=choice([True, False])
self.x_move=10
self.y_move=10
def move(self):
new_x=self.xcor()+self.x_move
new_y = self.ycor()+self.y_move
self.goto(new_x,new_y)
def bounce(self):
self.y_move *= -1
# # YOU CAN DO THIS TO DETECT COLLISION TOO
# def move(self):
# x_cor=self.xcor()+10
# y_cor = self.ycor()
#
# if y_cor>=280:
# self.sign=True
# elif y_cor<= -280:
# self.sign=False
# if self.sign==True:
# y_cor-=10
# else:
# y_cor+=10
#
# self.goto(x_cor,y_cor)