/
game.py
71 lines (49 loc) · 1.5 KB
/
game.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
import meet
import random
user_cell_dictionary={"radius":30,"x":6,"y":6,"dy":1,"dx":1,"color":"yellow"}
cells=[]
x=0
while x<24:
x+=1
ball3={"radius":random.randint(3,10),"x":meet.get_random_x(),"y":meet.get_random_y(),"dy":1,"dx":1}
circle3 = meet.create_cell(ball3)
cells.append(circle3)
user_cell=meet.create_cell(user_cell_dictionary)
cells.append(user_cell)
def Edge(cells):
h=meet.get_screen_width()
w=meet.get_screen_height()
for cell in cells:
if cell.xcor() + cell.get_radius() >= h:
x=cell.get_dx()
cell.set_dx(-x)
elif cell.xcor() - cell.get_radius()<= -h:
x=cell.get_dx()
cell.set_dx(-x)
if cell.ycor() + cell.get_radius() >= w:
y=cell.get_dy()
cell.set_dy(-y)
elif cell.ycor() - cell.get_radius() <= -w:
y=cell.get_dy()
cell.set_dy(-y)
def collison():
for cell in cells:
for cell2 in cells:
if(((cell.xcor()-cell2.xcor())**2+(cell.ycor()-cell2.ycor())**2)**0.5 ) < cell.get_radius() + cell2.get_radius():
if (cell.get_radius() < cell2.get_radius()):
cell.goto(meet.get_random_x(),meet.get_random_y())
cell2.set_radius(cell2.get_radius()+1)
if cell==user_cell:
exit()
if (cell.get_radius() > cell2.get_radius()):
cell2.goto(meet.get_random_x(),meet.get_random_y())
cell.set_radius(cell.get_radius()+1)
if cell2==user_cell:
exit()
while (True):
direction = meet.get_user_direction(user_cell)
user_cell.set_dx(direction[0])
user_cell.set_dy(direction[1])
meet.move_cells(cells)
Edge(cells)
collison()