我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pygame.K_RETURN。
def ProcessInput(self, events, pressed_keys): for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: # Move to the next scene when the user pressed Enter pass if event.type == pygame.MOUSEBUTTONDOWN: self.start_button.isClicked(event) self.help_button.isClicked(event) self.difficulty_button.isClicked(event) if event.type == pygame.MOUSEBUTTONUP: self.start_button.isClicked(event) self.help_button.isClicked(event) self.difficulty_button.isClicked(event) if event.type == pygame.MOUSEMOTION: self.start_button.isHovered(event) self.help_button.isHovered(event) self.difficulty_button.isHovered(event)
def Kaboom(score): init() gameDisplay.blit(GameOver,(382,175)) pygame.draw.rect(gameDisplay, white, (200, 400, 550, 50)) text = smallfont.render("Press [RETURN] to continue and [Q] to quit", True, darkBlue) gameDisplay.blit(text, [370,400]) text = smallfont.render("Score : " + str(score), True, red) gameDisplay.blit(text, [450,420]) pygame.display.update() gameExit = True while gameExit: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: gameExit = False gameloop() if event.key == pygame.K_q: pygame.quit()
def ProcessInput(self, events, pressed_keys): for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: # Move to the next scene when the user pressed Enter pass if event.type == pygame.MOUSEBUTTONDOWN: for button in self.buttons: button.isClicked(event) if event.type == pygame.MOUSEBUTTONUP: for button in self.buttons: button.isClicked(event) if event.type == pygame.MOUSEMOTION: for button in self.buttons: button.isHovered(event)
def ProcessInput(self, events, pressed_keys): """ Process Input from user Inherited from SceneBase Args: self events - list of pygame events pressed_keys """ for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: # Move to the next scene when the user pressed Enter pass if event.type == pygame.MOUSEBUTTONDOWN: self.easy_button.isClicked(event) self.adv_button.isClicked(event) if event.type == pygame.MOUSEBUTTONUP: self.easy_button.isClicked(event) self.adv_button.isClicked(event) if event.type == pygame.MOUSEMOTION: self.easy_button.isHovered(event) self.adv_button.isHovered(event)
def handleEvent(self, event): self.collisionEngine.eventHandler(event) self.scene.handleEvent(event) if event.type == pg.KEYDOWN: if event.key == pg.K_RETURN: self.camera.duration = 0 if event.type == self.SCENE_EVENT: if event.category == "complete": self._nextScene() if event.category == "transition": self._handleTransition(event) if event.category == "death": self._handleDeath() if event.category == "revive": self._handleRevive() if event.category == "pause": if self.lives != 0: self.pause = True self.messageMenu("transition", "pause_menu") if event.category == "unpause": self.pause = False self._loadUI(self.maxLives, self.lives)
def handleEvent(self, event): if event.type == pg.KEYDOWN: if event.key == pg.K_UP: self.arrow.moveUp() if event.key == pg.K_DOWN: self.arrow.moveDown() if event.key == pg.K_RETURN: self.audio.state = "enter" if self.arrow.index == 0: self.messageMenu("transition", "blank_menu") self.messageCutScene("transition", "office_cutscene") if self.arrow.index == 1: self.messageMenu("transition", "blank_menu") self.messageScene("start_game", "coop") if self.arrow.index == 2: self.messageMenu("transition", "options_menu") if self.arrow.index == 3: quit()
def update_cursor(self, keys): """Update the position of the cursor""" input_list = [pg.K_RETURN, pg.K_a, pg.K_s] if self.cursor.state == c.PLAYER1: self.cursor.rect.y = 358 if keys[pg.K_DOWN]: self.cursor.state = c.PLAYER2 for input in input_list: if keys[input]: self.reset_game_info() self.done = True elif self.cursor.state == c.PLAYER2: self.cursor.rect.y = 403 if keys[pg.K_UP]: self.cursor.state = c.PLAYER1
def notify(self, event): if self.isActivated: if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: self.optionList[self.selector.selectedIndex].deselect() self.selector.moveUp() self.scrollUp() self.optionList[self.selector.selectedIndex].select() elif event.key == pygame.K_DOWN: self.optionList[self.selector.selectedIndex].deselect() self.selector.moveDown() self.scrollDown() self.optionList[self.selector.selectedIndex].select() elif event.key == pygame.K_SPACE: self.chosenOptionIndex = self.selectedIndex() self.isActivated = False elif event.key == pygame.K_RETURN: self.chosenOptionIndex = self.selectedIndex() self.isActivated = False
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if self.show_msg == False: if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN: lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] elif not self.board.grid[4][18]: char = event.unicode if len(char) > 0 and lhv < 2 and char in self.digits: self.home_square.value += char self.home_square.update_me = True self.mainloop.redraw_needed[0] = True elif event.type == pygame.MOUSEMOTION and self.drag: if self.board.grid[4][18]: self.home_square.value = "" self.home_square.update_me = True elif event.type == pygame.MOUSEBUTTONUP: for each in self.board.units: if each.is_door is True: self.board.all_sprites_list.move_to_front(each)
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if self.show_msg == False: if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN: char = event.unicode if len(char) > 0: if char == self.middle.value: if len(self.right.value) > 0: self.left.value += char next_letter = self.right.value[0] self.middle.value = next_letter self.right.value = self.right.value[1:] self.kbrd.get_btns_to_hl(next_letter) self.mainloop.sfx.play(15) elif len(self.middle.value) > 0: self.left.value += char self.middle.value = "" self.check_entry() for each in [self.left, self.middle, self.right]: each.update_me = True else: self.mainloop.sfx.play(16) self.mainloop.redraw_needed[0] = True
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if self.show_msg == False: if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN: lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] elif not self.board.grid[4][18]: char = event.unicode if len(char) > 0 and char in self.digits: self.home_square.value = char self.home_square.update_me = True self.mainloop.redraw_needed[0] = True elif event.type == pygame.MOUSEMOTION and self.drag: if self.board.grid[4][18]: self.home_square.value = "" self.home_square.update_me = True elif event.type == pygame.MOUSEBUTTONUP: for each in self.board.units: if each.is_door is True: self.board.all_sprites_list.move_to_front(each)
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if self.show_msg == False: if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN: lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] elif not self.board.grid[4][16]: char = event.unicode if len(char) > 0 and char in self.digits: self.home_square.value = char self.home_square.update_me = True self.mainloop.redraw_needed[0] = True elif event.type == pygame.MOUSEMOTION and self.drag: if self.board.grid[4][16]: self.home_square.value = "" self.home_square.update_me = True elif event.type == pygame.MOUSEBUTTONUP: for each in self.board.units: if each.is_door is True: self.board.all_sprites_list.move_to_front(each)
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if self.show_msg == False: if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN and not self.correct: lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] else: char = event.unicode if (len(char) > 0 and lhv < 5 and char in self.digits): self.home_square.value += char self.home_square.update_me = True self.mainloop.redraw_needed[0] = True elif event.type == pygame.MOUSEBUTTONUP: self.home_square.update_me = True if self.board.active_ship == self.home_square.unit_id: self.home_square.perm_outline_width = 5 self.home_square = self.ans_h self.board.active_ship = self.home_square.unit_id self.home_square.update_me = True self.mainloop.redraw_needed[0] = True
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if self.show_msg == False: if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN: lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] else: char = event.unicode if char in self.digits: if len(char) > 0 and lhv < self.max_len: self.home_square.value += char else: self.home_square.value = char self.home_square.update_me = True self.mainloop.redraw_needed[0] = True
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if self.show_msg == False: if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN: lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] else: char = event.unicode if char in self.digits: if len(char) > 0 and lhv < 3: self.home_square.value += char else: self.home_square.value = char self.home_square.update_me = True self.mainloop.redraw_needed[0] = True
def onKeyDown(self, event): if not self.select_item: if event.type == pygame.KEYDOWN and event.key == pygame.K_DELETE: pass elif event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER and event.key != pygame.K_TAB: lhv = len(self.value) if event.key == pygame.K_BACKSPACE: if lhv > 0: if self.ls.lang.ltr_text: self.value = self.value[0:lhv - 1] else: self.value = self.value[1:lhv] else: char = event.unicode if len(char) > 0 and lhv < 21: if self.ls.lang.ltr_text: self.value = self.value + char else: self.value = char + self.value self.ls.reload_selects() self.ls.set_scrollbar_top(self.ls.scroll_min_top) elif event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER or event.key == pygame.K_TAB: self.nextFocus() self.update_trigger()
def touch_handler(self, event): #handle keypresses... if event.type == pygame.KEYDOWN: if event.key == pygame.K_BACKSPACE: self.panel.text.del_letter() elif event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER: self.panel.new_line() elif event.key == pygame.K_ESCAPE: self.close(None) elif event.key == pygame.K_LEFT: self.panel.text.cursor_left() elif event.key == pygame.K_RIGHT: self.panel.text.cursor_right() elif len(event.unicode) > 0: self.panel.text.add_letter(event.unicode) super(Keyboard,self).touch_handler(event)
def show(self): """ Shows the game over panel. """ self.display.set_screen_caption('Game Over') for event in pygame.event.get(): if (event.type == pygame.KEYDOWN): if (event.key == pygame.K_RETURN): return (True, "main_menu", None) if (event.key == pygame.K_s): return (True, "save_progress", None) if (event.type == pygame.QUIT): return (False, '', None) self.display.display_single_image(self.resources['game_over_msg'], self.resources['game_over_pos']) self.display.display_single_image(self.resources['game_over_char'], self.resources['game_over_pos']) self.display.display_single_image(self.resources['press_enter'], self.resources['press_enter_pos']) self.display.display_single_image(self.resources['save_msg'], self.resources['save_msg_pos']) return (True, 'game_over', None)
def textBoxInput(textbox): # starts grabbing key inputs, putting into textbox until enter pressed global keydict textbox.text = "" while True: updateDisplay() for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: textbox.clear() return textbox.text elif event.key == pygame.K_ESCAPE: pygame.quit() sys.exit() else: textbox.update(event) elif event.type == pygame.QUIT: pygame.quit() sys.exit()
def ask(self,question): word="" Text(self.game).draw_text2(self.default,question,green,wth//2,50) #example asking name pygame.display.flip() done = True while done: for event in pygame.event.get(): if event.type==pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_a: word+=str(chr(event.key)) if event.key == pygame.K_b: word+=chr(event.key) if event.key == pygame.K_c: word+=chr(event.key) if event.key == pygame.K_d: word+=chr(event.key) if event.key == pygame.K_RETURN: done=False #events... return Text(self.game).draw_text2(self.default,word,green,wth//2,100)
def handleEvents(self, events): for event in events: if event.type == pygame.QUIT: self.doQuit() return elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: self.doQuit() return elif event.key == pygame.K_DOWN: self.current_option += 1 if self.current_option >= len(self.options): self.current_option = 0 elif event.key == pygame.K_UP: self.current_option -= 1 if self.current_option < 0: self.current_option = len(self.options)-1 elif event.key == pygame.K_RETURN: self.currentOptionExecute() return
def handle_event(self, event): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: self.root.trigger_exit_to_main() elif event.key == pygame.K_p: self.toggle_pause() elif not self.paused: if event.key == pygame.K_SPACE: self.skip_turn = True elif event.key == pygame.K_RETURN: self.skip_game = True elif event.key in [pygame.K_LEFT, pygame.K_1]: self.parent.battle.award_victory(1) self.skip_game = True elif event.key in [pygame.K_RIGHT, pygame.K_2]: self.parent.battle.award_victory(2) self.skip_game = True
def ShowPhoto(photoFile): screen = pygameEngine.GetScreen() image = pygame.image.load(photoFile).convert() image = pygame.transform.scale(image, (config.WIDTH,config.HEIGHT)) screen.blit(image, (0,0)) pygame.display.update() sleep(1) pygameEngine.ShowNavButtons() i = 0 while True: # get one pygame event event = pygame.event.poll() # handle events # Button 1 = Quit if (event.type == pygame.MOUSEBUTTONUP and event.button == 1) or (event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE) or GPIO.input(config.GPIO_NUMBER_BUTTON_1): return -1 # Button 2 = Cycle old photos if (event.type == pygame.MOUSEBUTTONUP and event.button == 3) or (event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN) or GPIO.input(config.GPIO_NUMBER_BUTTON_2): return 1 # Button Esc or Q = Quit keys if event.type == pygame.KEYDOWN and (event.key == pygame.K_ESCAPE or event.key == pygame.K_q) : return -1
def title(): """ This shows the title screen before the game starts """ screen.blit(graphics.img_title_screen, (0, 0)) video.update() sounds.music_play('title_music.ogg') while True: ev = pg.event.poll() if ev.type == pg.KEYDOWN and ev.key == pg.K_RETURN: sounds.startgame() break sounds.music_stop() screen.fill(colors.Black) pg.time.delay(1000) letter_by_letter('I came to eat apples') pg.time.wait(1000) letter_by_letter('and chew bubblegum...') pg.time.wait(3000) sounds.begin() letter_by_letter('And I\'m all out of gum.') screen.fill(colors.Black) pg.time.delay(2000)
def process_input(self, events): if not self.end_state[0]: for event in events: if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: mouse_position = pygame.mouse.get_pos() x = int(mouse_position[0] / self.square_width) y = int(mouse_position[1] / self.square_width) if (x, y) not in self.players[1].positions: if self.players[0].add_position(x, y, self.minimax_board): computer_position = pruned_minimax(self.minimax_board) if not end_state(self.minimax_board)[0]: self.players[1].add_position(computer_position[0][0], computer_position[0][1], self.minimax_board, 1) else: for event in events: if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: self.clear() elif event.key == pygame.K_SPACE: self.clear(True) # the update method checks if the board is in an end state:
def run(self): while self.visible & this.drawing: # wait for event event = pygame.event.wait() if event.type == pygame.KEYDOWN: if event.key == pygame.K_DOWN: self.select_previous() elif event.key == pygame.K_LEFT: self.select_previous() elif event.key == pygame.K_RETURN: self.activate() elif event.key == pygame.K_z: self.activate() elif event.key == pygame.K_x: self.previous_menu() elif event.key == pygame.K_RIGHT: self.select_next() # runs self, as well as show.
def get_input(): for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if state.state == "playing": if event.key == pygame.K_LEFT: if valid(state.X - 1, state.Y, state.piece.forms[state.form]): state.X -= 1 if event.key == pygame.K_RIGHT: if valid(state.X + 1, state.Y, state.piece.forms[state.form]): state.X += 1 if event.key == pygame.K_SPACE: new_form = state.form - 1 if new_form < 0: new_form = 3 if valid(state.X, state.Y, state.piece.forms[new_form]): state.form = new_form if event.key == pygame.K_DOWN: state.state = "falling" if state.state == "lost": if event.key in [pygame.K_SPACE, pygame.K_RETURN]: state.start_game()
def _map_keys(self): key_map = self.io.key_map key_map[imgui.KEY_TAB] = pygame.K_TAB key_map[imgui.KEY_LEFT_ARROW] = pygame.K_LEFT key_map[imgui.KEY_RIGHT_ARROW] = pygame.K_RIGHT key_map[imgui.KEY_UP_ARROW] = pygame.K_UP key_map[imgui.KEY_DOWN_ARROW] = pygame.K_DOWN key_map[imgui.KEY_PAGE_UP] = pygame.K_PAGEUP key_map[imgui.KEY_PAGE_DOWN] = pygame.K_PAGEDOWN key_map[imgui.KEY_HOME] = pygame.K_HOME key_map[imgui.KEY_END] = pygame.K_END key_map[imgui.KEY_DELETE] = pygame.K_DELETE key_map[imgui.KEY_BACKSPACE] = pygame.K_BACKSPACE key_map[imgui.KEY_ENTER] = pygame.K_RETURN key_map[imgui.KEY_ESCAPE] = pygame.K_ESCAPE key_map[imgui.KEY_A] = pygame.K_a key_map[imgui.KEY_C] = pygame.K_c key_map[imgui.KEY_V] = pygame.K_v key_map[imgui.KEY_X] = pygame.K_x key_map[imgui.KEY_Y] = pygame.K_y key_map[imgui.KEY_Z] = pygame.K_z
def ProcessInput(self, events, pressed_keys): """ Process input from user Inherits from SceneBase Args: self events - pygame events pressed_keys """ for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: # Move to the next scene when the user pressed Enter pass if event.type == pygame.MOUSEBUTTONDOWN: for button in self.buttons: button.isClicked(event) if self.leveling_up: self.continue_button.isClicked(event) if event.type == pygame.MOUSEBUTTONUP: for button in self.buttons: button.isClicked(event) if self.leveling_up: self.continue_button.isClicked(event) if event.type == pygame.MOUSEMOTION: #for button in self.buttons: # button.isHovered(event) if self.leveling_up: self.continue_button.isHovered(event)
def handleEvent(self, event): self.collisionEngine.eventHandler(event) self.scene.handleEvent(event) if event.type == pg.KEYDOWN: if event.key == pg.K_RETURN: self.camera.duration = 0 if event.key == pg.K_SPACE: self._swapCameraFollow() if event.type == self.SCENE_EVENT: if event.category == "complete": self._nextScene() if event.category == "transition": self._handleTransition(event) if event.category == "unpause": self._loadUI(self.maxLives, self.lives) if event.category == "death": self._handleDeath(event) if event.category == "revive": self._handleRevive() if event.category == "pause": isAlive = all([live != 0 for live in self.lives]) if isAlive: self.pause = True self.messageMenu("transition", "pause_menu") if event.category == "unpause": self.pause = False self._loadUI(self.maxLives, self.lives)
def eventHandler(self, event): if event.type == pg.KEYDOWN: if event.key == pg.K_RETURN: self.resolveDoorCollisions() try: p1, p2 = self.scene.players p1Jump = p1.keybinds["coop_jump"] p2Jump = p2.keybinds["coop_jump"] if event.key == p1Jump or event.key == p2Jump: self.resolvePlayerCollisions(30) self.audio.state = "explosion" except ValueError: pass
def handleEvent(self, event): if event.type == pg.KEYDOWN: if event.key == pg.K_RETURN: self._messageNextScene()
def handleEvent(self, event): if event.type == pg.KEYDOWN: if event.key == pg.K_RETURN: self.messageCutScene("transition", "jail_cutscene")
def handleEvent(self, event): if event.type == pg.KEYDOWN: if event.key == pg.K_RETURN: self._messageStart()
def handleEvent(self, event): if event.type == pg.KEYDOWN: if event.key == pg.K_RETURN: self._sendMessage()
def handleEvent(self, event): if event.type == pg.KEYDOWN: if event.key == pg.K_ESCAPE: self.effect.timeStartDarken = self.effect.time self.effect.timeEndDarken = self.effect.time + self.dt self.audio.state = "exit" if event.key == pg.K_UP: self.arrow.moveUp() if event.key == pg.K_DOWN: self.arrow.moveDown() if self.arrow.index == 0: if event.key == pg.K_RIGHT: self.backgroundSetting.next() if event.key == pg.K_LEFT: self.backgroundSetting.previous() if event.key == pg.K_RETURN: if self.backgroundSetting.index == 0: self.render.flip(True, False) if self.backgroundSetting.index == 1: self.render.flip(False, True) if self.arrow.index == 1: if event.key == pg.K_RIGHT: self.fullscreenSetting.next() if event.key == pg.K_LEFT: self.fullscreenSetting.previous() if event.key == pg.K_RETURN: if self.fullscreenSetting.index == 0: pg.display.set_mode((settings.WIDTH, settings.HEIGHT)) if self.fullscreenSetting.index == 1: pg.display.set_mode((settings.WIDTH, settings.HEIGHT), pg.FULLSCREEN) self.messageMenu("screen") self.messageScene("screen") self.messageCutScene("screen")
def handleEvent(self, event): if event.type == pg.KEYDOWN: if event.key == pg.K_RETURN: self.messageMenu("transition", "main_menu") self.messageScene("no_mode")
def notify(self, event): if self.isActivated: if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: pass elif event.key == pygame.K_DOWN: pass elif event.key == pygame.K_SPACE: self.isActivated = False elif event.key == pygame.K_RETURN: pass
def notify(self, event): if self.selected: if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: self.optionList[self.selector.vPos].deselect() self.selector.moveUp() self.optionList[self.selector.vPos].select() elif event.key == pygame.K_DOWN: self.optionList[self.selector.vPos].deselect() self.selector.moveDown() self.optionList[self.selector.vPos].select() elif event.key == pygame.K_SPACE: self.optionList[self.selector.vPos].doOption() elif event.key == pygame.K_RETURN: self.optionList[self.selector.vPos].doOption()
def update(self,screen,event_queue,dt,clock, joystick, netmodel, vizmodel): nextState = self self.name = gameover.enter_text(event_queue,screen, 8) for event in event_queue: if event.type == pygame.KEYUP: if event.key == pygame.K_RETURN: self.name = gameover.pressed leaderboard.StoreScore(self.name,self.score) nextState = Leaderboard(self.name) return nextState
def update(self, screen, event_queue, dt,clock,joystick, netmodel, vizmodel): # Logos/titles screen.blit(self.logo,(screen.get_width() / 4 - 265,screen.get_height() * 3 / 4-500)) screen.blit(self.intel,(screen.get_width() / 4 - 300,screen.get_height()-130)) screen.blit(self.activestate,(screen.get_width() - 980,screen.get_height() - 130)) nextState = self displaytext('Play', 32, screen.get_width() / 4 - 20, screen.get_height() * 3 / 4 - 80, WHITE, screen) displaytext('Train', 32, screen.get_width() / 4 - 20, screen.get_height() * 3 / 4 - 40, WHITE, screen) displaytext('Exit', 32, screen.get_width() / 4 - 20, screen.get_height() * 3 / 4, WHITE, screen) displaytext(u'\u00bb', 32, screen.get_width() / 4 - 60, screen.get_height() * 3 / 4 - 40*self.menu_selection, WHITE, screen) # Each game state processes its own input queue in its own way to avoid messy input logic for event in event_queue: if event.type == pygame.KEYDOWN or event.type == pygame.JOYBUTTONDOWN: if (event.type == pygame.KEYDOWN and (event.key == pygame.K_DOWN)) or (event.type == pygame.JOYBUTTONDOWN and (event.button == 1)) or (event.type == pygame.JOYAXISMOTION and (event.axis == 1 or event.value >= DEADZONE)): self.menu_selection -= 1 if self.menu_selection == -1: self.menu_selection = 2 if (event.type == pygame.KEYDOWN and (event.key == pygame.K_UP)) or (event.type == pygame.JOYBUTTONDOWN and (event.button == 0)) or (event.type == pygame.JOYAXISMOTION and (event.axis == 1 or event.value <= -DEADZONE)): self.menu_selection += 1 if self.menu_selection == 3: self.menu_selection = 0 if (event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN) or (event.type == pygame.JOYBUTTONDOWN and event.button == 11): if self.menu_selection == 2: nextState = Play(False) elif self.menu_selection == 1: nextState = Play(True) else: nextState = None if (event.type == pygame.KEYDOWN and event.key == pygame.K_x): self.ExportModel() if (event.type == pygame.KEYDOWN and event.key == pygame.K_d): self.DumpData() if (event.type == pygame.KEYDOWN and event.key == pygame.K_w): self.DumpWeights() return nextState
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if self.show_msg == False: if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN: lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] else: char = event.unicode if len(char) > 0 and lhv < 3 and char in self.digits: self.home_square.value += char self.home_square.update_me = True self.mainloop.redraw_needed[0] = True
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if self.show_msg == False: if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN: lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] else: char = event.unicode if len(char) > 0 and lhv < self.sollen and char in self.digits: self.home_square.value += char self.home_square.update_me = True self.mainloop.redraw_needed[0] = True
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if self.show_msg == False: if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN: self.auto_check_reset() if event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT: self.home_sqare_switch(self.board.active_ship + 1) elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT: self.home_sqare_switch(self.board.active_ship - 1) elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP: self.home_sqare_switch(self.board.active_ship - self.sumn1n2sl + 1) elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN: self.home_sqare_switch(self.board.active_ship + self.sumn1n2sl) elif event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN and not self.correct: lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] else: char = event.unicode if (len(char) > 0 and lhv < 2 and char in self.digits): self.home_square.value = char if self.auto_select: self.home_sqare_switch(self.board.active_ship + 1) else: self.home_square.value = "" self.home_square.update_me = True self.mainloop.redraw_needed[0] = True elif event.type == pygame.MOUSEBUTTONUP: self.home_sqare_switch(self.board.active_ship)
def onKeyDown(self, event): if event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER: self.fsubmit() self.update_trigger()
def init_rotary_encoders(self): """ Rotary encoders (RE) initializer. This is executed only if RE enabled in config.txt. Two REs are configured this way: 1. Volume Control: GPIO16 - Volume Up, GPIO26 - Volume Down, GPIO13 - Mute 2. Tuning: GPIO12 - Move Right, GPIO6 - Move Left, GPIO5 - Select RE events will be wrapped into keyboard events with the following assignment: Volume Up - '+' key on numeric keypad, Volume Down - '-' key on keypad, Mute - 'x' key """ if not self.config[USAGE][USE_ROTARY_ENCODERS]: return from event.rotary import RotaryEncoder RotaryEncoder(16, 26, 13, pygame.K_KP_PLUS, pygame.K_KP_MINUS, pygame.K_x) RotaryEncoder(12, 6, 5, pygame.K_RIGHT, pygame.K_LEFT, pygame.K_RETURN)
def __pygamebox(title, message): try: import pygame pygame.quit() #clean out anything running pygame.display.init() pygame.font.init() screen = pygame.display.set_mode((460, 140)) pygame.display.set_caption(title) font = pygame.font.Font(None, 18) foreg, backg, liteg = (0, 0, 0), (180, 180, 180), (210, 210, 210) ok = font.render('Ok', 1, foreg, liteg) okbox = ok.get_rect().inflate(200, 10) okbox.centerx = screen.get_rect().centerx okbox.bottom = screen.get_rect().bottom - 10 screen.fill(backg) screen.fill(liteg, okbox) screen.blit(ok, okbox.inflate(-200, -10)) pos = [10, 10] for text in message.split('\n'): if text: msg = font.render(text, 1, foreg, backg) screen.blit(msg, pos) pos[1] += font.get_height() pygame.display.flip() stopkeys = pygame.K_ESCAPE, pygame.K_SPACE, pygame.K_RETURN, pygame.K_KP_ENTER while 1: e = pygame.event.wait() if e.type == pygame.QUIT or \ (e.type == pygame.KEYDOWN and e.key in stopkeys) or \ (e.type == pygame.MOUSEBUTTONDOWN and okbox.collidepoint(e.pos)): break pygame.quit() except pygame.error: raise ImportError