def update_input(self): scrolled = False if Input.was_pressed(M_4): scrolled = self.scroll_up() elif Input.was_pressed(M_5): scrolled = self.scroll_down() if scrolled: pos = Input.mouse_pos self.menu.reposition_cursor(pos)
def update(self): for key, command in self.mapping.iteritems(): if Input.was_pressed(key) is not None: if hasattr(command, '__getitem__'): return command[0](*command[1:]) else: return command()
def __update_mouse_motion(self): if self.menu.mouse_control == Menu.MOUSE_OFF: return False cursor = self.menu.cursor if cursor is None: return False event = Input.event(MOUSEMOTION) if event is not None: pos = event.pos self.menu.reposition_cursor(pos)
def __update_mouse_input(self): evt = Input.was_pressed(M_1) if evt is not None: if self.menu.cursor is not None: w = self.menu.cursor.widget if w is not None: x, y = evt.pos widget_x, widget_y = w.get_menu_position() captured = w.left_click(x - widget_x, y - widget_y) if not captured: self.activate() evt = Input.was_pressed(M_3) if evt is not None: if self.menu.cursor is not None: w = self.menu.cursor.widget if w is not None: x, y = evt.pos widget_x, widget_y = w.get_menu_position() captured = w.right_click(x - widget_x, y - widget_y) self.__update_mouse_motion()
def __update_input(self): for key in game_config.key_cancel: if Input.was_pressed(key) is not None: self.do_cancel = True return for key in game_config.key_action: if Input.was_pressed(key) is not None: self.do_action = True return if self.party_avatar.scheduled_movement \ or self.party_avatar.movement_phase \ or self.message_queue.is_busy(): return if self.do_cancel: self.do_cancel = False get_context_stack().stop() return if self.do_action: self.do_action = False self.map_model.party_action() return for key in game_config.key_up: if Input.motion(key): self.party_avatar.schedule_movement(Step(UP)) return for key in game_config.key_down: if Input.motion(key): self.party_avatar.schedule_movement(Step(DOWN)) return for key in game_config.key_left: if Input.motion(key): self.party_avatar.schedule_movement(Step(LEFT)) return for key in game_config.key_right: if Input.motion(key): self.party_avatar.schedule_movement(Step(RIGHT)) return if game_config.map_mouse_enabled: evt = Input.was_pressed(M_1) if evt is not None: if not self.party_avatar.scheduled_movement: self.__mouse_movement(evt.pos) return
def __update_input(self): #print '__update_input' for key in game_config.key_cancel: if Input.was_pressed(key) is not None: self.menu.close() self.command_cooldown = MenuController.COMMAND_COOLDOWN return for key in game_config.key_action: if Input.was_pressed(key) is not None: self.activate() self.command_cooldown = MenuController.COMMAND_COOLDOWN return if self.menu.cursor is None: return for key in game_config.key_up: if Input.motion(key): self.step(UP) self.command_cooldown = MenuController.COMMAND_COOLDOWN return for key in game_config.key_down: if Input.motion(key): self.step(DOWN) self.command_cooldown = MenuController.COMMAND_COOLDOWN return for key in game_config.key_left: if Input.motion(key): self.step(LEFT) self.command_cooldown = MenuController.COMMAND_COOLDOWN return for key in game_config.key_right: if Input.motion(key): self.step(RIGHT) self.command_cooldown = MenuController.COMMAND_COOLDOWN return self.__update_mouse_input()
def update_input(self): if Input.was_pressed(M_1): self.close()
def update_input(self): if Input.was_pressed(M_1): self.activate()
def update_input(self): for key in m_cfg.key_left.union(m_cfg.key_right): Input.was_pressed(key)
def update_input(self): for k in game_config.key_cancel: Input.was_pressed(k)
def gameloop(self, current=None): """ This method transfers the control flow to the ContextStack, which will keep its stacked Contexts running until one of them calls ContextStack.stop() or they are all removed from the ContextStack. The ContextStack will cap the cycles/second at game_config.fps. In each cycle, the following will happen: 1) For each active context in the map, bottom-up: a) The update() method of that Context will be called b) The draw() method of that Context will be drawn 2) The screen will be flipped so that the screen receives all the updates at once. 3) For each incoming event: a) For each context, top-down: i) The event will be offered to the context. ii) The context will choose to pass down or hold the event, no matter if it was actually used or not. iii) If the context chose not to pass down, continue to do 3. 4) If anyone called ContextStack.stop() or if there are no Contexts in the stack, stop. """ #print 'gameloop(%s)' % current self.keep_going = True self.clock = pygame.time.Clock() while self.stack and self.keep_going: # Limit FPS self.clock.tick(game_config.fps) get_metronome().step() Input.update_mouse(pygame.mouse.get_pressed(), pygame.mouse.get_pos()) Input.add_events(pygame.event.get()) if current is not None: current.update() else: # Update contexts in reverse order stop = False for context in reversed(self.stack): if context.active: #print 'updating %s' % context stop = context.update() if stop: break # Draw active contexts in normal order for context in self.stack: context.draw() if Input.isset('QUIT'): exit() Input.update() # Flip display get_screen().flip() if current is not None and current not in self.stack: self.keep_going = False # print 'gameloop ended' self.keep_going = True
def update_input(self): if Input.was_pressed(M_1) or Input.was_pressed(M_4): self.filled += 0.05 if Input.was_pressed(M_3) or Input.was_pressed(M_5): self.filled -= 0.05
def update_input(self): if Input.was_pressed(M_1) or Input.was_pressed(M_4): self.add_line() if Input.was_pressed(M_3) or Input.was_pressed(M_5): self.remove_line()