Modifica la gestione dei tasti nella classe GameWindow; aggiungi supporto per il rilascio dei tasti e migliora la logica di scrolling

This commit is contained in:
2024-12-23 16:23:40 +01:00
parent 3be35d07ee
commit 2e4d0b8726
3 changed files with 27 additions and 21 deletions
+16 -13
View File
@@ -14,7 +14,8 @@ class MiceMaze(controls.KeyBindings):
self.audio = True
self.cell_size = 40
self.full_screen = False
self.engine = engine.GameWindow(self.map.width, self.map.height, self.cell_size, "Mice!", key_callback=self.key_pressed)
self.engine = engine.GameWindow(self.map.width, self.map.height,
self.cell_size, "Mice!", key_callback=(self.key_pressed, self.key_released))
self.pointer = (random.randint(1, self.map.width-2), random.randint(1, self.map.height-2))
self.scroll_cursor()
self.points = 0
@@ -106,6 +107,7 @@ class MiceMaze(controls.KeyBindings):
unit.collisions()
unit.draw()
self.engine.update_status(f"Mice: {len(self.units)} - Points: {self.points}")
self.scroll()
self.engine.new_cycle(50, self.update_maze)
@@ -155,23 +157,24 @@ class MiceMaze(controls.KeyBindings):
def start_scrolling(self, direction):
self.scrolling_direction = direction
self.scrolling = True
self.scroll()
if not self.scrolling:
self.scrolling = 1
def stop_scrolling(self):
self.scrolling = False
self.scrolling = 0
def scroll(self):
if self.scrolling:
if self.scrolling_direction == "Up":
self.scroll_cursor(y=-1)
elif self.scrolling_direction == "Down":
self.scroll_cursor(y=1)
elif self.scrolling_direction == "Left":
self.scroll_cursor(x=-1)
elif self.scrolling_direction == "Right":
self.scroll_cursor(x=1)
self.engine.new_cycle(100, self.scroll)
if not self.scrolling % 5:
if self.scrolling_direction == "Up":
self.scroll_cursor(y=-1)
elif self.scrolling_direction == "Down":
self.scroll_cursor(y=1)
elif self.scrolling_direction == "Left":
self.scroll_cursor(x=-1)
elif self.scrolling_direction == "Right":
self.scroll_cursor(x=1)
self.scrolling += 1
if __name__ == "__main__":