Browse Source

Initial commit

develop
Toromino 1 year ago
commit
905cb71d06
4 changed files with 141 additions and 0 deletions
  1. 3
    0
      README.md
  2. 41
    0
      __main__.py
  3. 52
    0
      objects.py
  4. 45
    0
      stage.py

+ 3
- 0
README.md View File

@@ -0,0 +1,3 @@
1
+# enso
2
+
3
+wip

+ 41
- 0
__main__.py View File

@@ -0,0 +1,41 @@
1
+from stage import Stage
2
+from objects import Circle
3
+
4
+import pygame
5
+import json
6
+import math
7
+
8
+if __name__ == '__main__':
9
+    pygame.init()
10
+    screen = pygame.display.set_mode((800, 600))
11
+    clock = pygame.time.Clock()
12
+    pygame.display.set_caption('Enso')
13
+
14
+    test_objects = [
15
+    Circle(time=1),
16
+    Circle(time=2, position=(400, 400), color=pygame.Color(0, 0, 255)),
17
+    Circle(time=3),
18
+    Circle(time=4, position=(400, 400), color=pygame.Color(0, 0, 255)),
19
+    Circle(time=5),
20
+    Circle(time=6, position=(400, 400), color=pygame.Color(0, 0, 255)),
21
+    Circle(time=7)
22
+    ]
23
+
24
+    test_stage = Stage(screen, test_objects, 'chocolate.mp3')
25
+
26
+    thread_running = True
27
+
28
+    while thread_running:
29
+
30
+        screen.fill(pygame.Color(255, 255, 255))
31
+
32
+        test_stage.handle_events()
33
+        test_stage.update()
34
+        test_stage.draw()
35
+
36
+        for event in pygame.event.get():
37
+            if event.type == pygame.QUIT:
38
+                thread_running = False
39
+
40
+        pygame.display.update()
41
+        clock.tick(60)

+ 52
- 0
objects.py View File

@@ -0,0 +1,52 @@
1
+import math
2
+import pygame
3
+
4
+class Circle(object):
5
+
6
+    def __init__ (self, size=50, position=(200, 200), time=0, color=pygame.Color(255, 0, 150)):
7
+        self.size = size
8
+        self.position = position
9
+        self.startTime = time
10
+        self.color = color
11
+
12
+        self.appeared = False
13
+        self.completed = False
14
+        self.approachCircleSize = self.size * 1.5
15
+
16
+    def click(self):
17
+        if self.appeared:
18
+            if (self.size / self.approachCircleSize) >= 0.85:
19
+                return 300
20
+            elif (self.size / self.approachCircleSize) >= 0.75:
21
+                return 100
22
+            elif (self.size / self.approachCircleSize) >= 0.5:
23
+                return 50
24
+            else:
25
+                return 0
26
+
27
+            self.completed = True
28
+            self.appeared = False
29
+
30
+    def update(self, start_time):
31
+        if self.appeared:
32
+            if self.approachCircleSize > self.size:
33
+                self.approachCircleSize -= 0.5
34
+            else:
35
+                self.completed = True
36
+                self.appeared = False
37
+        elif not self.completed:
38
+            if ((pygame.time.get_ticks() - start_time)/1000) > self.startTime:
39
+                self.appeared = True
40
+
41
+    def draw(self, screen, circleNumber):
42
+        if self.appeared:
43
+            # Circle
44
+            pygame.draw.circle(screen, self.color, self.position, self.size)
45
+
46
+            # Approach Circle
47
+            pygame.draw.circle(screen, pygame.Color(0, 0, 0), self.position, math.floor(self.approachCircleSize), 1)
48
+
49
+            # Number
50
+            font = pygame.font.SysFont("comicsansms", 72)
51
+            text = font.render(str(circleNumber), True, (0, 0, 128))
52
+            screen.blit(text, (self.position[0] - text.get_width() // 2, self.position[1] - text.get_height() // 2))

+ 45
- 0
stage.py View File

@@ -0,0 +1,45 @@
1
+import math
2
+import pygame
3
+
4
+class Stage(object):
5
+
6
+    def __init__(self, screen=None, objects=[], audio_file=''):
7
+        self.screen = screen
8
+        self.objects = objects
9
+        self.audio_file = audio_file
10
+        self.start_time = pygame.time.get_ticks()
11
+
12
+        try:
13
+            pygame.mixer.music.load(self.audio_file)
14
+            pygame.mixer.music.set_volume(0.2) # TODO: Add global volume control
15
+            pygame.mixer.music.play()
16
+        except:
17
+            print("Couldn't find audio file")
18
+
19
+    def update(self):
20
+
21
+        for o in self.objects:
22
+            o.update(self.start_time)
23
+
24
+    def draw(self):
25
+
26
+        for o in self.objects:
27
+            o.draw(self.screen, self.objects.index(o) + 1)
28
+
29
+        # TODO: Show time instead of ticks
30
+        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))
32
+        self.screen.blit(text, (90 - text.get_width() // 2, 30 - text.get_height() // 2))
33
+
34
+    def handle_events(self):
35
+
36
+        for event in pygame.event.get():
37
+            if event.type == pygame.MOUSEBUTTONDOWN:
38
+
39
+                for o in self.objects:
40
+                    mouse_x = pygame.mouse.get_pos()[0]
41
+                    mouse_y = pygame.mouse.get_pos()[1]
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())

Loading…
Cancel
Save