diff --git a/engine/controls.py b/engine/controls.py index c12562c..ef4bb57 100644 --- a/engine/controls.py +++ b/engine/controls.py @@ -30,8 +30,6 @@ class KeyBindings: elif key == "Space" or key == 1: self.play_sound("PUTDOWN.WAV") self.spawn_bomb(self.pointer) - elif key == "UpRelease" or key == "DownRelease" or key == "LeftRelease" or key == "RightRelease": - self.stop_scrolling() elif key == "P": self.pause = not self.pause # elif key == "mouse": @@ -39,4 +37,26 @@ class KeyBindings: # self.pointer = adjusted_coords # self.scroll_cursor() def key_released(self, key): - self.stop_scrolling() \ No newline at end of file + if key in ["Up", "Down", "Left", "Right"]: + self.stop_scrolling() + + def start_scrolling(self, direction): + self.scrolling_direction = direction + if not self.scrolling: + self.scrolling = 1 + + def stop_scrolling(self): + self.scrolling = 0 + + def scroll(self): + if self.scrolling: + 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 diff --git a/engine/sdl2.py b/engine/sdl2.py index 15fd5ef..3126f9b 100644 --- a/engine/sdl2.py +++ b/engine/sdl2.py @@ -144,7 +144,7 @@ class GameWindow: key = sdl2.SDL_GetKeyName(event.key.keysym.sym).decode('utf-8') self.key_down(key) elif event.type == sdl2.SDL_KEYUP and self.key_down: - key = sdl2.SDL_GetKeyName(event.key.keysym.sym).decode('utf-8') + "Release" + key = sdl2.SDL_GetKeyName(event.key.keysym.sym).decode('utf-8') self.key_up(key) print(key) elif event.type == sdl2.SDL_MOUSEMOTION: @@ -152,6 +152,9 @@ class GameWindow: elif event.type == sdl2.SDL_JOYBUTTONDOWN: key = event.jbutton.button self.key_down(key) + elif event.type == sdl2.SDL_JOYBUTTONUP: + key = event.jbutton.button + self.key_up(key) # Disegna qui gli sprite self.renderer.present() diff --git a/rats.py b/rats.py index 18db998..a51eac2 100644 --- a/rats.py +++ b/rats.py @@ -155,26 +155,6 @@ class MiceMaze(controls.KeyBindings): def add_point(self, value): self.points += value - def start_scrolling(self, direction): - self.scrolling_direction = direction - if not self.scrolling: - self.scrolling = 1 - - def stop_scrolling(self): - self.scrolling = 0 - - def scroll(self): - if self.scrolling: - 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__":