Browse Source

randomization for manager

Thomas Buck 1 year ago
parent
commit
2779ddad94
2 changed files with 55 additions and 22 deletions
  1. 30
    18
      livingroom.py
  2. 25
    4
      manager.py

+ 30
- 18
livingroom.py View File

@@ -9,6 +9,7 @@
9 9
 
10 10
 camp_pink = (251, 72, 196)
11 11
 camp_green = (63, 255, 33)
12
+pause = 2.0
12 13
 
13 14
 from splash import SplashScreen
14 15
 from scroll import ScrollText
@@ -22,7 +23,6 @@ from gamepad import InputWrapper
22 23
 from manager import Manager
23 24
 from tetris import Tetris
24 25
 from breakout import Breakout
25
-from weather import WeatherScreen
26 26
 from config import Config
27 27
 import util
28 28
 
@@ -37,31 +37,43 @@ t.loop_start()
37 37
 splash.draw()
38 38
 t.loop_end()
39 39
 
40
-m = Manager(t, i)
40
+m = Manager(t, i, 2, True)
41 41
 
42
-m.add(ImageScreen(t, "cann.png"))
43
-m.add(Solid(t, 1.0))
44
-
45
-m.add(WeatherScreen(t, i, Config.weather_latlon))
46
-m.add(Solid(t, 1.0))
42
+if not util.isPi():
43
+    # TODO weather does not run on Pi yet unfortunately :(
44
+    from weather import WeatherScreen
45
+    m.add(WeatherScreen(t, i, Config.weather_latlon))
46
+    m.add(Solid(t, pause))
47 47
 
48 48
 m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), None, 2.0))
49
-m.add(Solid(t, 1.0))
49
+m.add(Solid(t, pause))
50
+
51
+m.add(ImageScreen(t, "32_earth.gif", 0.2, 2))
52
+m.add(Solid(t, pause))
53
+
54
+m.add(ImageScreen(t, "cann.png", 0.2, 1, 10.0))
55
+m.add(Solid(t, pause))
56
+
57
+m.add(ImageScreen(t, "cann2.png", 0.2, 1, 10.0))
58
+m.add(Solid(t, pause))
59
+
60
+m.add(ImageScreen(t, "64_cloud.gif", 0.2, 1, 5.0, (0, 0, 0)))
61
+m.add(Solid(t, pause))
50 62
 
51
-m.add(ImageScreen(t, "cann2.png"))
52
-m.add(Solid(t, 1.0))
63
+m.add(ImageScreen(t, "64_sephiroth.gif", 0.2, 4, 5.0, (0, 0, 0)))
64
+m.add(Solid(t, pause))
53 65
 
54
-m.add(ImageScreen(t, "earth.gif"))
55
-m.add(Solid(t, 1.0))
66
+m.add(ImageScreen(t, "64_nlogospin.gif", 0.2, 2))
67
+m.add(Solid(t, pause))
56 68
 
57
-#m.add(Breakout(t, i))
58
-#m.add(Solid(t, 1.0))
69
+m.add(Breakout(t, i))
70
+m.add(Solid(t, pause))
59 71
 
60
-#m.add(Tetris(t, i,))
61
-#m.add(Solid(t, 1.0))
72
+m.add(Tetris(t, i,))
73
+m.add(Solid(t, pause))
62 74
 
63
-#m.add(Snake(t, i, camp_pink, camp_green))
64
-#m.add(Solid(t, 1.0))
75
+m.add(Snake(t, i, camp_pink, camp_green))
76
+m.add(Solid(t, pause))
65 77
 
66 78
 m.restart()
67 79
 util.loop(t, m.draw)

+ 25
- 4
manager.py View File

@@ -8,17 +8,27 @@
8 8
 # ----------------------------------------------------------------------------
9 9
 
10 10
 import time
11
+import random
11 12
 
12 13
 class Manager:
13
-    def __init__(self, g, i = None, ss = 2):
14
+    def __init__(self, g, i = None, ss = 2, randomize = False):
14 15
         self.gui = g
15 16
         self.input = i
16 17
         self.step_size = ss
18
+        self.randomize = randomize
17 19
         self.screens = []
20
+
21
+        if self.randomize:
22
+            random.seed()
23
+
18 24
         self.restart()
19 25
 
20 26
     def restart(self):
21
-        self.index = 0
27
+        if self.randomize and (len(self.screens) > 0):
28
+            self.index = int(random.randrange(0, len(self.screens) / self.step_size) * self.step_size)
29
+        else:
30
+            self.index = 0
31
+
22 32
         self.done = False
23 33
         self.lastTime = time.time()
24 34
         self.old_keys = {
@@ -65,8 +75,19 @@ class Manager:
65 75
         self.lastTime = time.time()
66 76
 
67 77
         if update_flag:
68
-            # go through all for normal operation
69
-            self.index = (self.index + i) % len(self.screens)
78
+            if self.randomize:
79
+                if (self.index % self.step_size) == (self.step_size - 1):
80
+                    # end of "segment", now go to random next segment
81
+                    new_index = self.index
82
+                    while (new_index == self.index) and (len(self.screens) > self.step_size):
83
+                        new_index = int(random.randrange(0, len(self.screens) / self.step_size) * self.step_size)
84
+                    self.index = new_index
85
+                else:
86
+                    # still in "segment", so just normal iteration
87
+                    self.index = (self.index + i) % len(self.screens)
88
+            else:
89
+                # go through all for normal operation
90
+                self.index = (self.index + i) % len(self.screens)
70 91
         else:
71 92
             # use step_size for button presses
72 93
             self.index = int((int(self.index / self.step_size) + i) * self.step_size) % len(self.screens)

Loading…
Cancel
Save