Browse Source

Fix quit event, change clock to display seconds instead of ticks

develop
Toromino 1 year ago
parent
commit
ece85827fb
2 changed files with 17 additions and 16 deletions
  1. 5
    4
      __main__.py
  2. 12
    12
      stage.py

+ 5
- 4
__main__.py View File

@@ -29,13 +29,14 @@ if __name__ == '__main__':
29 29
 
30 30
         screen.fill(pygame.Color(255, 255, 255))
31 31
 
32
-        test_stage.handle_events()
33
-        test_stage.update()
34
-        test_stage.draw()
35
-
36 32
         for event in pygame.event.get():
37 33
             if event.type == pygame.QUIT:
38 34
                 thread_running = False
35
+            else:
36
+                test_stage.handle_events(event)
37
+
38
+        test_stage.update()
39
+        test_stage.draw()
39 40
 
40 41
         pygame.display.update()
41 42
         clock.tick(60)

+ 12
- 12
stage.py View File

@@ -8,6 +8,7 @@ class Stage(object):
8 8
         self.objects = objects
9 9
         self.audio_file = audio_file
10 10
         self.start_time = pygame.time.get_ticks()
11
+        self.time = None
11 12
 
12 13
         try:
13 14
             pygame.mixer.music.load(self.audio_file)
@@ -21,25 +22,24 @@ class Stage(object):
21 22
         for o in self.objects:
22 23
             o.update(self.start_time)
23 24
 
25
+        self.time = pygame.time.get_ticks() - self.start_time/1000
26
+
24 27
     def draw(self):
25 28
 
26 29
         for o in self.objects:
27 30
             o.draw(self.screen, self.objects.index(o) + 1)
28 31
 
29
-        # TODO: Show time instead of ticks
30 32
         font = pygame.font.SysFont("comicsansms", 72)
31
-        text = font.render(str(math.floor(pygame.time.get_ticks() - self.start_time/1000)), True, (0, 0, 0))
33
+        text = font.render(str(math.floor(self.time / 1000)), True, (0, 0, 0))
32 34
         self.screen.blit(text, (90 - text.get_width() // 2, 30 - text.get_height() // 2))
33 35
 
34
-    def handle_events(self):
35
-
36
-        for event in pygame.event.get():
37
-            if event.type == pygame.MOUSEBUTTONDOWN:
36
+    def handle_events(self, event):
37
+        if event.type == pygame.MOUSEBUTTONDOWN:
38 38
 
39
-                for o in self.objects:
40
-                    mouse_x = pygame.mouse.get_pos()[0]
41
-                    mouse_y = pygame.mouse.get_pos()[1]
39
+            for o in self.objects:
40
+                mouse_x = pygame.mouse.get_pos()[0]
41
+                mouse_y = pygame.mouse.get_pos()[1]
42 42
 
43
-                    if o.appeared and o.completed == False:
44
-                        if math.sqrt((mouse_x - o.size)**2 + (mouse_y - o.size)**2):
45
-                            print(o.click())
43
+                if o.appeared and o.completed == False:
44
+                    if math.sqrt((mouse_x - o.size)**2 + (mouse_y - o.size)**2):
45
+                        print(o.click())

Loading…
Cancel
Save