You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.6 KiB

# 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 == "UpRelease" or key == "DownRelease" or key == "LeftRelease" or key == "RightRelease":
self.stop_scrolling()
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()