Browse Source

breakout: allow holding key when controlling board

Signed-off-by: Thomas Buck <thomas@venom.fritz.box>
Jannis 1 year ago
parent
commit
8e25711146
1 changed files with 6 additions and 5 deletions
  1. 6
    5
      breakout.py

+ 6
- 5
breakout.py View File

20
         self.timestep = ts
20
         self.timestep = ts
21
         self.timeout = to
21
         self.timeout = to
22
 
22
 
23
-        self.paddle_width = 43#9
23
+        self.paddle_width = 9
24
 
24
 
25
         self.winText = ScrollText(self.gui, "You Won!", "uushi",
25
         self.winText = ScrollText(self.gui, "You Won!", "uushi",
26
                                   2, 50, (0, 255, 0))
26
                                   2, 50, (0, 255, 0))
96
 
96
 
97
         return False
97
         return False
98
 
98
 
99
-    def buttons(self):
99
+    def buttons(self, next_step=False):
100
         keys = self.input.get()
100
         keys = self.input.get()
101
 
101
 
102
-        if keys["left"] and (not self.old_keys["left"]) and (not self.old_keys["select"]):
102
+        if keys["left"] and (not self.old_keys["left"] or next_step) and (not self.old_keys["select"]):
103
             self.direction = "l"
103
             self.direction = "l"
104
-        elif keys["right"] and (not self.old_keys["right"]) and (not self.old_keys["select"]):
104
+        elif keys["right"] and (not self.old_keys["right"] or next_step) and (not self.old_keys["select"]):
105
             self.direction = "r"
105
             self.direction = "r"
106
         elif (keys["select"] and keys["start"] and (not self.old_keys["start"])) or (keys["start"] and keys["select"] and (not self.old_keys["select"])):
106
         elif (keys["select"] and keys["start"] and (not self.old_keys["start"])) or (keys["start"] and keys["select"] and (not self.old_keys["select"])):
107
             self.restart()
107
             self.restart()
171
         self.scoreText.draw()
171
         self.scoreText.draw()
172
 
172
 
173
     def draw(self):
173
     def draw(self):
174
+        now = time.time()
174
         # handle / generate player inputs
175
         # handle / generate player inputs
175
         if self.input != None:
176
         if self.input != None:
176
-            self.buttons()
177
+            self.buttons((now - self.last) >= self.timestep)
177
         else:
178
         else:
178
             # TODO "AI"
179
             # TODO "AI"
179
             pass
180
             pass

Loading…
Cancel
Save