コード例 #1
0
    def configure_keybindings(self):
        InGameState.configure_keybindings(self)

        self.keydown_action_map.update({
            CAMERA_UP:              lambda: self.set_keystate("up", True), 
            CAMERA_LEFT:            lambda: self.set_keystate("left", True), 
            CAMERA_RIGHT:           lambda: self.set_keystate("right", True), 
            CAMERA_DOWN:            lambda: self.set_keystate("down", True), 
            RESIZE_LEFT:            lambda: self.resize_selected(-self._val(), 0),
            RESIZE_UP:              lambda: self.resize_selected(0, -self._val()),
            RESIZE_RIGHT:           lambda: self.resize_selected(self._val(), 0),
            RESIZE_DOWN:            lambda: self.resize_selected(0, self._val()),
            TRANSLATE_LEFT:         lambda: self.move_selected(-self._val(), 0),
            TRANSLATE_UP:           lambda: self.move_selected(0, -self._val()),
            TRANSLATE_RIGHT:        lambda: self.move_selected(self._val(), 0),
            TRANSLATE_DOWN:         lambda: self.move_selected(0, self._val()),
            TOGGLE_EDIT_MODE:       lambda: self.state_manager.set_current_state(GameStateManager.PLAYING_STATE),
            SAVE_LEVEL:             lambda: self.do_save(),
            DUPLICATE_SELECTED:     lambda: self.duplicate_selected(),
            CYCLE_SELECTED_TYPE:    lambda: self.cylcle_type_of_selected(),
            DELETE_SELECTED:        lambda: self.delete_selected()
        })
        self.keyup_action_map.update({
            CAMERA_UP:      lambda: self.set_keystate("up", False), 
            CAMERA_LEFT:    lambda: self.set_keystate("left", False), 
            CAMERA_RIGHT:   lambda: self.set_keystate("right", False), 
            CAMERA_DOWN:    lambda: self.set_keystate("down", False), 
        })
コード例 #2
0
 def handle_event(self, event):
     InGameState.handle_event(self, event)
     if event.type == pygame.MOUSEBUTTONDOWN or event.type == pygame.MOUSEBUTTONUP:
         x, y = self.get_drawer().screen_to_game_position((event.pos[0], event.pos[1]), snap_to_grid=False)
         grid_x, grid_y = self.get_drawer().screen_to_game_position((event.pos[0], event.pos[1]), snap_to_grid=True)
         
         if event.type == pygame.MOUSEBUTTONDOWN:
             self._mouse_down_pos = (grid_x, grid_y)
         elif event.type == pygame.MOUSEBUTTONUP:
             # using grid position values to prevent tiny drag annoyances
             if self._mouse_down_pos == None or (grid_x, grid_y) == self._mouse_down_pos:
                 utilities.log("Click at: ("+str(x)+", "+str(y)+") ["+str(grid_x)+", "+str(grid_y)+"]")
                 self._click_and_release_at(x,y)
             else:
                 x1 = self._mouse_down_pos[0]
                 y1 = self._mouse_down_pos[1]
                 x2 = grid_x
                 y2 = grid_y
                 xavg = (x1 + x2) / 2
                 yavg = (y1 + y2) / 2
                 utilities.log("Drag from: ["+str(x1)+", "+str(y1)+"] to ["+str(x2)+", "+str(y2)+"]")
                 x_path_str = str(xavg)+" + "+str((x2 - x1) / 2)+"*cos(t*0.03)"
                 y_path_str = str(yavg)+" + "+str((y2 - y1) / 2)+"*sin(t*0.03)"
                 path_json_str = "\"path\": {\"type\": \"path\", \"x_path\": \""+x_path_str+"\", \"y_path\": \""+y_path_str+"\"}"
                 utilities.log(path_json_str)
コード例 #3
0
 def __init__(self, settings, platformer_instance):
     InGameState.__init__(self, settings, platformer_instance)
     self.selected = None
     self.selected_old_color = None
     
     # used to alternate which block gets selected if user clicks on an overlapping position
     self._last_clicked_objs = []
     self._last_idx_used = -1
     
     self._mouse_down_pos = None