def draw(self, grid, grid_editor, d_surf):
     if len(grid_editor.selected_blocks) == 1:
         k = next(iter(grid_editor.selected_blocks))
         points = block_grid_space_manager.calculate_block_points(
             k, grid.blocks.get(k), self.bgss)
         pygame.draw.polygon(d_surf, DEFAULT_SELECTED_COLOUR,
                             points.top_points)
         pygame.draw.lines(d_surf, DEFAULT_SELECTED_LINE_COLOUR, True,
                           points.top_points)
         for i in range(4):
             pygame.draw.circle(
                 d_surf, DEFAULT_SELECTED_POINT_COLOUR if i
                 in grid_editor.selected_points else DEFAULT_POINT_COLOUR,
                 int_tuple(points.top_points[i]), DEFAULT_POINT_RADIUS)
             pygame.draw.circle(d_surf,
                                DEFAULT_POINT_LINE_COLOUR,
                                int_tuple(points.top_points[i]),
                                DEFAULT_POINT_RADIUS,
                                width=1)
     else:
         for k in grid_editor.selected_blocks:
             points = block_grid_space_manager.calculate_block_points(
                 k, grid.blocks.get(k), self.bgss)
             pygame.draw.polygon(d_surf, DEFAULT_SELECTED_COLOUR,
                                 points.top_points)
             pygame.draw.lines(d_surf, DEFAULT_SELECTED_LINE_COLOUR, True,
                               points.top_points)
Esempio n. 2
0
    def testCalculateBlockPoints(self):
        block = mock.Mock()
        block.vertex_heights = [
            self.start_height, self.start_height, self.start_height,
            self.start_height
        ]

        left_point_bottom = (float(self.start_x - (self.block_width / 2)),
                             float(self.start_y))
        top_point_bottom = (float(self.start_x),
                            float(self.start_y - self.block_height / 2))
        right_point_bottom = (float(self.start_x + (self.block_width / 2)),
                              float(self.start_y))
        bottom_point_bottom = (float(self.start_x),
                               float(self.start_y + self.block_height / 2))

        left_point_top = (left_point_bottom[0], left_point_bottom[1] -
                          self.start_height * self.height_modifier)
        top_point_top = (top_point_bottom[0], top_point_bottom[1] -
                         self.start_height * self.height_modifier)
        right_point_top = (right_point_bottom[0], right_point_bottom[1] -
                           self.start_height * self.height_modifier)
        bottom_point_top = (bottom_point_bottom[0], bottom_point_bottom[1] -
                            self.start_height * self.height_modifier)

        result = block_grid_space_manager.calculate_block_points((0, 0), block,
                                                                 self.bgss)

        self.assertEqual([
            left_point_bottom, top_point_bottom, right_point_bottom,
            bottom_point_bottom
        ], result.base_points)
        self.assertEqual(
            [left_point_top, top_point_top, right_point_top, bottom_point_top],
            result.top_points)
Esempio n. 3
0
    def select(self, grid, pos):
        for item in reversed(list(grid.blocks.items())):
            points = block_grid_space_manager.calculate_block_points(
                item[0], item[1], self.bgss)

            if collision_utils.is_diamond_point_collision(
                    points.top_points[0], points.top_points[1],
                    points.top_points[2], points.top_points[3], pos):
                return item[0]
Esempio n. 4
0
    def draw_fill(self, grid, d_surf, colour_map={}):
        for k in grid.blocks:
            points = block_grid_space_manager.calculate_block_points(
                k, grid.blocks[k], self.bgss)

            front_points = [
                points.top_points[i] for i in [LEFT, BOTTOM, RIGHT]
            ] + [points.base_points[i] for i in [RIGHT, BOTTOM, LEFT]]

            pygame.draw.polygon(d_surf, colour_map.get(k, DEFAULT_TOP_COLOUR),
                                points.top_points)
            pygame.draw.polygon(d_surf, DEFAULT_SIDE_COLOUR, front_points)
Esempio n. 5
0
    def draw_mesh(self, grid, d_surf):
        for k in grid.blocks:
            points = block_grid_space_manager.calculate_block_points(
                k, grid.blocks[k], self.bgss)

            pygame.draw.lines(d_surf, DEFAULT_LINE_COLOUR, True,
                              points.top_points)
            pygame.draw.lines(d_surf, DEFAULT_LINE_COLOUR, True,
                              points.base_points)

            for i in range(4):
                pygame.draw.line(d_surf, DEFAULT_LINE_COLOUR,
                                 points.top_points[i], points.base_points[i])
Esempio n. 6
0
	def get_selected_point(self, grid, pos):
		for k in self.selected_blocks:
			points = block_grid_space_manager.calculate_block_points(k, grid.blocks.get(k), self.bgss)
			for i, top_point in enumerate(points.top_points):
				if collision_utils.is_circle_point_collision(top_point, 5, pos):
					return i
	def draw(self, grid, hoverer, d_surf):
		k = hoverer.hovered
		if k:
			points = block_grid_space_manager.calculate_block_points(k, grid.blocks[k], self.bgss)
			pygame.draw.polygon(d_surf, DEFAULT_HOVER_COL, points.top_points)
			pygame.draw.lines(d_surf, DEFAULT_LINE_COLOUR, True, points.top_points)