# This file contains the Controls class, which is responsible for handling user input. # The key_pressed method is called when a key is pressed, and it contains the logic for handling different key presses. import random class KeyBindings: def key_pressed(self, key, coords=None): #print(key) if key == "Q" or key == 12: self.engine.close() elif key == "Return" or key == 13: self.new_rat() elif key == "D": if self.units: self.units[random.choice(list(self.units.keys()))].die(score=5) elif key == "M": self.audio = not self.audio elif key == "F": self.full_screen = not self.full_screen self.engine.full_screen(self.full_screen) elif key == "Up" or key == 8: self.start_scrolling("Up") elif key == "Down" or key == 9: self.start_scrolling("Down") elif key == "Left" or key == 10: self.start_scrolling("Left") elif key == "Right" or key == 11: self.start_scrolling("Right") elif key == "Space" or key == 1: self.play_sound("PUTDOWN.WAV") self.spawn_bomb(self.pointer) elif key == "P": self.pause = not self.pause # elif key == "mouse": # adjusted_coords = (coords[0]//self.cell_size*2, coords[1]//self.cell_size*2) # self.pointer = adjusted_coords # self.scroll_cursor() def key_released(self, key): if key in ["Up", "Down", "Left", "Right", 8, 9, 10, 11]: 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 def axis_scroll(self, x, y): self.scroll_cursor(1 if x > 0 else -1, 1 if y > 0 else -1)