예제 #1
0
def test_graphics_main_thread(widget_verify_thread):
    from kivy.graphics import Color

    widget, verify_thread = widget_verify_thread
    with widget.canvas:
        color = Color()
    color.rgb = .1, .2, .3
예제 #2
0
파일: buttons.py 프로젝트: vallemrv/tpvB3
 def draw_color(self):
     if self.container and self.shape_up:
         size = self.container.size
         color = Color()
         color.rgb = get_color_from_hex(self.bgColor)
         self.shape_up.add(color)
         self.shape_up.add(Rectangle(pos=self.container.pos, size=size))
         self.container.canvas.before.add(self.shape_up)
예제 #3
0
파일: buttons.py 프로젝트: vallemrv/tpvB3
 def on_bgColor(self, root, val):
     if self.shape_up == None:
         self.shape_up = InstructionGroup(grup="shape_up")
     else:
         self.shape.canvas.remove(self.shape_up)
         self.shape_up.clear()
     color = Color()
     color.rgb = get_color_from_hex(val)
     self.shape_up.add(color)
     self.shape_up.add(Ellipse(pos=self.shape.pos, size=self.shape.size))
     self.shape.canvas.before.add(self.shape_up)
     self.shape_up.clear()
예제 #4
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})"
                )