Esempio n. 1
0
    def draw(self):
        Game.engine['gfx'].draw_rectangle(
            (self.x, self.y), (self.width, self.height), self.current_colour)

        # Kivy is special so we make sure that our attached widget is the right colour and size
        # to get the overlay to appear
        if Game.engine_def['gfx'] == "kivy":
            from kivy.graphics import Color, PushMatrix, PopMatrix, Translate, Quad
            if not self in Game.engine['gfx'].entity_draws:
                Game.engine['gfx'].entity_draws[self] = dict()
                with Game.engine['gfx'].widget.canvas:
                    Game.engine['gfx'].entity_draws[self]['color'] = Color()
                    Game.engine['gfx'].entity_draws[self][
                        'color'].rgba = self.current_colour
                    PushMatrix()
                    Game.engine['gfx'].entity_draws[self][
                        'translate'] = Translate()

                    Game.engine['gfx'].entity_draws[self]['rect'] = Quad(
                        points=(0.0, 0.0, self.width, 0.0, self.width,
                                self.height, 0.0, self.height))
                    Game.engine['gfx'].entity_draws[self]['translate'].xy = (
                        self.x, self.y)
                    PopMatrix()
            # Otherwise just update values
            else:
                Game.engine['gfx'].entity_draws[self]['translate'].xy = (
                    self.x, self.y)
                Game.engine['gfx'].entity_draws[self][
                    'color'].rgba = self.current_colour
                Game.engine['gfx'].entity_draws[self]['rect'].points = (
                    0.0, 0.0, self.width, 0.0, self.width, self.height, 0.0,
                    self.height)
Esempio n. 2
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))
Esempio n. 3
0
    def _render(self):
        if self.num_particles == 0:
            return
        for i in range(self.num_particles):
            particle = self.particles[i]
            size = (self.texture.size[0] * particle.scale,
                    self.texture.size[1] * particle.scale)
            if particle not in self.particles_dict:
                self.particles_dict[particle] = dict()
                color = particle.color[:]
                with self.canvas:

                    PushMatrix()
                    self.particles_dict[particle]['color'] = Color(
                        color[0], color[1], color[2], color[3])
                    self.particles_dict[particle]['translate'] = Translate()
                    self.particles_dict[particle]['rotate'] = Rotate()
                    self.particles_dict[particle]['rotate'].set(
                        particle.rotation, 0, 0, 1)
                    self.particles_dict[particle]['rect'] = Quad(
                        texture=self.texture,
                        points=(-size[0] * 0.5, -size[1] * 0.5, size[0] * 0.5,
                                -size[1] * 0.5, size[0] * 0.5, size[1] * 0.5,
                                -size[0] * 0.5, size[1] * 0.5))
                    self.particles_dict[particle]['translate'].xy = (
                        particle.x, particle.y)
                    PopMatrix()

            else:
                self.particles_dict[particle][
                    'rotate'].angle = particle.rotation
                self.particles_dict[particle]['translate'].xy = (particle.x,
                                                                 particle.y)
                self.particles_dict[particle]['color'].rgba = particle.color
Esempio n. 4
0
 def __init__(self, **kw):
     super(ResourceBar, self).__init__(**kw)
     for k, v in kw.iteritems():
         if hasattr(self, k):
             setattr(self, k, v)
     with self.canvas.before:
         self.quadbg_color = Color(.1, .4, .4, 1)
         self.quadbg = Quad(source='img/resourcebar_bg.png')
     with self.canvas:
         self.quad_color = Color(.5, .5, .5, 1)
         self.quad = Quad(source='img/resourcebar.png')
     with self.canvas.after:
         self.quadfg_color = Color(.2, .8, .8, 1)
         self.quadfg = Quad(source='img/resourcebar_fg.png')
     self.bind(pos=self._update)
     self.bind(size=self._update)
     self.bind(fill_pct=self._update_fill_pct)
     self.bind(slant_pct=self._update_slant_pct)
Esempio n. 5
0
    def generate_level(self):
        for w in self.blocks:
            self.remove_widget(w)

        self.canvas.remove_group(CentripetalGame.g_level)
        self.blocks = []

        color = 0
        width = min(Window.width, Window.height)

        #r_start = 300
        n_rings = self.n_rings
        #num_segments = self.num_segments
        num_segments = n_rings + 7
        ring_spacing = width / 60.0 / n_rings * 7  # maybe this shouldn't depend on the window width/height?

        r_start = width / 2 - ring_spacing * n_rings

        for ring in range(n_rings):
            r_1 = ring * ring_spacing + r_start
            r_2 = (ring + 1) * ring_spacing + r_start
            #num_segments = ring*4
            step = (2 * pi) / num_segments
            for i in range(num_segments):
                angle = step * i
                #color += random.uniform(0,0.5)
                color += random.uniform(0, 1.0 / (num_segments * n_rings) * 2)
                w = Block()
                self.add_widget(w)
                pts = [
                    cx + cos(angle) * r_1, cy + sin(angle) * r_1,
                    cx + cos(angle) * r_2, cy + sin(angle) * r_2,
                    cx + cos(angle + step) * r_2, cy + sin(angle + step) * r_2,
                    cx + cos(angle + step) * r_1, cy + sin(angle + step) * r_1
                ]
                w.pts = pts
                w.lowerx = pts[0]
                w.lowery = pts[1]
                w.upperx = pts[0]
                w.uppery = pts[1]

                for i in range(0, 8, 2):
                    if pts[i] < w.lowerx: w.lowerx = pts[i]
                    if pts[i] > w.upperx: w.upperx = pts[i]
                    if pts[i + 1] < w.lowery: w.lowery = pts[i + 1]
                    if pts[i + 1] > w.uppery: w.uppery = pts[i + 1]

                with w.canvas:
                    Color(color,
                          random.uniform(0.4, 1),
                          random.uniform(0.8, 1),
                          mode='hsv',
                          group=CentripetalGame.g_level)
                    Quad(points=pts, group=CentripetalGame.g_level)
                self.blocks.append(w)
Esempio n. 6
0
    def redraw(self, index):

        self.canvas.clear()
        with self.canvas:
            for i, quad in enumerate(quads):
                if i == index:
                    Color(1, 1, 1, 1, mode='rgba')
                else:
                    Color(1, 1, 1, 1, mode='rgba')

                points = tuple(quad.T[..., :2].flatten() + 100)
                Quad(source=imgs[i].path, points=points)
Esempio n. 7
0
    def box(self, space):
        mass = 10
        moment = pymunk.moment_for_box(mass, (40, 20))
        b = pymunk.Body(mass, moment)
        s = pymunk.Poly.create_box(b, (40, 20))
        s.friction = 1
        b.position = 600, self.box_y
        self.box_y += 30
        space.add(b, s)

        with self.canvas:
            Color(0.2, 0.2, 0.2)
            s.ky = Quad(points=self.points_from_poly(s))
Esempio n. 8
0
    def draw_quad(self, star_list):
        star_tex = Image('star1.png').texture

        with self.canvas:
            for star in star_list:
                size = .5 * star[2]
                PushMatrix()
                t = Translate()
                r = Rotate()
                r.angle = star[3]
                Quad(texture=star_tex,
                     points=(-size, -size, size, -size, size, size, -size,
                             size))
                t.xy = star[0], star[1]
                PopMatrix()
Esempio n. 9
0
 def on_parent(self, *args):
     if not self.canvas:
         Clock.schedule_once(self.on_parent, 0)
         return
     if not self.trunk_points or not self.head_points:
         self._repoint()
     if hasattr(self, '_color0'):
         return
     with self.canvas:
         self._color0 = Color(rgba=self.bg_color_selected if self.
                              selected else self.bg_color_unselected)
         for att in (
                 'bg_color_selected',
                 'bg_color_unselected',
                 'selected',
         ):
             self.fbind(att, self._pull_bg_color0)
         self._quad0 = Quad(points=self.trunk_quad_vertices_bg)
         self.fbind('trunk_quad_vertices_bg', self._pull_points_quad0)
         self._color1 = Color(rgba=(
             self.bg_color_selected_head or self.bg_color_selected
         ) if self.selected else (
             self.bg_color_unselected_head or self.bg_color_unselected))
         for att in ('bg_color_selected_head', 'bg_color_selected',
                     'bg_color_unselected_head', 'bg_color_unselected',
                     'selected'):
             self.fbind(att, self._pull_head_bg_color1)
         self._quad1_0 = Quad(points=self.left_head_quad_vertices_bg)
         self.fbind('left_head_quad_vertices_bg',
                    self._pull_bg_left_head_points_quad1_0)
         self._quad1_1 = Quad(points=self.right_head_quad_vertices_bg)
         self.fbind('right_head_quad_vertices_bg',
                    self._pull_bg_right_head_points_quad1_1)
         self._color2 = Color(rgba=self.fg_color_selected if self.
                              selected else self.fg_color_unselected)
         for att in ('fg_color_selected', 'fg_color_unselected',
                     'selected'):
             self.fbind(att, self._pull_color2)
         self._quad2 = Quad(points=self.trunk_quad_vertices_fg)
         self.fbind('trunk_quad_vertices_fg', self._pull_quad2_points)
         self._color3 = Color(rgba=(
             self.fg_color_selected_head or self.fg_color_selected
         ) if self.selected else (
             self.fg_color_unselected_head or self.fg_color_unselected))
         for att in ('selected', 'fg_color_selected_head',
                     'fg_color_selected', 'fg_color_unselected_head',
                     'fg_color_unselected'):
             self.fbind(att, self._pull_color3)
         self._quad3_0 = Quad(points=self.left_head_quad_vertices_fg)
         self.fbind('left_head_quad_vertices_fg', self._pull_points_quad3_0)
         self._quad3_1 = Quad(points=self.right_head_quad_vertices_fg)
         self.fbind('right_head_quad_vertices_fg',
                    self._pull_points_quad3_1)
Esempio n. 10
0
 def cannon(self, space, startingPosition=(0, 20), xDirModifier=1):
     mass = 10
     moment = pymunk.moment_for_box(mass, (20, 20))
     b = pymunk.Body(mass, moment)
     s = pymunk.Poly.create_box(b, (20, 20))
     s.friction = 3
     b.position = startingPosition
     s.color = random.randint(10, 255) / 255.0, random.randint(
         10, 255) / 255.0, random.randint(10, 255) / 255.0
     space.add(b, s)
     magnatude = random.randint(10000, 15000)
     angleRadians = math.radians(random.randint(3000, 7000) / 100.0)
     impulse = Vec2d((math.cos(angleRadians) * magnatude) * xDirModifier,
                     math.sin(angleRadians) * magnatude)
     b.apply_impulse_at_local_point((impulse))
     with self.canvas:
         Color(*s.color)
         s.ky = Quad(points=self.points_from_poly(s))
Esempio n. 11
0
    def addImage(self, img, toRedraw=True):
        """Add a new image to the map"""

        # self.canvas.clear()
        if self.ned is None:
            #
            # Map is drawn around first image.
            #
            print 'Setting first image'
            self.ned = AUVSIcv.NED.NED(img.latitude, img.longitude, 0)

        #
        # Calculate the coordinates of the image (corners of quad)
        #
        projections = img.calculateQuad(self.ned)
        points = tuple(projections.T[..., :2].flatten())

        #
        # Calculate the new limits of the map on the canvas
        #
        self.updateLimits(min(points[::2]), min(points[1::2]))
        self.updateLimits(max(points[::2]), max(points[1::2]))

        minXImage = min(points[::2])
        maxXImage = max(points[::2])
        minYImage = min(points[1::2])
        maxYImage = max(points[1::2])

        newProjections = self.picData.addPicture(
            img, Area(minXImage, maxXImage, minYImage, maxYImage))
        if newProjections is not None:
            points = tuple(newProjections.T[..., :2].flatten())

        #
        # Add the new image to the canvas.
        #
        with self.canvas:
            Color(1, 1, 1, 1, mode='rgba')
            Quad(source=img.path, points=points)

        self.add_GPS_point(img.latitude, img.longitude)
        if toRedraw is True:
            self.redrawLinesOfButtons()  #withoutGPSpoints
Esempio n. 12
0
    def render_entities(self, view_mode: int, x_lower: int, x_upper: int,
                        y_lower: int, y_upper: int, dt: float) -> None:

        # Temporary, Should be Converted to self.quad_dict instead of List
        # self.remove_entity_graphics(dt)
        # print("entities : ", len(self.engine.game_map.entities))

        if view_mode == 1:  # render all entities within viewport
            entities_sorted_for_rendering = [
                e for e in self.engine.game_map.entities
                if x_lower <= e.x < x_upper and y_lower <= e.y < y_upper
            ]
        else:  # render all entities within FOV
            entities_sorted_for_rendering = [
                e for e in self.engine.game_map.entities
                if self.engine.game_map.visible[e.x][e.y]
            ]
        entities_sorted_for_rendering = sorted(
            entities_sorted_for_rendering,
            key=lambda entity: entity.render_order.value)
        # print("entity count: ", len(self.engine.game_map.entities))

        # Update Each Entity Within "View"
        for e in entities_sorted_for_rendering:
            x_norm = e.x - x_lower
            y_norm = e.y - y_lower

            # Update Animation Cycle
            texture_name = e.name2
            try:
                # Find Max Cycle Count
                max_anim_cycle = self.parent.tex_count_dict[texture_name]

                # Use Modulus to Find out Which Anim Cycle to be On
                true_anim_index = (int(self.animation_cycle_index) %
                                   max_anim_cycle) * e.is_alive
                # print(f"true_anim_index: {true_anim_index}")
                # Trickery to allow for player.png and player_0.png to exist as the same file
                # print(f"{texture_name}" + "%s" % (("_%s" % true_anim_index) * true_anim_index))
                tex = self.parent.tile_tex_dict[f"{texture_name}" + "%s" % (
                    ("-%s" % true_anim_index) * true_anim_index)]
            except KeyError:
                # Revert to First Texture
                e.animation_index = 0
                tex = self.parent.tile_tex_dict[f"{texture_name}"]
                # print(f"KeyError with {e.name} animation_index:{e.animation_index} texture_name:{texture_name}")
            texture_size = tex.size * 2

            try:
                # Rendering
                PushMatrix()
                entity_translate = Translate()
                entity_color = Color()
                entity_color.rgb = e.color
                entity_color.a = 1

                # Direction of Sprite
                if e.direction == Direction.LEFT:
                    entity_quad = Quad(
                        texture=tex,
                        points=(-texture_size[0] * 0.5, -texture_size[1] * 0.5,
                                texture_size[0] * 0.5, -texture_size[1] * 0.5,
                                texture_size[0] * 0.5, texture_size[1] * 0.5,
                                -texture_size[0] * 0.5, texture_size[1] * 0.5))
                else:  # elif e.direction == Direction.RIGHT:
                    entity_quad = Quad(
                        texture=tex,
                        points=(texture_size[0] * 0.5, -texture_size[1] * 0.5,
                                -texture_size[0] * 0.5, -texture_size[1] * 0.5,
                                -texture_size[0] * 0.5, texture_size[1] * 0.5,
                                texture_size[0] * 0.5, texture_size[1] * 0.5))
                entity_translate.xy = self.x + (texture_size[0] * 0.5) + (x_norm * self.TILE_SIZE), \
                                      self.y + (texture_size[1] * 0.5) + (y_norm * self.TILE_SIZE)
                # self.entity_graphics.append(entity_quad)
                PopMatrix()
            except KeyError:
                print(
                    f"Couldn't render Entity:{e.name}|{e.name2} at (map x,map y):({e.x},{e.y})"
                )
Esempio n. 13
0
def newRectangle(shape, scaller=1):
    return Quad(points=points_from_poly(shape, scaller))
Esempio n. 14
0
    def draw(self, dt):
        self.loops += 1
        
        # Check thread signals
        self.checkSignals()

        # Game mode
        if(self.state != "editor"):
            # self.simulation.update()

            self.window.statebar.ids["steps"].text = "Steps: "+str(self.simulation.space.steps)

            # Car control
            for shape in self.simulation.space.shapes:
                if(isinstance(shape, Car) and not isinstance(shape, CarAI)):
                    if(self.keys["up"] == 1):
                        shape.forward(dt*100)
                    if(self.keys["down"] == 1):
                        shape.backward(dt*100)
                    if(self.keys["left"] == 1):
                        shape.left(dt*100)
                    if(self.keys["right"] == 1):
                        shape.right(dt*100)

        # Editor mode
        elif(self.state == "editor"):
            # Undo action
            if(self.keys["lctrl"] == 1 and self.keys["z"] == 1 and not self.undoDone):
                # Do undo //Delete and create only
                if(self.changes.__len__() != 0):
                    change = self.changes[self.changes.__len__()-1]
                    match = None
                    for shape in self.simulation.space.shapes:
                        if(shape == change):
                            self.simulation.deleteObject(shape, "nochange")
                            self.changes.remove(shape)
                            match = "found"

                    if(match == None):
                        self.simulation.space.add(change)

                        self.canvas.add(Color(rgba=change.rgba))
                        self.canvas.add(change.ky)

                        self.simulation.repaintObjects()
                        self.changes.remove(change)

                self.undoDone = True
                
            # Reset undo action
            if(self.keys["z"] == 0 and self.undoDone):
                self.undoDone = False

            # Adding tool indication + rectangle adding grap rep
            if(self.editorTool == "add"):
                pos = self.to_local(*Window.mouse_pos)

                # Mouse indication shape
                if(self.addingIndication == None):
                    with self.canvas:
                        Color(0,0.8,0,0.6)
                        self.addingIndication = Ellipse(pos=(pos[0]-5, pos[1]-5), size=(10,10))
                else:
                    self.addingIndication.pos = (pos[0]-5, pos[1]-5)

                # When adding rectangle show its graphical representation
                if(self.addingStage == 1):
                    c = pos
                    a = (self.temp_rect.points[0], self.temp_rect.points[1])
                    b = (self.temp_rect.points[2], self.temp_rect.points[3])

                    a, b, c, d = calculateRectangle(a,b,c)

                    if(self.temp_barrier == None):
                        if(a != None):
                            with self.canvas:
                                Color(0.8,0,0,0.6)
                                self.temp_barrier = Quad(points=(a[0], a[1], b[0], b[1], d[0], d[1], c[0], c[1]))
                    else:
                        if(a != None):
                            self.temp_barrier.points = (a[0], a[1], b[0], b[1], d[0], d[1], c[0], c[1])

            # Deleting mouse indication
            elif(self.editorTool == "delete"):
                pos = self.to_local(*Window.mouse_pos)
                pos = (pos[0]-5, pos[1]-5)

                if(self.addingIndication == None):
                    with self.canvas:
                        Color(0.8,0,0,0.6)
                        self.addingIndication = Ellipse(pos=pos, size=(10,10))
                else:
                    self.addingIndication.pos = pos
            else:
                if(self.addingIndication != None):
                    self.canvas.remove(self.addingIndication)
                    self.addingIndication = None

            # Barrier adding width change
            if(self.temp_barrier != None and isinstance(self.temp_barrier, Line)):
                if(self.keys["up"] == 1):
                    if(self.temp_barrier.width/self.scaller < 100):
                        self.temp_barrier.width += 1
                elif(self.keys["down"] == 1):
                    if(self.temp_barrier.width/self.scaller > 1 and self.temp_barrier.width > 1):
                        self.temp_barrier.width -= 1
    
            # Highligting
            else:
                pos = self.to_local(*Window.mouse_pos)
                pos = (pos[0]/self.scaller, pos[1]/self.scaller)

                for shape in reversed(self.simulation.space.shapes):
                    # Highlight object when no moving
                    if(not self.movingObject):
                        # Highlight hover objects
                        if(shape.point_query(pos)[0] < 0):
                            if(self.tempHighlight != None):
                                self.canvas.remove(self.tempHighlight)
                                self.tempHighlight = None

                            self.tempHighlight = self.highlightObject(shape)
                            break

                        # Cleanup highlight
                        elif(self.tempHighlight != None):
                            self.canvas.remove(self.tempHighlight)
                            self.tempHighlight = None
                    # Cleanup highlight
                    elif(self.tempHighlight != None):
                        self.canvas.remove(self.tempHighlight)
                        self.tempHighlight = None
        # If we want to draw
        if(self.isDrawing):
            # Draw all kivy objects from space.shapes
            self.paintKivy()

            # Update camere if neccesary
            self.updateCamera()
Esempio n. 15
0
    def draw_entities(self, entity_list):
        self.get_device_size_metrics()

        # Create our canvas to draw to if we hadn't got one yet
        if self.widget is None:
            self.widget = Widget()
            Game.engine['window'].kivy_app.widget.add_widget(self.widget)
        self.widget.width = Window.width
        self.widget.height = Window.height

        # If our z order is potentially dirty then we need to completely redraw
        # everything, se we clear the canvas and draw list, then get the proper order.
        if self.z_index_dirty:
            self.widget.canvas.clear()
            self.entity_draws = {}

            #self.entity_list_draw_order = copy.copy(entity_list)
            self.entity_list_draw_order = entity_list
            self.entity_list_draw_order.sort(key=lambda object: object.z
                                             if hasattr(object, "z") else 0,
                                             reverse=True)
            self.z_index_dirty = False

        # Now render for each entity
        for entity in self.entity_list_draw_order:

            if entity.image and getattr(entity.image, "image", None):
                platform.glBlendFunc()
                # Work out the real width/height and screen position of the entity
                size = ((entity.image.width) *
                        (entity.scale * Game.device_scale),
                        (entity.image.height) *
                        (entity.scale * Game.device_scale))
                x, y = entity.get_screen_draw_position()
                y = Game.screen_resolution[1] - (entity.image.height *
                                                 entity.scale) - y
                pos = ((x * Game.device_scale) - Game.global_x_pos_adjust,
                       y * Game.device_scale)

                # If this entity hasn't yet been attached to the canvas then do so
                if not entity in self.entity_draws:
                    self.entity_draws[entity] = dict()
                    with self.widget.canvas:
                        self.entity_draws[entity]['color'] = color = Color()
                        platform.apply_rgb(entity, color)
                        color.a = entity.alpha
                        PushMatrix()
                        self.entity_draws[entity]['translate'] = Translate()
                        self.entity_draws[entity]['rotate'] = Rotate()
                        self.entity_draws[entity]['rotate'].set(
                            entity.rotation, 0, 0, 1)
                        self.entity_draws[entity]['rect'] = Quad(
                            texture=entity.image.image.texture,
                            points=(0.0, 0.0, size[0], 0.0, size[0], size[1],
                                    0.0, size[1]))
                        self.entity_draws[entity]['translate'].xy = pos
                        PopMatrix()
                    # Otherwise just update values
                else:
                    self.entity_draws[entity]['rotate'].angle = entity.rotation
                    self.entity_draws[entity]['translate'].xy = pos
                    color = self.entity_draws[entity]['color']
                    platform.apply_rgb(entity, color)
                    color.a = entity.alpha
                    self.entity_draws[entity][
                        'rect'].texture = entity.image.image.texture
                    self.entity_draws[entity]['rect'].points = (0.0, 0.0,
                                                                size[0], 0.0,
                                                                size[0],
                                                                size[1], 0.0,
                                                                size[1])

            entity.draw()
Esempio n. 16
0
 def init_tiles(self):
     with self.canvas:
         Color(.9, .9, .9)
         for i in range(0, self.nb_tiles):
             self.tiles.append(Quad())
Esempio n. 17
0
 def paint(self, canvasHandler):
     with canvasHandler.canvas:
         Color(rgba=self.rgba)
         
         # self.ky = Quad(points=points_from_poly(self, scaller), texture=self.texture)
         self.ky = Quad(points=points_from_poly(self, canvasHandler.scaller))
    def build(self):
        self.title = "Goal Tracker"
        self.load_settings()
        self.replay_analyze = replay_analyzer(self.replay_folder,
                                              self.player_id)
        self.message_feed_label = Label(text="",
                                        pos=(650, 50),
                                        font_size='20sp',
                                        color=[1, 1, 1],
                                        outline_color=[0, 0, 0],
                                        outline_width=5,
                                        markup=True)
        self.anim = Animation(x=700, duration=0.0) + Animation(
            x=50, duration=0.3) + Animation(x=50, duration=2) + Animation(
                x=-700, duration=0.3)
        self.f = FloatLayout()
        self.message_num = 0
        self.percent_played = 0.0
        self.replay_stats = replay_stats(
            self.main_race, self.main_race_only,
            self.replay_analyze.get_already_played(), self.today_goal,
            self.week_goal)
        self.percent_played_label = Label(
            text="[b][i]" + ("%.1f" %
                             (self.percent_played * 100)) + "%[/i][/b]",
            size=(50, 50),
            pos_hint={
                "x": .34,
                'top': .95
            },
            font_size='90sp',
            color=[1, 0, 0],
            outline_color=[0, 0, 0],
            outline_width=5,
            markup=True)
        self.message_feed_label = Label(text="",
                                        pos=(650, 45),
                                        font_size='20sp',
                                        color=[1, 1, 1],
                                        outline_color=[0, 0, 0],
                                        outline_width=5,
                                        markup=True)
        self.new_percent_played = self.replay_stats.percentage_minute_played()
        self.message_list = message_feed.get_message_list(
            self.replay_stats.percentage_minute_played(),
            self.replay_stats.win_rate_dict(), self.twitch_messages_on)
        self.message_feed_label.bind(
            size=self.message_feed_label.setter('text_size'))
        self.message_feed_animate()
        self.goal_title = Label(text="[b]Today's goal:[/b]",
                                size=(50, 50),
                                pos_hint={
                                    "x": -.25,
                                    'top': 1.3
                                },
                                font_size='50sp',
                                color=[1, 1, 1],
                                outline_color=[0, 0, 0],
                                outline_width=5,
                                markup=True)
        self.minutes_today_label = Label(
            text="Minutes played today: " +
            str("%.2f" % self.replay_stats.total_minutes_played('today')) +
            "(Goal:" + str(self.replay_stats.minute_goal_today) + ")",
            pos=(20, 18))
        self.minutes_today_label.bind(
            size=self.minutes_today_label.setter('text_size'))
        self.minutes_week_label = Label(
            text="Minutes played this week: " +
            str("%.2f" % self.replay_stats.total_minutes_played('this_week')) +
            "(Goal:" + str(self.replay_stats.minute_goal_week) + ")",
            pos=(20, 0))
        self.minutes_week_label.bind(
            size=self.minutes_week_label.setter('text_size'))

        with self.f.canvas:
            #create border
            Color(1, 1, 1, 1)
            Quad(points=[45, 80, 40, 130, 460, 137, 455, 75])
            Color(0, 0, 0, 1)
            Quad(points=[48, 83, 45, 123, 445, 125, 445, 80])
            #percentage bar
            Color(1, 0, 0, 1)
            self.percent_played_bar = Rectangle(
                pos=(55, 90),
                size=((385 * (self.replay_stats.percentage_minute_played())),
                      28))
        self.f.add_widget(self.percent_played_label)
        self.f.add_widget(self.goal_title)
        self.f.add_widget(self.minutes_today_label)
        self.f.add_widget(self.minutes_week_label)
        self.f.add_widget(self.message_feed_label)
        #put down here cause kivy and multiprocessing seems like it doesnt play together well
        from kivy.core.window import Window
        Window.add_widget(self.f)
        Window.size = (700, 200)
        if (self.auto_anchor):
            Window.left = GetSystemMetrics(
                0
            ) - Window.width + self.auto_anchor_left_right_offset if self.auto_anchor_corner.split(
                " ")[1] == "right" else 0 + self.auto_anchor_left_right_offset
            Window.top = (
                GetSystemMetrics(1) - Window.height - 40 +
                self.auto_anchor_bottom_top_offset
            ) if self.auto_anchor_corner.split(
                " ")[0] == "bottom" else 0 + self.auto_anchor_bottom_top_offset
        observer = Observer()
        observer.schedule(file_observer(self.update),
                          self.replay_folder,
                          recursive=False)
        observer.start()
        Clock.schedule_once(self.increase_percent, 0.01)