コード例 #1
0
def map_to_sprites(game_map: List[List[int]]) -> arcade.SpriteList[Entity]:
    """ Take a grid of numbers and convert to sprites. """
    sprite_list = arcade.SpriteList(use_spatial_hash=True,
                                    spatial_hash_cell_size=16)

    # Take the tiles and make sprites out of them
    for y in range(len(game_map[0])):
        for x in range(len(game_map)):
            sprite = None
            # print(f"{game_map[x][y]} ", end="")
            if game_map[x][y] == TILE_WALL:
                sprite = Entity(x, y, WALL_TEXTURE_ID, colors['transparent'])
                sprite.name = "Wall"
                sprite.block_sight = True
                sprite.blocks = True
                sprite.visible_color = colors["light_wall"]
                sprite.not_visible_color = colors["dark_wall"]
            elif game_map[x][y] == TILE_FLOOR:
                sprite = Entity(x, y, FLOOR_TEXTURE_ID, colors['transparent'])
                sprite.name = "Ground"
                sprite.block_sight = False
                sprite.visible_color = colors["light_ground"]
                sprite.not_visible_color = colors["dark_ground"]
            elif game_map[x][y] == TILE_STAIRS_DOWN:
                sprite = Stairs(x, y, STAIRS_DOWN_TEXTURE_ID,
                                colors['transparent'])
                sprite.name = "Stairs Down"
                sprite.block_sight = False
                sprite.visible_color = colors["light_ground"]
                sprite.not_visible_color = colors["dark_ground"]
            elif game_map[x][y] == TILE_HEALING_POTION:
                sprite = Potion(x, y)
            elif game_map[x][y] == TILE_LIGHTNING_SCROLL:
                sprite = LightningScroll(x, y)
            elif game_map[x][y] == TILE_FIREBALL_SCROLL:
                sprite = FireballScroll(x, y)
            elif game_map[x][y]:
                raise ValueError(f"Unknown number in map: {game_map[x][y]}")

            if sprite:
                sprite_list.append(sprite)
        # print()

    return sprite_list
コード例 #2
0
def make_monster_sprite(monster_dict):
    sprite = Entity()
    sprite.texture = load_texture(monster_dict['Texture'])
    sprite.ai = BasicMonster()
    sprite.ai.owner = sprite
    sprite.fighter = Fighter()
    sprite.fighter.owner = sprite
    sprite.fighter.hp = int(monster_dict['HP'])
    sprite.fighter.power = int(monster_dict['Attack'])
    sprite.fighter.defense = int(monster_dict['Defense'])
    sprite.fighter.xp_reward = int(monster_dict['XP'])
    sprite.not_visible_color = colors['transparent']
    sprite.blocks = True
    sprite.name = monster_dict['Name']
    return sprite