예제 #1
0
def predefined_actors_2():
    actors = dict()
    m_spr = predef.CELL_CREATOR.create('@', colors.WHITE, colors.TRANSPARENT_COLOR)
    input_channel = intention_channel.UserIntentionChannel()
    main_hero = GameObject(pos=Vec2i(8, 18), name='main_char', sprite=m_spr)
    actors[main_hero] = input_channel
    return actors, main_hero
예제 #2
0
def predefined_actors():
    actors = dict()

    input_channel = intention_channel.UserIntentionChannel()
    viking_sprite = pygame.image.load('./_gamedata/test2.png')

    w, h = viking_sprite.get_size()
    scale = 2
    new_sprite = pygame.Surface((w * scale, h * scale), flags=pygame.SRCALPHA)
    viking_sprite.get_colorkey()
    for i in range(32):
        for j in range(32):
            pi_color = viking_sprite.get_at((i, j))
            for i_new in range(scale):
                for j_new in range(scale):
                    new_pos = (scale * i + i_new, scale * j + j_new)
                    new_sprite.set_at(new_pos, pi_color)
    print(new_sprite.get_size())
    main_hero_items = CharacterItems()
    main_hero_items.right_hand.put_item(OneHandAxe())
    main_hero = Character(pos=Vec2i(8, 18), name='main_char',
                          sprite=new_sprite,
                          attributes=CharacterAttributes(16, 14, 15, 10, 10),
                          inventory_capacity=20,
                          base_hp=1000,
                          character_items=main_hero_items)
    actors[main_hero] = input_channel

    d_spr = predef.CELL_CREATOR.create('D', colors.BLUE, colors.TRANSPARENT_COLOR)
    dragon_gobj = Character(pos=Vec2i(10, 18), name='dragon', sprite=d_spr,
                            attributes=CharacterAttributes(10, 10, 10, 10, 10),
                            inventory_capacity=20,
                            base_hp=100,
                            character_items=CharacterItems())
    ai_com_chan = intention_channel.AIRandMoveIC()
    actors[dragon_gobj] = ai_com_chan

    n_spr = predef.CELL_CREATOR.create('@', colors.BW_GREY, colors.TRANSPARENT_COLOR)
    necro_gobj = Character(pos=Vec2i(12, 18), name='necromancer', sprite=n_spr,
                           attributes=CharacterAttributes(10, 10, 10, 10, 10),
                           inventory_capacity=20,
                           base_hp=100,
                           character_items=CharacterItems())
    actors[necro_gobj] = ai_com_chan
    return actors, main_hero
예제 #3
0
def adhoc_dot_sprite(tile_size_pixels: utils.Vec2i, boldness: int,
                     transparency: int) -> pygame.Surface:
    dot_sprite: pygame.Surface = pygame.Surface(tile_size_pixels.to_tuple(),
                                                flags=pygame.SRCALPHA)
    dot_sprite.fill(color=(0, 0, 0, 0))
    tile_center_xy = tile_size_pixels // 2
    for i in range(-boldness, boldness):
        for j in range(-boldness, boldness):
            t = tile_center_xy + utils.Vec2i(1, 0) * i + utils.Vec2i(0, 1) * j
            dot_sprite.set_at(t.to_tuple(), (255, 255, 255, transparency))
    return dot_sprite
예제 #4
0
def test_tile_map():
    tiles = TileMap()  # EMPTY
    desert_cell_sprite = pygame.Surface(screen.CELL_SIZE)
    desert_cell_sprite.fill(colors.SAND)
    for i in range(8, 15):
        for j in range(18, 23):
            pos = Vec2i(i, j)
            tiles.set_tile(
                pos,
                Tile(pos=pos, name='sand_sprite', sprite=desert_cell_sprite))
    for i in range(15, 20):
        pos = Vec2i(i, 18)
        tiles.set_tile(
            pos, Tile(pos=pos, name='sand_sprite', sprite=desert_cell_sprite))
    for i in range(20, 24):
        for j in range(8, 19):
            pos = Vec2i(i, j)
            tiles.set_tile(
                pos,
                Tile(pos=pos, name='sand_sprite', sprite=desert_cell_sprite))
    return tiles
예제 #5
0
    def _draw_layers(self, center: utils.Vec2i) -> None:
        PERFOMANCE_DATA.blit_last_elapsed = 0
        screen_size = self._screen_size  # optimization is important
        monitor_center = self._monitor_center
        center_tuple = center.to_tuple()
        p_xy = [0, 0]
        for i in range(self._layers.num_layers()):
            layer = self._layers.get_layer(i)
            for visual in layer:
                sprite = visual.get_sprite()

                p_xy[0], p_xy[1] = visual.get_corner_xy().to_tuple()
                p_xy[0] -= center_tuple[0]
                p_xy[1] -= center_tuple[1]
                p_xy[1] = screen_size[1] - p_xy[1] - monitor_center[1]
                p_xy[0] += monitor_center[0]

                t_begin = pygame.time.get_ticks()
                self._display.blit(sprite, p_xy)
                t_end = pygame.time.get_ticks()
                PERFOMANCE_DATA.blit_last_elapsed += (t_end - t_begin)
        PERFOMANCE_DATA.blit_total += PERFOMANCE_DATA.blit_last_elapsed
예제 #6
0
def draw_tile_descartes(what_to_draw: pygame.Surface, ij: Vec2i,
                        where_to_draw: pygame.Surface):
    draw_surf_descartes(what_to_draw,
                        ij.dot(Vec2i(screen.CELL_WIDTH, screen.CELL_HEIGHT)),
                        where_to_draw)
예제 #7
0
 def empty_tile(cls, pos: Vec2i = Vec2i(0, 0), name: str = ''):
     return Tile(pos=pos,
                 name=name,
                 sprite=pygame.Surface(
                     (screen.CELL_WIDTH, screen.CELL_HEIGHT)))
예제 #8
0
    def get_pos(self) -> Vec2i:
        return self._pos

    def set_pos(self, new_pos: Vec2i) -> None:
        self._pos = new_pos

    def get_sprite(self) -> pygame.Surface:
        return self._sprite

    def set_sprite(self, new_sprite: pygame.Surface) -> None:
        self._sprite = new_sprite

    def get_name(self) -> str:
        return self._name

    def set_name(self, new_name):
        self._name = new_name


if __name__ == '__main__':
    from sys import getsizeof
    sp = pygame.Surface(size=(15, 155))
    test_gobj1 = GameObject(pos=Vec2i(1, 2), name='Monster', sprite=sp)
    print(getsizeof(test_gobj1))
    test_gobj2 = GameObject(pos=Vec2i(1, 2), name='Monster2', sprite=None)
    print(getsizeof(test_gobj2))
    test_gobj3 = GameObject(pos=Vec2i(1, 2), name='Monster3', sprite=None)
    print(getsizeof(test_gobj3))
    print(getsizeof(test_gobj3))
예제 #9
0
 def descartes_to_monitor(self, xy_desc: utils.Vec2i) -> utils.Vec2i:
     new_xy = xy_desc.copy()
     new_xy[1] = self._screen_size[1] - new_xy[1] - self._monitor_center[1]
     new_xy[0] += self._monitor_center[0]
     return new_xy