def getXYCoordinatesFromBox(box, tile_size): logger = RkLogger.__call__().get_logger() logger.info("box {}".format(box)) # find the middle point x = box[0] + tile_size / 2 y = box[1] + tile_size / 2 x_index = int(x / tile_size) y_index = int(y / tile_size) return y_index, x_index
def __init__(self, screen, level): self.mood_str = None self.transitionToState = None self.screen = screen self.game_utils = GameUtils(level) self.level = level self.top_drag_grid_x = SCREEN_SPACER_SIZE self.top_drag_grid_y = SCREEN_SPACER_SIZE self.dash_board_position = [0, 0] self.drag_tiles_position = [0, 0] self.dashboard = DashBoard(self.screen, self.game_utils.grid_width, self.game_utils.grid_height, SCREEN_SPACER_SIZE) self.drag_tiles_container = DragContainer(self.screen, self.game_utils.grid_width, SCREEN_SPACER_SIZE) self.grid_size = None self.puzzle_image = None self.pil_image = None self.logger = RkLogger.__call__().get_logger() self.tiles_grid = None self.tiles_to_show = None
def handle_event(self, event): if event.type == pygame.MOUSEBUTTONDOWN: # If the user clicked on the input_box rect. if self.rect.collidepoint(event.pos): # Toggle the active variable. self.active = not self.active else: self.active = False # Change the current color of the input box. self.color = COLOR_ACTIVE if self.active else COLOR_INACTIVE if event.type == pygame.KEYDOWN: if self.active: if event.key == pygame.K_RETURN: if self.text != '': logger = RkLogger.__call__().get_logger() logger.info("mood entered " + self.text) # self.text = '' elif event.key == pygame.K_BACKSPACE: self.text = self.text[:-1] else: self.text += event.unicode # Re-render the text. self.txt_surface = FONT.render(self.text, True, self.color)
def handleEvents(self): events = pygame.event.get() for event in events: logger = RkLogger.__call__().get_logger() logger.info("event type " + str(event.type)) if event.type == pygame.QUIT: exit() # handle the text input first self.textinput.handle_event(event) logger.info("textinput " + self.textinput.text) self.mood_str = self.textinput.text self.mood_str_1 = self.textinput.get_text() if event.type == pygame.QUIT: done = True if event.type == pygame.KEYDOWN: if event.key == K_DOWN: self.selectedItem = (self.selectedItem + 1) % len( self.menuItems) if event.key == K_UP: self.selectedItem = (self.selectedItem - 1) % len( self.menuItems) if event.key == K_RETURN: # check to see if there is anything in the text logger.info("K_RETURN mood_str " + self.textinput.text) logger.info("K_RETURN clicked menu item " + self.menuItems[self.selectedItem]) # set loading message if self.menuItems[self.selectedItem] == 'Play': self.transitionToState = VIEW_STATE_LOADING else: self.transitionToState = self.MENU_ITEM_TO_VIEW_STATE[ self.selectedItem]
def fit_squares(self): logger = RkLogger.__call__().get_logger() logger.info("fit_squares") im = self.pil_image num_tiles = self.level['num_tiles'] width = im.width height = im.height px = math.ceil(math.sqrt(num_tiles * width / height)) if math.floor(px * height / width) * px < num_tiles: sx = height / math.ceil(px * height / width) else: sx = width / px py = math.ceil(math.sqrt(num_tiles * height / width)) if math.floor(py * width / height) * py < num_tiles: sy = width / math.ceil((width * py / height)) else: sy = height / py # TODO get the number of cols and rows by deviding the width/size and height/size # return all as tuple size = int(max(sx, sy)) num_cols = int(width / size) num_rows = int(height / size) return size, num_cols, num_rows
def __init__(self, art_dict): self.currentState = None self.art_dict = art_dict self.logger = RkLogger.__call__().get_logger()
def __init__(self, mood_str): self.currentState = None self.search_value = mood_str self.logger = RkLogger.__call__().get_logger()
def __init__(self, art_obj, width, height): self.currentState = None self.art_obj = art_obj self.width = width self.height = height self.logger = RkLogger.__call__().get_logger()