-
Notifications
You must be signed in to change notification settings - Fork 0
/
ball.py
75 lines (58 loc) · 1.45 KB
/
ball.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from turtle import *
import random
import math
import time
#tracer(0)
# hideturtle()
class Ball(Turtle):
def __init__(self,x,y,dx,dy,radius,color):
Turtle.__init__(self)
self.pu()
self.goto(x,y)
self.dx = dx
self.dy = dy
self.shape("circle")
self.radius=radius
self.shapesize(radius/10)
self.color(color)
def top(self):
return self.ycor()+self.radius/2
def bottom(self):
return self.ycor()-self.radius/2
def right(self):
return self.xcor()+self.radius/2
def left(self):
return self.xcor()-self.radius/2
def move(self,screen_width,screen_height):
current_x=self.xcor()
current_y=self.ycor()
new_x=current_x+self.dx
new_y=current_y+self.dy
right_side_ball=new_x+self.radius
left_side_ball=new_x-self.radius
top_side_ball=new_y+self.radius
bottom_side_ball=new_y-self.radius
right_edge=screen_width
left_edge=-screen_width
top_edge=screen_height
bottom_edge=-screen_height
self.goto(new_x,new_y)
if right_side_ball> right_edge:
self.dx=- self.dx
elif left_side_ball<left_edge:
self.dx = -self.dx
elif top_side_ball>top_edge:
print("top")
self.dy= - self.dy
elif bottom_side_ball<bottom_edge:
<<<<<<< HEAD
=======
print("game over")
>>>>>>> c0fa3192c7b0cd2f1a8b3b4f7c9420cfbec5694b
write("GAME OVER",True,align="center",font=("Arial",25,"normal"))
time.sleep(5)
exit()
#ball_1=Ball(0,0,5,10,30,"blue")
#for i in range(50):
#ball_1.move(200,200)
#getscreen().update()