-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnerting asteroids.py
More file actions
50 lines (48 loc) · 1.46 KB
/
Copy pathconnerting asteroids.py
File metadata and controls
50 lines (48 loc) · 1.46 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
import pgzrun
from random import randint
from time import time
WIDTH=800
HEIGHT=600
SATELLITES=[]
lines=[]
next_satellite=0
start_time=0
total_time=0
number_of_satellites=25
end_time=0
def create_satellites():
global start_time
for i in range(0,number_of_satellites):
satellite =Actor("new asteroid")
satellite.pos=randint(40,WIDTH-40), randint(40,HEIGHT-40)
SATELLITES.append(satellite)
start_time=time()
def draw():
global total_time
screen.blit('background',(0,0))
number=1
for satellite in SATELLITES:
screen.draw.text(str(number),(satellite.pos[0],satellite.pos[1]+20))
satellite.draw()
number=number+1
for line in lines:
screen.draw.line(line[0],line[1],(255,255,255))
if next_satellite<number_of_satellites:
total_time=time()-start_time
screen.draw.text(str(round(total_time,1)),(10,10),fontsize=30)
else:
screen.draw.text(str(round(total_time,1)),(10,10),fontsize=30)
def update():
pass
def on_mouse_down(pos):
global next_satellite,lines
if next_satellite<number_of_satellites:
if SATELLITES[next_satellite].collidepoint(pos):
if next_satellite:
lines.append((SATELLITES[next_satellite-1].pos,SATELLITES[next_satellite].pos))
next_satellite=next_satellite+1
else:
lines=[]
next_satellite=0
create_satellites()
pgzrun.go()