def handle_inputs(self) -> None: # Called for each game tick. We check our keyboard presses here. for pg_event in pygame.event.get(): # handle window manager closing our window if self.is_quit_event(pg_event): EventManager.post(QuitEvent()) # handle key down events elif pg_event.type == pygame.KEYDOWN: self.handle_keypress(pg_event.unicode, pressed=True) # elif pg_event.type == pygame.KEYUP: # self.handle_keypress(pg_event.unicode, pressed=False) elif pg_event.type == pygame.MOUSEBUTTONDOWN: self.handle_mouse_click(pressed=True) elif pg_event.type == pygame.MOUSEBUTTONUP: self.handle_mouse_click(pressed=False)
def run(self) -> None: EventManager.post(TickEvent()) while True: EventManager.post(TickEvent())
def update(self, event: Event) -> None: if event.event_type == EventType.KEY_PRESS: if event.key == 'y': EventManager.post(ChangeScreenEvent('combat'))
def handle_mouse_click(self, pressed: bool) -> None: mouse_event = MouseClickEvent(position=pygame.mouse.get_pos(), pressed=pressed) EventManager.post(mouse_event)
def handle_keypress(self, key_name: str, pressed: bool) -> None: input_event = KeyPressEvent(key=key_name, pressed=pressed) EventManager.post(input_event)