Beispiel #1
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
Beispiel #2
0
    def touching_poly(self, poly):
        poly_lines = [(dot1, dot2) for dot1, dot2 in zip(poly, poly[1:])]
        x1, y1, x2, y2 = int(self.x) - 10, int(self.y) - 10, \
                         int(self.x) + 10, int(self.y) + 10
        qix_box = game_utils._bounding_box((x1, y1), (x2, y2))

        # first do a cheap run on the bounding box
        if len(poly_lines) > 1:
            (xb1, yb1), (xb2, yb2) = game_utils.box_range(poly)
            if not any((xb1 <= x <= xb2 and yb1 <= y <= yb2 for (x, y) in qix_box)):
                return False

        for line1 in zip(qix_box, qix_box[1:]):
            for line2 in poly_lines:
                if game_utils.intersection(line1, line2):
                    return True
Beispiel #3
0
    def _on_enter_frame(self, scene, context):
        if not self._debug:
            return

        g = graphics.Graphics(context)
        to_scene = self.board.to_scene_coords
        g.set_line_style(width=3)
        """
        for qix in self.board.qix:
            g.move_to(*to_scene(qix.x, qix.y))
            g.line_to(*to_scene(qix.next_x, qix.next_y))
        g.stroke("#f00")
        """

        for rect in self.board.game_rects:
            (x1,y1), (x2, y2) = game_utils.box_range(rect)
            (x1,y1), (x2, y2) = to_scene(x1, y1), to_scene(x2, y2)
            g.rectangle(x1, y1, x2-x1, y2-y1)
        g.fill_stroke("#0f0", "#fff", 0.3)