Пример #1
0
def RingSection(start, end, inner_radius, outer_radius):
    """Draw a section of a ring. Useful for circular “progressbars”.

    `start` and `end` are angles in radians
    `inner_radius` and `outer_radius` are in pixels
    The ring section is centered at (0, 0)
    """
    num = 64
    for t in range(int(start * num), int(end * num)):
        a = t * pi * 2 / num
        b = (t + 1) * pi * 2 / num
        Triangle(points=(
            cos(a) * inner_radius,
            sin(a) * inner_radius,
            cos(a) * outer_radius,
            sin(a) * outer_radius,
            cos(b) * inner_radius,
            sin(b) * inner_radius,
        ))
        Triangle(points=(
            cos(a) * outer_radius,
            sin(a) * outer_radius,
            cos(b) * inner_radius,
            sin(b) * inner_radius,
            cos(b) * outer_radius,
            sin(b) * outer_radius,
        ))
Пример #2
0
 def show(self):
     with self.canvas:
         if not self.is_on_board():
             self.object_on_board = Triangle(points=self.points)
             self.state = True
         else:
             self.canvas.remove(self.object_on_board)
             self.object_on_board = Triangle(points=self.points)
Пример #3
0
 def show(self):
     """
     Actual rendering of the snake's head. The representation is simply a
     Triangle oriented according to the direction of the object.
     """
     with self.canvas:
         if not self.is_on_board():
             self.object_on_board = Triangle(points=self.points)
             self.state = True  # object is on board
         else:
             # if object is already on board, remove old representation
             # before drawing a new one
             self.canvas.remove(self.object_on_board)
             self.object_on_board = Triangle(points=self.points)
Пример #4
0
    def car(self, space):
        pos = Vec2d(100, 100)

        wheel_color = 0.2, 0.86, 0.47
        shovel_color = 0.86, 0.47, 0.2
        mass = 100
        radius = 25
        moment = pymunk.moment_for_circle(mass, 20, radius)
        wheel1_b = pymunk.Body(mass, moment)
        wheel1_s = pymunk.Circle(wheel1_b, radius)
        wheel1_s.friction = 1.5
        wheel1_s.color = wheel_color
        space.add(wheel1_b, wheel1_s)

        mass = 100
        radius = 25
        moment = pymunk.moment_for_circle(mass, 20, radius)
        wheel2_b = pymunk.Body(mass, moment)
        wheel2_s = pymunk.Circle(wheel2_b, radius)
        wheel2_s.friction = 1.5
        wheel2_s.color = wheel_color
        space.add(wheel2_b, wheel2_s)

        mass = 100
        size = (50, 30)
        moment = pymunk.moment_for_box(mass, size)
        chassi_b = pymunk.Body(mass, moment)
        chassi_s = pymunk.Poly.create_box(chassi_b, size)
        space.add(chassi_b, chassi_s)

        vs = [(0, 0), (0, -45), (25, -45)]
        shovel_s = pymunk.Poly(chassi_b, vs, transform=pymunk.Transform(tx=85))
        shovel_s.friction = 0.5
        shovel_s.color = shovel_color
        space.add(shovel_s)

        wheel1_b.position = pos - (55, 0)
        wheel2_b.position = pos + (55, 0)
        chassi_b.position = pos + (0, 25)

        space.add(
            pymunk.PinJoint(wheel1_b, chassi_b, (0, 0), (-25, -15)),
            pymunk.PinJoint(wheel1_b, chassi_b, (0, 0), (-25, 15)),
            pymunk.PinJoint(wheel2_b, chassi_b, (0, 0), (25, -15)),
            pymunk.PinJoint(wheel2_b, chassi_b, (0, 0), (25, 15)),
        )

        speed = -4
        space.add(
            pymunk.SimpleMotor(wheel1_b, chassi_b, speed),
            pymunk.SimpleMotor(wheel2_b, chassi_b, speed),
        )
        with self.canvas:
            Color(*wheel_color)
            wheel1_s.ky = self.ellipse_from_circle(wheel1_s)
            Color(*wheel_color)
            wheel2_s.ky = self.ellipse_from_circle(wheel2_s)
            Color(*shovel_color)
            chassi_s.ky = Quad(points=self.points_from_poly(chassi_s))
            shovel_s.ky = Triangle(points=self.points_from_poly(shovel_s))
Пример #5
0
    def draw_figure(self):
        x1, y1 = self.float_layout.pos
        x2, y2 = self.float_layout.size
        x2 += x1
        y2 += y1

        with self.canvas:
            Color(0.92, 0.71, 0.36)
            Rectangle(pos=[x1 + 100, y1 + 5], size=[100, 100])

            Color(0.23, 0.15, 0)
            Rectangle(pos=[x1 + 180, y1 + 105], size=[10, 100])

            Color(0.11, 0.12, 0.84)
            Triangle(points=[
                x1 + 80, y1 + 105, x1 + 220, y1 + 105, x1 + 150, y1 + 200
            ])

            Color(1, 1, 0)
            Ellipse(pos=[x1 + 400, y2 - 100])

            Color(0.10, 0.36, 0)

            for i in range(int(x2 - x1)):
                Line(points=[
                    x1 + i, y1, x1 + random.randint(-10, 10) + i, y1 +
                    random.randint(6, 19)
                ])
Пример #6
0
    def on_touch_down(self, touch):
        self.set_color(self.color_paint)
        if Widget.on_touch_down(self, touch):
            return

        with self.canvas:
            if 45 < touch.y < self.height - 45 and 25 < touch.x < self.width - 25:
                if self.shape == 1:
                    touch.ud['current_line'] = Line(
                        points=(touch.x - self.defaut_size / 2,
                                touch.y - self.defaut_size / 2),
                        width=self.line_width)
                elif self.shape == 2:
                    self.start_x = touch.x - self.defaut_size / 2
                    self.start_y = touch.y - self.defaut_size / 2
                    touch.ud['current_ellipse'] = Ellipse(
                        pos=(touch.x - self.defaut_size / 2,
                             touch.y - self.defaut_size / 2),
                        size=(self.defaut_size, self.defaut_size))
                elif self.shape == 3:
                    self.start_x = touch.x
                    self.start_y = touch.y - self.defaut_size
                    touch.ud['current_rectangle'] = Rectangle(
                        pos=(touch.x, touch.y - self.defaut_size),
                        size=(self.defaut_size, self.defaut_size))
                elif self.shape == 4:
                    touch.ud['current_triangle'] = Triangle(
                        points=(touch.x, touch.y,
                                touch.x + self.defaut_size / 2,
                                touch.y + self.defaut_size,
                                touch.x + self.defaut_size, touch.y))
Пример #7
0
    def drawUserIcon(self, rotation, canvas, mobile):
        # x = n*cos(theta)
        # y = n*sin(theta)
        print 'Trying to draw user...'
        x = self.pixel_coords.getX()
        #y = HUD_HEIGHT - self.pixel_coords.getY() #Corrects for if origin is top left
        y = self.pixel_coords.getY()

        # Rotate according to icon heading
        user_heading = rotation
        if (mobile == True):
            self.mobile = True
        else:
            self.mobile = False
        #polygon_coords = self.rotateIcon(Point2D(x,y), polygon_coords)

        # Determine coords of polygon
        icon_coords = self.getUserIconShapeCoords(x, y, float(user_heading))

        # Draw the icon
        with canvas:
            Color(.5, 1, 0, mode='rgb')
            if not self.mobile:
                triangle = ObjectProperty(None)
                triangle = Triangle(points=[
                    icon_coords[0][0], icon_coords[0][1], icon_coords[1][0],
                    icon_coords[1][1], icon_coords[2][0], icon_coords[2][1]
                ])
            else:
                pass

        print 'Done drawing user icon'
Пример #8
0
    def build(self):
        from kivy.garden.smaa import SMAA

        Window.bind(on_keyboard=self._on_keyboard_handler)

        self.smaa = SMAA()
        self.effects = [self.smaa, Widget()]
        self.effect_index = 0
        self.label = Label(text='SMAA', top=Window.height)
        self.effect = effect = self.effects[0]
        self.root = FloatLayout()
        self.root.add_widget(effect)

        if 0:
            from kivy.graphics import Color, Rectangle
            wid = Widget(size=Window.size)
            with wid.canvas:
                Color(1, 1, 1, 1)
                Rectangle(size=Window.size)
            effect.add_widget(wid)

        if 1:
            #from kivy.uix.image import Image
            #root.add_widget(Image(source='data/logo/kivy-icon-512.png',
            #                      size=(800, 600)))

            filenames = sys.argv[1:]
            if not filenames:
                filenames = glob(join(dirname(__file__), '*.svg'))

            for filename in filenames:
                svg = SvgWidget(filename)
                effect.add_widget(svg)

            effect.add_widget(self.label)
            svg.scale = 5.
            svg.center = Window.center

        if 0:
            wid = Scatter(size=Window.size)
            from kivy.graphics import Color, Triangle, Rectangle
            with wid.canvas:
                Color(0, 0, 0, 1)
                Rectangle(size=Window.size)
                Color(1, 1, 1, 1)
                w, h = Window.size
                cx, cy = w / 2., h / 2.
                Triangle(points=[cx - w * 0.25, cy - h * 0.25,
                                 cx, cy + h * 0.25,
                                 cx + w * 0.25, cy - h * 0.25])
            effect.add_widget(wid)

        if 0:
            from kivy.uix.button import Button
            from kivy.uix.slider import Slider
            effect.add_widget(Button(text='Hello World'))
            effect.add_widget(Slider(pos=(200, 200)))

        control_ui = Builder.load_string(smaa_ui)
        self.root.add_widget(control_ui)
Пример #9
0
 def eleccion(self, obj, st):
     print("Pos X: %g, Pos Y: %g" % (st.x, st.y))
     ca, cb, cc = .5, .5, .6
     a, b = 150, 45
     radio = 50
     with self.pintor.canvas:
         Color(ca, cb, cc, mode='hsv')
         Triangle(points=[0, 0, 100, 100, 80, 20])
Пример #10
0
    def __init__(self, edge, canvas):
        self.edge = edge
        self.canvas = canvas
        self._is_tail_selected = None
        self.color = Color(*EDGE_COLOR)

        super().__init__(width=EDGE_WIDTH)

        self.head_color = Color(*HEAD_COLOR)
        self.head = Triangle(points=(0, 0, 0, 0, 0, 0))
Пример #11
0
    def __init__(self, level_names, labels, name_dict, scores):
        super(PreviewDisplay, self).__init__()
        self.level_names = level_names
        self.labels = labels
        self.name_dict = name_dict
        self.scores = scores

        self.pointer = 0
        self.previews = []
        self.x = 340
        self.y = 350

        self.left_color = Color(rgb=(1, 1, 1))
        self.right_color = Color(rgb=(1, 1, 1))

        self.left_triangle = Triangle(points=(310, 230, 265, 260, 310, 290))
        self.right_triangle = Triangle(points=(1070, 230, 1115, 260, 1070,
                                               290))

        self.set_previews()
Пример #12
0
 def build(self, center, needleSize):
     """
     building the needle with two Triangles of different color
     """
     self.pos = center - needleSize / 2.
     self.size = needleSize
     self.size_hint = [None, None]
     with self.canvas:
         Color(1., 0, 0)
         needleTP1 = Vector(needleSize[0] / 2., needleSize[1])
         needleTP2 = Vector(needleSize[0] / 2., 0)
         needleTP3 = Vector(-needleSize[0], needleSize[1] / 2.)
         needlePoints = (needleTP1[0], needleTP1[1], needleTP2[0],
                         needleTP2[1], needleTP3[0], needleTP3[1])
         self.needleT1 = Triangle(points=needlePoints)
         Color(0.5, 0.5, 0.5)
         needleTP3 = Vector(2 * needleSize[0], needleSize[1] / 2.)
         needlePoints = (needleTP1[0], needleTP1[1], needleTP2[0],
                         needleTP2[1], needleTP3[0], needleTP3[1])
         self.needleT2 = Triangle(points=needlePoints)
Пример #13
0
 def draw_field(self):
     for ov in self.field:
         ov = self.map_ov(ov)
         e = ov.v.rotate(90).normalize()
         tri_points = tuple(
             ov.end()) + tuple(ov.p + 2 * e) + tuple(ov.p - 2 * e)
         tri = Triangle(points=tri_points)
         dot = Ellipse(pos=(ov.p - Vector(2, 2)), size=(5, 5))
         self.canvas.add(ov.color)
         self.canvas.add(tri)
         self.canvas.add(dot)
 def draw(self):
     self.wid.canvas.clear()
     with self.wid.canvas:
         for i in self.triangles:
             Color(*i.color)
             Triangle(points=([
                 i.vertex[0][0] + self.wid.x, i.vertex[0][1] +
                 self.wid.y, i.vertex[1][0] + self.wid.x, i.vertex[1][1] +
                 self.wid.y, i.vertex[2][0] + self.wid.x, i.vertex[2][1] +
                 self.wid.y
             ]))
             Color((1, 1, 1))
             if self.show_norms:
                 Bezier(points=[
                     (i.vertex[0][0] + i.vertex[1][0]) / 2 +
                     self.wid.x, (i.vertex[0][1] + i.vertex[1][1]) / 2 +
                     self.wid.y, (i.vertex[0][0] + i.vertex[1][0]) / 2 +
                     i.normal[0][0] * 20 +
                     self.wid.x, (i.vertex[0][1] + i.vertex[1][1]) / 2 +
                     i.normal[0][1] * 20 + self.wid.y
                 ])
                 Bezier(points=[
                     (i.vertex[1][0] + i.vertex[2][0]) / 2 +
                     self.wid.x, (i.vertex[1][1] + i.vertex[2][1]) / 2 +
                     self.wid.y, (i.vertex[1][0] + i.vertex[2][0]) / 2 +
                     i.normal[1][0] * 20 +
                     self.wid.x, (i.vertex[1][1] + i.vertex[2][1]) / 2 +
                     i.normal[1][1] * 20 + self.wid.y
                 ])
                 Bezier(points=[
                     (i.vertex[2][0] + i.vertex[0][0]) / 2 +
                     self.wid.x, (i.vertex[2][1] + i.vertex[0][1]) / 2 +
                     self.wid.y, (i.vertex[2][0] + i.vertex[0][0]) / 2 +
                     i.normal[2][0] * 20 +
                     self.wid.x, (i.vertex[2][1] + i.vertex[0][1]) / 2 +
                     i.normal[2][1] * 20 + self.wid.y
                 ])
         for i in self.blocks:
             Color(*i.color)
             Rectangle(pos=(i.pos[0] + self.wid.x, i.pos[1] + self.wid.y),
                       size=i.size)
         for i in self.particles:
             if i.hover or i.id == self.selected:
                 Color(1, 1, 1)
                 Ellipse(pos=(i.pos[0] + self.wid.x - 2,
                              i.pos[1] + self.wid.y - 2),
                         size=(i.size[0] + 4, i.size[1] + 4))
             Color(*i.color)
             Ellipse(pos=(i.pos[0] + self.wid.x, i.pos[1] + self.wid.y),
                     size=i.size)
Пример #15
0
    def boxfloor(self, space):
        mass = 10
        vs = [(-50, 30), (60, 22), (-50, 22)]

        moment = pymunk.moment_for_poly(mass, vs)
        b = pymunk.Body(mass, moment)
        s = pymunk.Poly(b, vs)
        s.friction = 1
        s.color = 0, 0, 0
        b.position = 600, 250

        space.add(b, s)
        with self.canvas:
            Color(0.2, 0.2, 0.2)
            s.ky = Triangle(points=self.points_from_poly(s))
Пример #16
0
    def on_touch_down(self, touch):
        if touch.is_double_tap:
            x = touch.x
            y = touch.y
            cType = 0
            cPiece = 0
            cDist = math.sqrt((x - self.board_cnt[0][0][0])**2 +
                              (y - self.board_cnt[0][0][1])**2)
            for i in range(len(self.board_cnt)):
                for j in range(len(self.board_cnt[i])):
                    dist = math.sqrt((x - self.board_cnt[i][j][0])**2 +
                                     (y - self.board_cnt[i][j][1])**2)
                    if dist < cDist:
                        cDist = dist
                        cType = i
                        cPiece = j

            print('> Type {} Pos {}'.format(cType, cPiece))
            # Actions
            if self.mark is None:
                self.bdb.canvas.clear()
                with self.bdb.canvas:
                    Color(0, 0, 0, .3)
                    self.mark = Triangle(points=self.board_pos[cType][cPiece])
                    self.last_cType = cType
                    self.last_cPiece = cPiece

            else:
                self.mark = None
                self.bdb.canvas.clear()
                anim = Animation(pos=self.board_cnt[cType][cPiece],
                                 duration=1.)
                ccType = 0
                ccPiece = 0
                x = self.board_cnt[self.last_cType][self.last_cPiece][0]
                y = self.board_cnt[self.last_cType][self.last_cPiece][1]
                cDist = math.sqrt((x - self.pieces[0][0].pos[0])**2 +
                                  (y - self.pieces[0][0].pos[1])**2)
                for i in range(len(self.pieces)):
                    for j in range(len(self.pieces[i])):
                        dist = math.sqrt((x - self.pieces[i][j].pos[0])**2 +
                                         (y - self.pieces[i][j].pos[1])**2)
                        if dist < cDist:
                            cDist = dist
                            ccType = i
                            ccPiece = j
                anim.start(self.pieces[ccType][ccPiece])
Пример #17
0
    def draw(self, *args):

        if not self.synapse:
            if self.type:
                color = [1, 0, 0]  # RED
            else:
                color = [0, 0, 1]  # BLUE
            colorWeight = WEIGHT_COLOR
        elif self.synapse:
            color = [0.8, 0.8, 0.8]  # White
            colorWeight = [0.8, 0.8, 0.8]

        fromNeuron = self.fromNeuron.center
        targetNeuron = self.targetNeuron.center
        neuronSize = (self.fromNeuron.width / 2) + 2
        markerSize = 6

        # Angled Line:
        angle = atan2((targetNeuron[1] - fromNeuron[1]),
                      (targetNeuron[0] - fromNeuron[0]))
        fromX = fromNeuron[0] + neuronSize * cos(angle)
        fromY = fromNeuron[1] + neuronSize * sin(angle)
        toX = targetNeuron[0] - (neuronSize + markerSize) * cos(angle)
        toY = targetNeuron[1] - (neuronSize + markerSize) * sin(angle)

        # Arrow marker...POINTS (arrow0, arrow1, arro2):
        rotation = math.degrees(math.atan2(fromY - toY, toX - fromX)) + 90
        arrow0_X = (toX + markerSize * math.sin(math.radians(rotation)))
        arrow0_Y = (toY + markerSize * math.cos(math.radians(rotation)))
        arrow1_X = (toX + markerSize * math.sin(math.radians(rotation - 120)))
        arrow1_Y = (toY + markerSize * math.cos(math.radians(rotation - 120)))
        arrow2_X = (toX + markerSize * math.sin(math.radians(rotation + 120)))
        arrow2_Y = (toY + markerSize * math.cos(math.radians(rotation + 120)))

        self.canvas.clear()
        with self.canvas:
            Color(*color)
            Line(points=[(fromX, fromY), (toX, toY)], width=0.6)
            Triangle(points=[
                arrow0_X, arrow0_Y, arrow1_X, arrow1_Y, arrow2_X, arrow2_Y
            ])
            Color(*colorWeight)
            t = self.weight
            Cx = fromX * (1 - t) + toX * t
            Cy = fromY * (1 - t) + toY * t

            Line(points=[(fromX, fromY), (Cx, Cy)], width=2.8, cap='square')
Пример #18
0
    def draw(self, x, y):
        x1, y1 = self.init_pos

        if self.draw_triangle is not None:
            mouse_x_y = x, y

            vertices = utils.constructTriangleFromLine(self.init_pos,
                                                       mouse_x_y)
            self.draw_triangle.points = vertices
            self.draw_altitude.points = [x, y, x1, y1]
        else:
            with self.game.canvas:
                self.color = utils.random_color()
                Color(*self.color, mode="rgba")
                self.draw_triangle = Triangle(
                    points=utils.get_triangle_points(x1, y1, x, y))
                Color(*utils.random_color(), mode="rgba")
                self.draw_altitude = \
                    Line(points=[x1, y1, x, y],
                         width=LINE_WIDTH, cap="square")
Пример #19
0
    def updateScreen(self):
        self.canvas.clear()
        self.clear_widgets()
        with self.canvas:
            i = 0
            for each in self.structure.triangulation:
                points = []
                for point in each.vertices:
                    for dim in point:
                        points.append(dim)
                # print(points)
                Color(rgba=each.color)
                i = (i + 1) % len(COLORS)
                Triangle(points=points)

            Color(0, 0, 0)
            d = 3
            for each in self.polygons:
                self.canvas.add(each.line)

            Color(0., 0., 0.)
            for touch in self.points:
                Ellipse(pos=(touch[0] - d / 2, touch[1] - d / 2), size=(d, d))
Пример #20
0
    def add_triangle(self, vertices, random_color):
        vbackup = vertices
        vertices = [int(v) for v in vertices]
        vertices = zip(vertices[::2], vertices[1::2])
        center = cymunk.util.calc_center(vertices)
        body = cymunk.Body(100, cymunk.moment_for_poly(100, vertices))
        body.position.x = center[0]
        body.position.y = center[1]
        triangle = cymunk.Poly(body, vertices)
        triangle.elasticity = 0.6
        triangle.friction = FRICTION
        self.space.add(body, triangle)

        with self.parent.canvas.before:
            color = Color(*random_color, mode="rgba")
            rot = Rotate(angle=0, axis=(0, 0, 1), origin=center)
            triangle_shape = Triangle(points=vbackup)
            unrot = Rotate(0, (0, 0, 1), origin=center)
        body.data = {
            "color": color,
            "instruction": [triangle_shape, rot, unrot],
            "type": TRIANGLE_TYPE,
            "shapes": [triangle],
        }
Пример #21
0
    def draw(self):
        """Draw the tower turret/markings/menu

        (The tower base is drawn in TowersGame as a background)
        """
        self.canvas.clear()
        if not self.parent:
            return

        with self.canvas:
            PushMatrix()
            # Center coordinate system at tower center, and rotate
            # so that 0 = away from player's home
            Translate(int(self.center[0]), int(self.center[1]), 0)
            if self.side:
                Rotate(180, 0, 0, 1)

            # Draw the tower markings
            if self.level > 1:
                Color(1, 1, 1, 0.9)
                w = self.parent.cell_width * 1.2
                h = self.parent.cell_height * 1.2
                if self.level == MAX_LEVEL:
                    # Level 6: big white rectangle
                    Rectangle(pos=(-w, -h), size=(2 * w, 2 * h))
                else:
                    # Levels 2 <= n <= 5: (n - 1) small triangles in corners
                    PushMatrix()
                    for i in range(self.level - 1):
                        Triangle(points=(w, h, w / 2, h, w, h / 2))
                        Rotate(90, 0, 0, 1)
                    PopMatrix()

            # If upgrading, draw a circular progress bar
            # showing upgrade_spent / upgrade_cost
            if self.upgrading_direction:
                fract_done = self.upgrade_spent / self.upgrade_cost
                Color(0.35, 0.35, 0.35, 0.25)
                RingSection(fract_done, 1, self.parent.cell_size * 4,
                            self.parent.cell_size * 6)
                Color(0.35, 0.75, 0.35, 0.5)
                RingSection(0, fract_done, self.parent.cell_size * 4,
                            self.parent.cell_size * 6)

            if self.touch_uid:
                Rotate(270, 0, 0, 1)

                # If touched, visualize the tower's range
                if self.level:
                    center = self.center
                    Color(1, 1, 1, 0.1)
                    FilledCircle((0, 0), self.parent.cell_size * self.range)
                    Color(1, 1, 1, 0.2)
                    HollowCircle((0, 0), self.parent.cell_size * self.range)

                # The upgrade/sell menu
                if self.menu_visible:
                    show_sell = self.level and self.upgrade_touch_position < 1
                    show_upgrade = (self.level < MAX_LEVEL
                                    and self.upgrade_touch_position > -1)

                    # Backgrounds
                    clamped_g = clamp(self.upgrade_touch_position, -1, 1)
                    if show_sell:
                        Color(0.75, 0.45, 0.35, 0.6 - clamped_g * 0.4)
                        RingSection(5 / 8, 7 / 8, self.parent.cell_size * 2.5,
                                    self.parent.cell_size * 6.5)

                    if show_upgrade:
                        Color(0.45, 0.75, 0.35, 0.6 + clamped_g * 0.4)
                        RingSection(1 / 8, 3 / 8, self.parent.cell_size * 2.5,
                                    self.parent.cell_size * 6.5)

                    # Labels
                    Color(0, 0, 0)
                    if show_upgrade:
                        # "Build" at level 0 since the tower's not really built
                        # yet (no money's been spent on it)
                        if self.level:
                            text = 'Upgrade'
                        else:
                            text = 'Build'
                        Label(text=u"%s\n€ %s" % (text, self.upgrade_cost),
                              pos=(-int(self.parent.cell_size * 2),
                                   int(self.parent.cell_size * 3)),
                              size=(int(self.parent.cell_size * 4),
                                    int(self.parent.cell_size * 3)),
                              halign='center',
                              font_size=10,
                              color=(0, 0, 0))
                    if show_sell:
                        if self.level:
                            Label(text=u"Sell\n€ %s" % self.sell_cost,
                                  pos=(-int(self.parent.cell_size * 2),
                                       -int(self.parent.cell_size * 6)),
                                  size=(int(self.parent.cell_size * 4),
                                        int(self.parent.cell_size * 3)),
                                  halign='center',
                                  font_size=10,
                                  color=(0, 0, 0))
            PopMatrix()
        self.draw_shot()
Пример #22
0
    def __init__(self, **kwargs):
        self.canvas = Canvas()

        window_width = Window.width
        window_height = Window.height

        aspect = window_width / float(window_height)

        center_x = window_width / 2.
        center_y = window_height / 2.

        element_size = window_width

        with self.canvas:
            self.fbo = Fbo(size=self.size, with_depthbuffer=True)
            self.fbo_color = Color(1, 1, 1, 1)
            self.fbo_rects = (
                StencilPush(),
                Triangle(points=(
                    0,
                    0,
                    center_x * 1.5,
                    window_height,
                    0,
                    window_height,
                )),
                StencilUse(),
                Rotate(angle=-90,
                       axis=(0, 0, 1),
                       origin=(center_x, window_height * 2 / 3.)),
                Rectangle(pos=(center_x - element_size / 2., -5),
                          size=(element_size, element_size / aspect),
                          texture=self.texture),
                Rotate(angle=90,
                       axis=(0, 0, 1),
                       origin=(center_x, window_height * 2 / 3.)),
                StencilUnUse(),
                Triangle(points=(
                    0,
                    0,
                    center_x * 1.5,
                    window_height,
                    0,
                    window_height,
                )),
                StencilPop(),
                StencilPush(),
                Triangle(points=(
                    window_width,
                    0,
                    center_x * .5,
                    window_height,
                    window_width,
                    window_height,
                )),
                StencilUse(),
                Rotate(angle=90,
                       axis=(0, 0, 1),
                       origin=(center_x, window_height * 2 / 3.)),
                Rectangle(pos=(center_x - element_size / 2., -5),
                          size=(element_size, element_size / aspect),
                          texture=self.texture),
            )

            Rotate(angle=-90,
                   axis=(0, 0, 1),
                   origin=(center_x, window_height * 2 / 3.))

            StencilUnUse()
            Triangle(points=(
                window_width,
                0,
                center_x * .5,
                window_height,
                window_width,
                window_height,
            ))
            StencilPop()

            StencilPush()
            Triangle(points=(
                0,
                0,
                window_width,
                0,
                center_x,
                window_height * 2 / 3.,
            ))
            StencilUse()

            if self.texture:
                self.texture.flip_horizontal()
            self.mirrored_rect = Rectangle(pos=(center_x - element_size / 2.,
                                                0),
                                           size=(element_size,
                                                 element_size / aspect),
                                           texture=self.texture)

            StencilUnUse()
            Triangle(points=(
                0,
                0,
                window_width,
                0,
                center_x,
                window_height * 2 / 3.,
            ))
            StencilPop()

        with self.fbo:
            ClearColor(0, 0, 0, 0)
            ClearBuffers()

        self.texture = self.fbo.texture
        super(HoloStandLayout, self).__init__(**kwargs)
Пример #23
0
 def draw_triangle(x1: float, y1: float, x2: float, y2: float, x3: float,
                   y3: float):
     """ 
     """
     Triangle(points=(x1, y1, x2, y2, x3, y3))
Пример #24
0
    def __init__(self, song, part, **kwargs):
        super(MainWidgetPractice, self).__init__(**kwargs)

        # Set terminal color to white
        Window.clearcolor = (.8, .8, .8, .8)

        self.timelabel = topright_label(
            (Window.width * 0.84, Window.height * 0.81))
        self.add_widget(self.timelabel)

        self.scorelabel = topright_label(
            (Window.width * 0.83, Window.height * 0.87))
        self.add_widget(self.scorelabel)

        self.streaklabel = center_label()
        self.add_widget(self.streaklabel)

        self.name = name_label()
        self.add_widget(self.name)

        self.next_phrase_label = center_label()
        self.add_widget(self.next_phrase_label)

        self.clock = Clock()
        self.clock.stop()
        self.gametime = -SCREEN_TIME
        self.gameon = False

        self.old_cursor_y = 1
        self.filter_rate = 0.4

        # Display user's cursor
        self.cursorcol = Color(.6, .6, .6)
        self.canvas.add(self.cursorcol)
        self.user = Triangle(
            points=[NOW_PIXEL - 60, -30, NOW_PIXEL - 60, 30, NOW_PIXEL, 0])
        self.canvas.add(self.user)

        # # Add particle system, which is used in BeatMatchDisplay when user sings the correct pitch.
        self.ps = ParticleSystem('particle/particle.pex')
        self.add_widget(self.ps)

        # Display screen when starting game.
        # self.name.text = "[color=000000][b]ACAHERO[/b]"
        self.scorelabel.text = "[b]color=000000]SCORE: 0[/b]"
        self.timelabel.text = "[b]TIME: %.2f[/b]" % self.gametime
        # self.streaklabel.text = "[color=000000][b]keys[/b]\n[i]p:[/i] [size=30]play | pause[/size]"

        self.gems_txt, self.barlines_txt, self.beats_txt = getDisplayFiles(
            song, part)

        song_data = SongData()
        song_data.read_data(self.gems_txt, self.barlines_txt, self.beats_txt)
        self.barlineData = song_data.barline_data
        self.lanes = song_data.lanes

        self.phrases = create_phrase_song_data(song_data)
        self.phrase_num = 0
        self.passing = True

        current_phrase = self.phrases[self.phrase_num]
        self.end_time = current_phrase.end_time

        self.healthbar = HealthBar()
        self.progress = ProgressBar(len(self.phrases))
        self.display = BeatMatchDisplay(self.phrases[0], self.ps, RATE)
        self.canvas.add(self.healthbar)
        self.canvas.add(self.progress)
        self.canvas.add(self.display)

        self.bg_filename, self.part_filename = getAudioFiles(song, part)
        self.audio = PhraseAudioController(self.bg_filename,
                                           self.part_filename,
                                           self.receive_audio,
                                           current_phrase.start_time,
                                           current_phrase.phrase_length)

        self.player = PhrasePlayer(self.phrases[0], self.display, self.audio,
                                   PitchDetector())

        self.display.draw_objects()
Пример #25
0
    def __init__(self, **kwargs):
        super(BizingoBoard, self).__init__(**kwargs)
        with self.canvas:

            # default parameters
            self.triangle_size = 50
            self.circle_radius = 15
            self.mouse_pos = (0, 0)
            self.mark = None
            self.last_cType = 0
            self.last_cPiece = 0

            # variables
            self.board_obj = [[], []]
            self.board_pos = [[], []]
            self.board_cnt = [[], []]
            self.pieces = [[], []]

            # board area
            Color(203 / 255, 236 / 255, 215 / 255)
            self.board_area = RoundedRectangle(pos=(60, 60),
                                               size=(600, 600),
                                               radius=[10])
            self.game_name_label = Label(
                text="B I Z I N G O",
                pos=(310, 640),
                font_size=60,
                font_name='fonts/comicate.ttf'
            )  # fonts: comicate, grasping, outwrite, valuoldcaps
            base_x = self.board_area.pos[0] + 50
            base_y = self.board_area.pos[1] + 80

            # type 1 triangles
            Color(255 / 255, 253 / 255, 254 / 255)
            for element in self.generate_triangles_type_1(
                    base_x, base_y, self.triangle_size):
                self.board_obj[0].append(Triangle(points=element))
                self.board_pos[0].append(element)
                self.board_cnt[0].append(self.cntr_t(element))

            # type 2 triangles
            Color(65 / 255, 167 / 255, 107 / 255)
            for element in self.generate_triangles_type_2(
                    base_x, base_y, self.triangle_size):
                self.board_obj[1].append(Triangle(points=element))
                self.board_pos[1].append(element)
                self.board_cnt[1].append(self.cntr_t(element))

            # player 1 pieces
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][13], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][14], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][15], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][16], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][17], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][23], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][24], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][25], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][26], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][27], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][28], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][32], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][34], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][35], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][36], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][38], self.circle_radius, 1))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][33], self.circle_radius, 2))
            self.pieces[0].append(
                BizingoPiece(self.board_cnt[0][37], self.circle_radius, 2))

            # player 2 pieces
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][50], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][52], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][53], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][55], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][58], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][59], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][60], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][61], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][62], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][65], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][66], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][67], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][68], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][71], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][72], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][73], self.circle_radius, 3))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][51], self.circle_radius, 4))
            self.pieces[1].append(
                BizingoPiece(self.board_cnt[1][54], self.circle_radius, 4))

            self.bdb = BizingoDrawBoard()
            self.bdb.canvas.clear()
Пример #26
0
 def __init__(self, **kwargs):
     super(Titulo, self).__init__(**kwargs)
     with self.canvas:
         self.triangle = Triangle(points=[40, 40, 200, 200, 160, 40])
Пример #27
0
 def update_drawing(self):
     global update_drawing_list, length
     with self.canvas:
         Color(0,0,0)
         Rectangle(pos = (0,0), size = (Window.size[0]/1.75, Window.size[1]/1.4))
     with self.canvas:
         Color(1,1,1)
         Rectangle(pos=(Window.size[0] / 20, Window.size[1] / 2.353), size=(Window.size[0] / 2, Window.size[1] / 300))
     beam_length = Window.size[0]/2
     y_pos = Window.size[1] / 2.353 + Window.size[1] / 600
     for items in update_drawing_list:
         if len(items) < 4:
             pass
         elif items[3] == "Point_load":
             self.abs_max = max(abs(self.abs_max), abs(items[1]))
         elif items[3] == "UDL":
             self.abs_max = max(abs(self.abs_max), abs(items[2]))
         elif items[4] == "VDL":
             equation = (items[3]-items[2])/(items[1]-items[0])*x+items[2]
             y_points = []
             x_points = []
             interval = (items[1] - items[0]) / 1000
             max_point = 0
             min_point = 0
             for i in range(1000):
                 y_point = equation.calculate(i * interval)
                 if y_point > max_point:
                     max_point = y_point
                 if y_point < min_point:
                     min_point = y_point
                 y_points.append(y_point)
                 abs_position = Window.size[0] / 20 + (float(items[0] + i * interval) * beam_length) / length
                 x_points.append(abs_position)
             self.abs_max = max(abs(max_point), abs(min_point), self.abs_max)
     for items in update_drawing_list:
         if items[1] == "Fixed":
             with self.canvas:
                 Color(1,0,0)
                 x_size = Window.size[0]/75
                 y_size = Window.size[0]/25
                 x_pos = Window.size[0] / 20 + (float(items[0]) * beam_length) / length - x_size/2
                 y_pos = Window.size[1] / 2.353 - (y_size/2)+ Window.size[1]/300
                 Rectangle(pos = (x_pos,y_pos), size = (x_size, y_size))
         elif items[1] == "Pin":
             with self.canvas:
                 Color(1,0,0)
                 x_pos = Window.size[0] / 20 + (float(items[0]) * beam_length) / length
                 y_pos = Window.size[1] / 2.353
                 x_difference = Window.size[0] / 37.5
                 y_difference = Window.size[1] / 25
                 points = [x_pos, y_pos, x_pos - x_difference, y_pos - y_difference, x_pos + x_difference,
                           y_pos - y_difference]
                 Triangle(points=points)
         elif items[1] == "Roller":
             with self.canvas:
                 Color(1, 0, 0)
                 x_pos = Window.size[0] / 20 + (float(items[0]) * beam_length) / length
                 y_pos = Window.size[1] / 2.353
                 x_difference = Window.size[0] / 37.5
                 y_difference = Window.size[1] / 25
                 points = [x_pos, y_pos, x_pos - x_difference, y_pos - y_difference, x_pos + x_difference,
                           y_pos - y_difference]
                 Triangle(points=points)
                 Color(1, 1, 1)
                 radius = x_difference/2
                 Line(circle = (x_pos, y_pos-y_difference-radius, radius))
         elif items[2] == "Moment":
             x_pos = Window.size[0] / 20 + (float(items[0]) * beam_length) / length
             y_pos = Window.size[1] / 2.353 + Window.size[1] / 600
             radius = Window.size[0] / 50
             x_tip = Window.size[0] / 120
             y_tip = Window.size[0] / 160
             with self.canvas:
                 Color(1, 1, 1)
                 Line(circle=(x_pos, y_pos, radius, 0, 180))
                 Line(points=[x_pos, y_pos+radius, x_pos+x_tip, y_pos+radius-y_tip, x_pos, y_pos+radius,
                              x_pos+x_tip, y_pos+radius+y_tip])
         elif items[3] == "Point_load":
             angle = radians(float(items[2]))
             x_pos = Window.size[0] / 20 + (float(items[0]) * beam_length) / length
             y_pos = Window.size[1] / 2.353 + Window.size[1]/600
             if items[1] > 0:
                 tip_y_pos = (items[1]*sin(angle)/self.abs_max)*(Window.size[1]/1.5-Window.size[1]/2.353)
                 tip_x_pos = -(items[1]*cos(angle)/self.abs_max)*(Window.size[1]/1.5-Window.size[1] / 2.353)
             elif items[1] < 0:
                 tip_y_pos = (items[1]*sin(angle)/self.abs_max)*(Window.size[1]/1.5-Window.size[1]/2.353)
                 tip_x_pos = (items[1] * cos(angle) / self.abs_max) * (Window.size[1] / 1.5 - Window.size[1]/2.353)
             with self.canvas:
                 Color(1, 1, 1)
                 right_x_wing = -Window.size[0]/80*cos(angle)+Window.size[1]/120*sin(angle)
                 right_y_wing = Window.size[0]/80*sin(angle)+Window.size[1]/120*cos(angle)
                 left_x_wing = -Window.size[0]/80*cos(angle)-Window.size[1]/120*sin(angle)
                 left_y_wing = Window.size[0]/80*sin(angle)-Window.size[1]/120*cos(angle)
                 if items[1] > 0:
                     Line(points=[x_pos, y_pos, x_pos+right_x_wing, y_pos+right_y_wing, x_pos, y_pos, x_pos+left_x_wing,
                                  y_pos+left_y_wing],width=1)
                     Line(points=[x_pos, y_pos,x_pos+tip_x_pos,y_pos+tip_y_pos], width=1)
                 elif items[1] == 0:
                     pass
                 else:
                     Line(points=[x_pos, y_pos, x_pos+right_x_wing, y_pos-right_y_wing, x_pos, y_pos, x_pos+left_x_wing,
                                  y_pos-left_y_wing],
                          width=1)
                     Line(points=[x_pos, y_pos, x_pos+tip_x_pos, y_pos+tip_y_pos], width=1)
         elif items[3] == "UDL":
             self.abs_max = max(abs(self.abs_max), abs(items[2]))
             arrows = int(max(3, (items[1]-items[0])/length*20)-2)
             start_pos = Window.size[0] / 20 + (float(items[0]) * beam_length) / length
             end_pos = Window.size[0] / 20 + (float(items[1]) * beam_length) / length
             base_height = Window.size[1] / 2.353 + Window.size[1]/600
             arrow_x = Window.size[1]/120
             if items[2] > 0:
                 arrow_y = Window.size[0]/80
             elif items[2] < 0:
                 arrow_y = -Window.size[0]/80
             else:
                 arrow_y = 0
                 arrow_x = 0
             height = (items[2]/self.abs_max)*(Window.size[1]/1.5-Window.size[1]/2.353)
             with self.canvas:
                 Color(1, 1, 1)
                 Line(points=[start_pos, base_height+height, end_pos, base_height+height])
                 Line(points=[start_pos+arrow_x, base_height+arrow_y, start_pos, base_height,
                              start_pos-arrow_x, base_height+arrow_y, start_pos, base_height,
                              start_pos, base_height+height])
                 Line(points=[end_pos + arrow_x, base_height + arrow_y, end_pos, base_height,
                              end_pos - arrow_x, base_height + arrow_y, end_pos, base_height,
                              end_pos, base_height + height])
                 for i in range(arrows):
                     position = (i+1)*(end_pos-start_pos)/(arrows+1)+start_pos
                     Line(points=[position + arrow_x, base_height + arrow_y, position, base_height,
                                  position - arrow_x, base_height + arrow_y, position, base_height,
                                  position, base_height + height])
         elif items[4] == "VDL":
             y_pos = Window.size[1] / 2.353 + Window.size[1]/600
             y_points = []
             x_points = []
             interval = (items[1] - items[0]) / 1000
             max_point = 0
             min_point = 0
             equation = (items[3] - items[2]) / (items[1] - items[0]) * x + items[2]
             for i in range(1000):
                 y_point = equation.calculate(0 + i * interval)
                 if y_point > max_point:
                     max_point = y_point
                 if y_point < min_point:
                     min_point = y_point
                 y_points.append(equation.calculate(0 + i * interval))
                 abs_position = Window.size[0] / 20 + (float(items[0] + i * interval) * beam_length) / length
                 x_points.append(abs_position)
             arrows = int(max(3, (items[1] - items[0]) / length * 20))
             start_pos = Window.size[0] / 20 + (float(items[0]) * beam_length) / length
             end_pos = Window.size[0] / 20 + (float(items[1]) * beam_length) / length
             arrow_x = Window.size[1] / 120
             arrow_interval = floor(1000/arrows)
             points = []
             for i in range(len(y_points)):
                 y_abs = (y_points[i] / self.abs_max) * (Window.size[1] / 1.5 - Window.size[1] / 2.353) + y_pos
                 if ((i) % arrow_interval == 0 and i < 951) or i == 0 or i == 999:
                     if y_points[i] > 0 and y_abs > (Window.size[0] / 80 + y_pos):
                         arrow_y = Window.size[0] / 80 + y_pos
                     elif y_points[i] < 0 and y_abs < (-Window.size[0] / 80 + y_pos) :
                         arrow_y = -Window.size[0] / 80 + y_pos
                     else:
                         arrow_y = y_pos
                     with self.canvas:
                         Color(1,1,1)
                         Line(points=[x_points[i], y_abs, x_points[i], y_pos], width=1)
                         Line(points=[x_points[i]+arrow_x, arrow_y, x_points[i], y_pos, x_points[i]-arrow_x, arrow_y])
                 points.append(x_points[i])
                 points.append(y_abs)
             with self.canvas:
                 Color(1,1,1)
                 Line(points=points, width=1)
Пример #28
0
 def init_ship(self):
     with self.canvas:
         Color(1, 0, 1)
         self.ship = Triangle()
Пример #29
0
    def update(self, dt):
        if self.first_update:
            self.stars = []
            i = 0
            while i < self.num_stars:
                pos = (random.randrange(self.parent.width),
                       random.randrange(self.parent.height))
                color = Color(0,
                              0,
                              random.random() * self.star_brightness,
                              mode='hsv')
                self.stars.append(Star(pos, color))
                i += 1
            self.first_update = False

        self.canvas.clear()
        self.pos = self.parent.pos
        with self.canvas:
            center_vec = Vector3(self.parent.center_x, self.parent.center_y, 0)

            for star in self.stars:
                Color(star.color.h, star.color.s, star.color.v, mode='hsv')
                Point(points=star.pos)

            for obj in self.render_objects:
                #Render Planets
                Color(1, 1, 1)
                if type(obj) == Planet:
                    rad = obj.radius * self.world_scale
                    Ellipse(pos=(self.parent.center_x - rad,
                                 self.parent.center_y - rad),
                            size=(rad * 2, rad * 2))
                    # Ellipse(pos=self.parent.center, size=(10,10))

                #Render Orbit Path
                if obj.__class__ == OrbitPath:
                    Color(1, 0, 0)
                    point_list = obj.get_point_list(center_vec,
                                                    self.world_scale,
                                                    step=2)
                    Line(points=point_list,
                         dash_length=2,
                         dash_offset=2,
                         width=1.2)

                #Render the Ship
                if type(obj) == Ship:
                    #Ship Body
                    Color(0, 1, 0)
                    ship_pos = center_vec.add(obj.pos.fmul(self.world_scale))
                    ship_dir = obj.direction
                    ship_dir_left = vector2d_perpendicular(ship_dir, 0)
                    ship_dir_right = vector2d_perpendicular(ship_dir, 1)
                    ship_tri_front = ship_pos.add(
                        ship_dir.fmul(self.ship_scale))
                    ship_tri_back = ship_pos.add(
                        ship_dir.fmul(-0.5 * self.ship_scale))
                    ship_tri_back_left = ship_tri_back.add(
                        ship_dir_left.fmul(self.ship_scale * 0.4))
                    ship_tri_back_right = ship_tri_back.add(
                        ship_dir_right.fmul(self.ship_scale * 0.4))

                    Triangle(points=(ship_tri_front.x, ship_tri_front.y,
                                     ship_tri_back_left.x,
                                     ship_tri_back_left.y,
                                     ship_tri_back_right.x,
                                     ship_tri_back_right.y))

                    #Engine Fire
                    Color(1, 0.4, 0.4)
                    fire_size_x = self.ship_scale * 0.3
                    fire_size_y = self.ship_scale * 1e-1 * obj.get_effective_engine_power(
                    )
                    fire_pos_top_left = ship_tri_back.add(
                        ship_dir_left.fmul(fire_size_x / 2.0))
                    fire_pos_top_right = ship_tri_back.add(
                        ship_dir_left.fmul(-fire_size_x / 2.0))
                    fire_pos_bottom = ship_tri_back.add(
                        ship_dir.fmul(-fire_size_y))
                    Triangle(points=(fire_pos_top_left.x, fire_pos_top_left.y,
                                     fire_pos_bottom.x, fire_pos_bottom.y,
                                     fire_pos_top_right.x,
                                     fire_pos_top_right.y))

                    #Ship Engine
                    Color(0.4, 0.4, 0.4)
                    engine_size_x = self.ship_scale * 0.5
                    engine_size_y = self.ship_scale * 0.5
                    engine_pos_top_left = ship_tri_back.add(
                        ship_dir_left.fmul(engine_size_x / 2.0))
                    engine_pos_top_right = ship_tri_back.add(
                        ship_dir_left.fmul(-engine_size_x / 2.0))
                    engine_pos_bottom_left = engine_pos_top_left.add(
                        ship_dir.fmul(-engine_size_y / 2.0))
                    engine_pos_bottom_right = engine_pos_top_right.add(
                        ship_dir.fmul(-engine_size_y / 2.0))

                    Triangle(points=(engine_pos_top_left.x,
                                     engine_pos_top_left.y,
                                     engine_pos_top_right.x,
                                     engine_pos_top_right.y,
                                     engine_pos_bottom_right.x,
                                     engine_pos_bottom_right.y))
                    Triangle(points=(engine_pos_top_left.x,
                                     engine_pos_top_left.y,
                                     engine_pos_bottom_left.x,
                                     engine_pos_bottom_left.y,
                                     engine_pos_bottom_right.x,
                                     engine_pos_bottom_right.y))
Пример #30
0
    def __init__(self, song, part, **kwargs):
        super(MainWidget, self).__init__(**kwargs)
    
        # Set terminal color to white
        Window.clearcolor = (.8, .8, .8, .8) 

        self.song = song
        self.part = part

        self.timelabel = topright_label((Window.width * 0.84, Window.height * 0.81))
        self.add_widget(self.timelabel)

        self.scorelabel = topright_label((Window.width * 0.83, Window.height * 0.87))
        self.add_widget(self.scorelabel)

        self.streaklabel = center_label()
        self.add_widget(self.streaklabel)

        self.name = name_label()
        self.add_widget(self.name)

        self.pitchlabel = center_label()
        self.add_widget(self.pitchlabel)

        self.clock = Clock()
        self.clock.stop()
        self.gametime = -SCREEN_TIME
        self.gameon = False

        self.old_cursor_y = 1
        self.filter_rate = 0.4

        self.noteon_ind = 0
        self.noteoff_ind = 0

        # Display user's cursor
        self.cursorcol = Color(.6,.6,.6)
        self.canvas.add(self.cursorcol)
        self.user = Triangle(points=[NOW_PIXEL-60, -30, NOW_PIXEL-60, 30, NOW_PIXEL, 0])
        self.canvas.add(self.user)

        # Add particle system, which is used in BeatMatchDisplay when user sings the correct pitch.
        self.ps = ParticleSystem('particle/particle.pex')
        self.add_widget(self.ps)

        self.scorelabel.text = "[b]color=000000]SCORE: 0[/b]"
        self.timelabel.text = "[b]TIME: %.2f[/b]" % self.gametime
        self.streaklabel.text = "[color=000000][b]keys[/b]\n[i]p:[/i] [size=30]play | pause[/size]"
       
        self.bg_filename, self.part_filename = getAudioFiles(song, part)
        self.synth = Synth('data/FluidR3_GM.sf2')
        self.writer = AudioWriter('recordings/{}/{}'.format(song, part))
        self.audio = AudioController(self.bg_filename, self.part_filename, self.synth, receive_audio_func=self.receive_audio)

        self.gems_txt, self.barlines_txt, self.beats_txt = getDisplayFiles(song, part)

        song_data = SongData()
        song_data.read_data(self.gems_txt, self.barlines_txt, self.beats_txt)
        self.lanes = song_data.lanes
        self.beatData = song_data.beat_data
        self.barlineData = song_data.barline_data
        self.healthbar = HealthBar()
        self.progress = ProgressBar(len(song_data.barline_data)/4)
        self.display = BeatMatchDisplay(song_data, self.ps, RATE)
        self.canvas.add(self.healthbar)
        self.canvas.add(self.progress)
        self.canvas.add(self.display)

        self.player = Player(song_data, self.display, self.audio, PitchDetector())

        self.display.draw_objects()

        self.curr_phrase = 0
        self.phrase_score = self.player.score
        self.phrase_max_score = self.player.max_score

        if os.path.isfile('recordings/{}/scores'.format(song)):
            self.score_list = pickle.load(open('recordings/{}/scores'.format(song), 'r'))
        else:
            self.score_list = {}
            for part in PARTS:
                self.score_list[part] = {"score": 0, "num": 0, "top": None}