Beispiel #1
0
    def close_claim(self, poly, speed, game):
        inside, outside = game_utils.cut_poly(self.game_area, poly)

        # we will triangulate only one of the guys
        # then we check if it is the bigger portion (last known area minus new)

        total_area = game_utils.total_area([self._start_game_area])
        prev_remaining = total_area - game.stats['claimed_area']

        rects_out = game_utils.triangulate(outside) or []

        qixes = [qix for qix in self.qix if not qix.claimed]
        # flip sides if the qix is not in the game area - can't claim
        # qix space
        claimed_qix = []
        for qix in qixes:
            if not game_utils.in_area((qix.x, qix.y), rects_out, on_line=True):
                claimed_qix.append(qix)

        claimed_area = prev_remaining - game_utils.total_area(rects_out)
        available_area = prev_remaining - claimed_area

        if (len(claimed_qix) > len(qixes) / 2.0) or (available_area < claimed_area and len(claimed_qix) >= len(qixes)):
            # outside normally should be bigger than inside
            # exception is when we have more qix on the smaller patch
            inside, outside = outside, inside
            rects_out = game_utils.triangulate(outside) or []
            claimed_area = prev_remaining - game_utils.total_area(rects_out)


        for qix in qixes:
            if not game_utils.in_area((qix.x, qix.y), rects_out, on_line=True):
                qix.claimed = True

        self.game_rects = rects_out
        self.game_area = outside
        self.game_area_path.points = outside

        claimed = sprites.ClaimedPoly(inside, speed)
        self.claimed_polys_containter.add_child(claimed)
        claimed.appear()
        self.claimed_polys.append((inside, 1))

        for qix in self.qix:
            # make sure they are not easing some place nasty
            qix.next_target()

        game.update_score(claimed_area, speed)
Beispiel #2
0
    def __init__(self, start_area, sparks=2, qix=1):
        graphics.Sprite.__init__(self, snap_to_pixel=False)

        # outer box - always relevant
        self._start_game_area = start_area

        #: the current available game area
        self.game_area = start_area
        self.scale_x, self.scale_y = 1, 1

        (x, y), (x2, y2) = game_utils.box_range(self.game_area)
        self.width, self.height = x2 - x, y2 - y

        self.claimed_polys_containter = graphics.Sprite()
        self.add_child(self.claimed_polys_containter)


        self.current_polygon = []

        self.current_polygon_path = graphics.Polygon([], stroke="#eee", line_width=3)
        self.add_child(self.current_polygon_path)

        self.game_area_path = graphics.Polygon([], stroke="#eee", line_width=3)
        self.add_child(
            graphics.Polygon(self.game_area, stroke="#eee", line_width=3, z_order=500),
            self.game_area_path,
        )


        self._current_direction = None

        self.claimed_polys = []



        self.cube = sprites.Cubic(x=x2 / 2, y = y2)
        self.add_child(self.cube)

        self.sparks_waiting = []
        self.sparks = []
        self.spark_throttle_secs = 1.5
        for i in range(sparks):
            self.sparks_waiting.append(sprites.Spark(x=x2 / 2, y=y, speed=2 + (i / 5.0), clockwise = i % 2 ==0))


        self.qix = []
        qix_colors = ["#afe", "#FEF4AF"]
        for i in range(qix):
            self.qix.append(sprites.Qix(x=x2 / 2,
                                        y=y2 / 2,
                                        angle=(i * 360.0 / qix),
                                        color=qix_colors[i % len(qix_colors)]))

        self.add_child(*self.qix)

        self.game_rects = game_utils.triangulate(self.game_area)

        self.level_start = None