-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_screen.py
77 lines (56 loc) · 2.22 KB
/
show_screen.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
76
import pygame
import planet
class Screen:
black = [0, 0, 0]
white = [255, 255, 255]
xmax = 1000
ymax = 700
def __init__(self): # truc qui va etre apellé a la création de tout objet affichage
pygame.init()
pygame.display.set_caption("Systeme solaire")
taille = [Screen.xmax, Screen.ymax]
self.screen = pygame.display.set_mode(taille)
self.clock = pygame.time.Clock()
def effacer(self):
self.screen.fill(Screen.black)
def actualiser(self):
pygame.display.flip()
self.clock.tick(80)
def evenement(self, listePlanetes):
# récupere la valeur des frottements
file = open("frottements.txt")
chaine = ""
for line in file:
chaine += line
if chaine == '0.99':
chaine = 0.99
elif chaine == '1.0':
chaine == 1.0
frottements = float(chaine)
for event in pygame.event.get(): # permet de savoir si on veut sortir du programme(accessoirement sans ca, sa plante)
if event.type == pygame.QUIT:
return True
pos = pygame.mouse.get_pos()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_b:
p = planet.Planete(pos[0], pos[1], 0, 0, 800)
listePlanetes.append(p)
elif event.key == pygame.K_c:
p = planet.Planete(pos[0], pos[1], 0, 0, 3000)
listePlanetes.append(p)
elif event.key == pygame.K_f:
if frottements == 1.0:
frottements = 0.99
else:
frottements = 1.0
mon_fichier = open("frottements.txt", "w")
frottements = str(frottements)
mon_fichier.write(frottements)
mon_fichier.close()
elif event.type == pygame.MOUSEBUTTONDOWN:
p = planet.Planete(pos[0], pos[1], 8, 0, 20)
listePlanetes.append(p)
return False
def affichePoint(self, x, y, m):
red = max(0, 255 - int(m / 5))
pygame.draw.circle(self.screen, [red, 255, 255], [x, y], 5 + int(m / 100))