def events(self): for event in pygame.event.get(): joystick.Update(event) if not hasattr(event, "key"): event.key = None if event.type == pygame.KEYUP or joystick.WasEvent(): if event.key == pygame.K_F2 or joystick.JustPressedLB(): screenshot.capture("WL", self.display) if event.key == pygame.K_ESCAPE or joystick.BackEvent(): self.money_old = self.money_new if event.key == pygame.K_TAB: self.top_selected = not self.top_selected if event.key == pygame.K_UP or joystick.JustWentUp(): self.top_selected = True if event.key == pygame.K_DOWN or joystick.JustWentDown(): self.top_selected = False if event.key == pygame.K_y or joystick.JustPressedY(): self.info() if event.key == pygame.K_RETURN or joystick.JustPressedA(): self.stopped = True if self.mode == "won": self.register_sound.play() self.money_sound.stop() if self.top_selected: self.done = True else: self.done = True self.exit = True
def events(self): for event in pygame.event.get(): joystick.Update(event) if not hasattr(event, "key"): event.key = None if event.type == pygame.KEYUP or joystick.WasEvent(): if event.key == pygame.K_F2 or joystick.JustPressedLB(): screenshot.capture("WL", self.display) if event.key == pygame.K_ESCAPE or joystick.BackEvent(): self.money_old = self.money_new if event.key == pygame.K_TAB: self.selected_option += 1 if self.selected_option > self.options_range[1]: self.selected_option = self.options_range[0] if event.key == pygame.K_UP or joystick.JustWentUp(): self.selected_option = clamp(self.selected_option - 1, *self.options_range) if event.key == pygame.K_DOWN or joystick.JustWentDown(): self.selected_option = clamp(self.selected_option + 1, *self.options_range) if event.key == pygame.K_y or joystick.JustPressedY(): self.info() if event.key == pygame.K_RETURN or joystick.JustPressedA(): self.stopped = True self.done = True if self.mode == "won": self.register_sound.play() self.money_sound.stop() text = self.text[self.selected_option] if text == "Retry": self.retry = True if text == "Exit Game": self.exit = True
def events(self): for event in pygame.event.get(): click = False joystick.Update(event) if not hasattr(event, "key"): event.key = None if event.type == pygame.MOUSEBUTTONDOWN: if self.button_rect.collidepoint(pygame.mouse.get_pos()): click = True if event.type == pygame.KEYUP or joystick.WasEvent(): if event.key == pygame.K_y or joystick.JustPressedY(): cat = self.catagories[self.selected] sel = self.sel_num[self.selected] if self.selected != 2: item = list(cat.keys())[sel] else: item = cat[sel][1] if item: display_info(self.display, self.images, item) if event.type == pygame.KEYDOWN or joystick.WasEvent(): if event.key in (pygame.K_UP, pygame.K_w) or joystick.JustWentUp(): if not self.button_selected: self.selected -= 1 else: self.button_selected = False if event.key in (pygame.K_DOWN, pygame.K_s) or joystick.JustWentDown(): self.selected += 1 if self.selected < 0: self.selected = 0 if self.selected == len(self.rects): self.selected = len(self.rects) - 1 self.button_selected = True if (event.key in (pygame.K_LEFT, pygame.K_a) or joystick.JustWentLeft()) and not self.button_selected: self.sel_num[self.selected] -= 1 if (event.key in (pygame.K_RIGHT, pygame.K_d) or joystick.JustWentRight()) and not self.button_selected: self.sel_num[self.selected] += 1 if self.sel_num[self.selected] < 0: self.sel_num[self.selected] = 0 if self.sel_num[self.selected] == len( self.catagories[self.selected]): self.sel_num[self.selected] = len( self.catagories[self.selected]) - 1 if (event.key == pygame.K_RETURN or joystick.JustPressedA()) and not self.button_selected: cat = self.catagories[self.selected] lcat = list(cat) sel = self.sel_num[self.selected] didSomething = False if self.selected == 1: for x in self.catagories[2]: if x[1] == None: if not lcat: return didSomething = True x[1] = lcat[sel] if cat[lcat[sel]] == 1: cat.pop(lcat[sel]) break else: cat[lcat[sel]] -= 1 break if not didSomething: Sound(fix_path("audio/donk.wav")).play() if self.selected == 2 and cat[sel][1] != None: done = False for x in self.catagories[1]: if x == cat[sel][1]: self.catagories[1][x] += 1 done = True if not done: self.catagories[1][cat[sel][1]] = 1 cat[sel][1] = None if (event.key == pygame.K_RETURN or joystick.JustPressedA()) and self.button_selected: click = True if click and not self.cannotContinue(): self.done = True
def events(self): for event in pygame.event.get(): joystick.Update(event) cat = self.catagories[self.rect_sel] click = False if not hasattr(event, 'key'): event.key = None if event.type == pygame.QUIT: # self.confirmExit() self.done = True if event.type == pygame.KEYUP or joystick.WasEvent(): if (event.key == pygame.K_y or joystick.JustPressedY()) and cat: selected = list(cat.keys())[self.sel_num[self.rect_sel]] display_info(self.display, self.images, selected) if event.type == pygame.KEYDOWN or joystick.WasEvent(): jwu = joystick.JustWentUp() or event.key in (pygame.K_w, pygame.K_UP) jwd = joystick.JustWentDown() or event.key in (pygame.K_s, pygame.K_DOWN) mod_sel = False if jwu or jwd: sel = self.sel_num[self.rect_sel] new_sel = copy(sel) if jwd and sel + MAX_STORE_ITEM_LENGTH < len(cat): mod_sel = True new_sel += MAX_STORE_ITEM_LENGTH if jwu and sel - MAX_STORE_ITEM_LENGTH >= 0: mod_sel = True new_sel -= MAX_STORE_ITEM_LENGTH if mod_sel: self.sel_num[self.rect_sel] = new_sel if event.key == pygame.K_ESCAPE or joystick.BackEvent(): self.done = True if (jwu and not mod_sel) or joystick.JustPressedLT( ) or event.key == pygame.K_PAGEUP: self.rect_sel -= 1 if (jwd and not mod_sel) or joystick.JustPressedRT( ) or event.key == pygame.K_PAGEDOWN: self.rect_sel += 1 if self.rect_sel < 0: self.rect_sel = 0 if self.rect_sel >= len(self.rects): self.rect_sel = len(self.rects) - 1 cat = self.catagories[ self.rect_sel] # REMEMBER: this line must be here!!! if event.key in (pygame.K_a, pygame.K_LEFT) or joystick.JustWentLeft(): self.sel_num[self.rect_sel] -= 1 if event.key in (pygame.K_d, pygame.K_RIGHT) or joystick.JustWentRight(): self.sel_num[self.rect_sel] += 1 if self.sel_num[self.rect_sel] < 0: self.sel_num[self.rect_sel] = 0 if self.sel_num[self.rect_sel] >= len(cat): self.sel_num[self.rect_sel] = len(cat) - 1 if event.key == pygame.K_RETURN or joystick.JustPressedA(): click = True if event.type == pygame.MOUSEBUTTONDOWN: if self.purchase_rect.collidepoint(pygame.mouse.get_pos()): click = True if self.exit_rect.collidepoint(pygame.mouse.get_pos()): self.done = True if click: self.purchase()