Beispiel #1
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()
Beispiel #2
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()
Beispiel #3
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})"
                )