-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (41 loc) · 1.47 KB
/
main.py
File metadata and controls
51 lines (41 loc) · 1.47 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
51
import pygame
import sys
from constants import WIDTH, HEIGHT
from simulationclass import Simulation
# Environment init
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
clock = pygame.time.Clock()
pygame.key.set_repeat(1, 3)
show = True # Flag to indicate whether the simulation will present the visual part or not
simulation = Simulation()
################################################################################
# Main loop
running = True
while running:
screen.fill((50, 120, 40))
# A faster loop to run AE faster when a visualization is off
while (not show):
simulation.run()
for event in pygame.event.get():
if event.type == pygame.KEYUP:
if event.key in [pygame.K_SPACE]:
show = not show
for event in pygame.event.get():
# Quit event
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYUP:
if event.key in [pygame.K_SPACE]:# Press Space to turn off the visual simulation
show = not show
# To make the simulation run faster, the visual part can be turned off, thus, the fps will no longer be limited
if show:
FPS = 100 # Frame updates per second
simulation.show(screen)
else: FPS = 10000000000000 # Unlimited FPS
pygame.display.update()
clock.tick(FPS)
################################################################################
# End
pygame.quit()
sys.exit()