def left_click(self, _dt, _cursor_pos): if self.inventory.enabled: max_down = 40 * self.inventory.rows max_right = 40 * self.inventory.cols if self.mouse_pos[0] < max_right and self.mouse_pos[1] < max_down: curr_row = round(self.mouse_pos[1] / 40) - 1 curr_col = round(self.mouse_pos[0] / 40) - 1 if curr_row >= 0 and curr_col >= 0 and self.sel_item[ 0] is not None: if self.inventory.get_item_at([curr_col, curr_row]) == None: self.inventory.items[curr_row][ curr_col] = self.sel_item[0] if self.sel_item[0] == self.inventory.get_item_at( [curr_col, curr_row]): to_rem = 1 if self.key_state[pygame.KMOD_CTRL]: to_rem = self.sel_item[1] # max_val = consts.ITEM_ATTR[self.sel_item[0]][consts.item_attr.MAX_STACK] max_val = 64 to_rem = min( to_rem, max_val - self.inventory.get_quantity_at( [curr_col, curr_row])) self.inventory.quantities[curr_row][curr_col] += to_rem self.sel_item[1] -= to_rem if self.sel_item[1] == 0: self.sel_item[0] = None elif self.sel_item[0] is not None: quantity = 1 if self.key_state[pygame.KMOD_CTRL]: quantity = self.sel_item[1] pos = self.cursor_pos.copy() self.eject_sel_item(pos, quantity) else: function = consts.l_use_hand which_item = self.get_held_item() if which_item: function = consts.ITEM_ATTR[which_item][consts.item_attr.L_USE] pos_x = consts.get_x_pos_chunk(_cursor_pos) pos_y = consts.get_y_pos_chunk(_cursor_pos) which_chunk = consts.get_curr_chunk( _cursor_pos ) - self.entity_buffer.chunk_buffer.get_start_chunk_ind() function(pos_x, pos_y, which_chunk, self.entity_buffer.chunk_buffer, self.entity_buffer, _dt)
def right_click(self, _dt, _cursor_pos): function = consts.r_use_hand which_item = self.get_held_item() if which_item: function = consts.ITEM_ATTR[which_item][consts.item_attr.R_USE] pos_x = consts.get_x_pos_chunk(_cursor_pos) pos_y = consts.get_y_pos_chunk(_cursor_pos) which_chunk = consts.get_curr_chunk( _cursor_pos) - self.entity_buffer.chunk_buffer.get_start_chunk_ind( ) function(pos_x, pos_y, which_chunk, self.entity_buffer.chunk_buffer, self.entity_buffer, _dt)
def right_click(self, _dt, _cursor_pos): if self.inventory.enabled: max_down = 40 * self.inventory.rows max_right = 40 * self.inventory.cols if self.mouse_pos[0] < max_right and self.mouse_pos[1] < max_down: curr_row = round(self.mouse_pos[1] / 40) - 1 curr_col = round(self.mouse_pos[0] / 40) - 1 which_item = self.inventory.get_item_at([curr_col, curr_row]) if curr_row >= 0 and curr_col >= 0 and which_item is not None: if self.sel_item[0] == None: self.sel_item[0] = which_item if self.sel_item[0] == self.inventory.get_item_at( [curr_col, curr_row]): # if self.sel_item[1] < consts.ITEM_ATTR[which_item][consts.item_attr.MAX_STACK]: to_add = 1 if self.key_state[pygame.KMOD_CTRL]: to_add = self.inventory.get_quantity_at( [curr_col, curr_row]) self.sel_item[1] += to_add self.inventory.rem_item_pos([curr_col, curr_row], to_add) else: function = consts.r_use_hand which_item = self.get_held_item() if which_item: function = consts.ITEM_ATTR[which_item][consts.item_attr.R_USE] pos_x = consts.get_x_pos_chunk(_cursor_pos) pos_y = consts.get_y_pos_chunk(_cursor_pos) which_chunk = consts.get_curr_chunk( _cursor_pos ) - self.entity_buffer.chunk_buffer.get_start_chunk_ind() function(pos_x, pos_y, which_chunk, self.entity_buffer.chunk_buffer, self.entity_buffer, _dt)
def get_tile(self, p): curr_chunk_ind = self.get_curr_chunk_ind(p) curr_chunk = self.chunk_buffer.chunks[curr_chunk_ind] tiles_at_y_pos = curr_chunk.blocks[consts.get_y_pos_chunk(p)] tile = tiles_at_y_pos[consts.get_x_pos_chunk(p)] return tile