Exemplo n.º 1
0
 def setup_unexplored_icon(self):
     texture_name = texture_manager.load_image(
         get_asset_path('assets', 'ui_elements', 'unexplored-icon.png'))
     model_manager = self.gameworld.model_manager
     self.unexplored_icon = model_manager.load_textured_rectangle(
         'vertex_format_4f',
         64,
         64,
         'unexplored-icon',
         '4f_unexplored-icon',
     )
     model = model_manager.models[self.unexplored_icon]
     vt1 = model[0]
     vt2 = model[1]
     vt3 = model[2]
     vt4 = model[3]
     u1, v1 = vt1.uvs
     u2, v2 = vt2.uvs
     u3, v3 = vt3.uvs
     u4, v4 = vt4.uvs
     vt1.uvs = (u1, v3)
     vt2.uvs = (u2, v4)
     vt3.uvs = (u3, v1)
     vt4.uvs = (u4, v2)
     self.unexplored_texture = 'unexplored-icon'
Exemplo n.º 2
0
 def load_music(self):
     sound_manager = self.gameworld.sound_manager
     sound_manager.loop_music = True
     for x in range(1, 11):
         name = 'track' + str(x)
         track_name = sound_manager.load_music(
             name, get_asset_path('assets', 'music', name + '.ogg'))
     sound_manager.play_track(choice(sound_manager.music_dict.keys()))
Exemplo n.º 3
0
 def setup_unexplored_icon(self):
     texture_name = texture_manager.load_image(
         get_asset_path('assets', 'ui_elements', 'unexplored-icon.png')
         )
     model_manager = self.gameworld.model_manager
     self.unexplored_icon = model_manager.load_textured_rectangle(
         'vertex_format_4f', 64, 64, 'unexplored-icon',
         '4f_unexplored-icon',
         )
     model = model_manager.models[self.unexplored_icon]
     vt1 = model[0]
     vt2 = model[1]
     vt3 = model[2]
     vt4 = model[3]
     u1, v1 = vt1.uvs
     u2, v2 = vt2.uvs
     u3, v3 = vt3.uvs
     u4, v4 = vt4.uvs
     vt1.uvs = (u1, v3)
     vt2.uvs = (u2, v4)
     vt3.uvs = (u3, v1)
     vt4.uvs = (u4, v2)
     self.unexplored_texture = 'unexplored-icon'
Exemplo n.º 4
0
class WaterDeliveryEnv:
    """A grid world where a robot must pick up a water bottle and then
    deliver water to all people in the grid. Rewards are given when each
    person is quenched.

    Parameters
    ----------
    layout : np.ndarray, layout.shape = (height, width, num_objects)
        The initial state.
    """
    # Types of objects
    OBJECTS = ROBOT, ROBOT_WITH_WATER, WATER, PERSON, QUENCHED_PERSON = range(
        5)

    # Create layouts
    DEFAULT_LAYOUT = np.zeros((5, 5, len(OBJECTS)), dtype=bool)
    DEFAULT_LAYOUT[4, 2, ROBOT] = 1
    DEFAULT_LAYOUT[0, 4, WATER] = 1
    DEFAULT_LAYOUT[1, 0, PERSON] = 1
    DEFAULT_LAYOUT[2, 0, PERSON] = 1
    DEFAULT_LAYOUT[3, 0, PERSON] = 1

    MEDIUM_LAYOUT = np.zeros((9, 9, len(OBJECTS)), dtype=bool)
    MEDIUM_LAYOUT[8, 4, ROBOT] = 1
    MEDIUM_LAYOUT[0, -1, WATER] = 1
    MEDIUM_LAYOUT[1, 0, PERSON] = 1
    MEDIUM_LAYOUT[5, 5, PERSON] = 1
    MEDIUM_LAYOUT[3, 4, PERSON] = 1
    MEDIUM_LAYOUT[4, 3, PERSON] = 1
    MEDIUM_LAYOUT[8, 7, PERSON] = 1
    MEDIUM_LAYOUT[6, 0, PERSON] = 1
    MEDIUM_LAYOUT[7, 2, PERSON] = 1

    HARD_LAYOUT = np.zeros((15, 15, len(OBJECTS)), dtype=bool)
    HARD_LAYOUT[14, 7, ROBOT] = 1
    HARD_LAYOUT[0, 14, WATER] = 1
    HARD_LAYOUT[1, 0, PERSON] = 1
    HARD_LAYOUT[5, 5, PERSON] = 1
    HARD_LAYOUT[9, 10, PERSON] = 1
    HARD_LAYOUT[4, 3, PERSON] = 1
    HARD_LAYOUT[10, 12, PERSON] = 1
    HARD_LAYOUT[11, 6, PERSON] = 1
    HARD_LAYOUT[13, 4, PERSON] = 1

    # Actions
    ACTIONS = UP, DOWN, LEFT, RIGHT = range(4)

    # Reward for quenching
    QUENCH_REWARD = 0.1
    WATER_PICKUP_REWARD = 0.01
    MAX_REWARD = max(QUENCH_REWARD, WATER_PICKUP_REWARD)

    # For rendering
    TOKEN_IMAGES = {
        ROBOT: plt.imread(get_asset_path('robot.png')),
        ROBOT_WITH_WATER: plt.imread(get_asset_path('robot_with_water.png')),
        WATER: plt.imread(get_asset_path('water.png')),
        PERSON: plt.imread(get_asset_path('person.png')),
        QUENCHED_PERSON: plt.imread(get_asset_path('quenched_person.png')),
    }

    OBJECT_CHARS = {
        ROBOT: "R",
        ROBOT_WITH_WATER: "R",
        WATER: "W",
        PERSON: "P",
        QUENCHED_PERSON: "X",
    }

    def __init__(self, layout=None, mode='default', num_alias_per_action=1):
        if layout is None:
            if mode == 'default':
                layout = self.DEFAULT_LAYOUT
            elif mode == 'medium':
                layout = self.MEDIUM_LAYOUT
            elif mode == 'hard':
                layout = self.HARD_LAYOUT
            else:
                raise Exception("Unrecognized mode.")
        self._initial_layout = layout
        self._layout = layout.copy()
        self._num_alias_per_action = num_alias_per_action

    def reset(self):
        self._layout = self._initial_layout.copy()
        return self.get_state(), {}

    def get_all_actions(self):
        actions = [a for a in self.ACTIONS]
        num_actions = len(actions)
        assert actions[0] == 0 and actions[-1] == len(actions) - 1
        for _ in range(self._num_alias_per_action):
            for _ in range(num_actions):
                actions.append(max(actions) + 1)
        return actions

    def step(self, action):
        # Handle action aliasing
        action = action % len(self.ACTIONS)

        # Start out reward at 0
        reward = 0

        # Move the robot
        rob_r, rob_c = None, None
        for robot_type in [self.ROBOT, self.ROBOT_WITH_WATER]:
            where_robot = np.argwhere(self._layout[..., robot_type])
            if len(where_robot) == 0:
                continue
            assert len(where_robot
                       ) == 1 or rob_r is not None, "Multiple robots in grid"
            rob_r, rob_c = where_robot[0]
            dr, dc = {
                self.UP: (-1, 0),
                self.DOWN: (1, 0),
                self.LEFT: (0, -1),
                self.RIGHT: (0, 1)
            }[action]
            new_r, new_c = rob_r + dr, rob_c + dc
            if 0 <= new_r < self._layout.shape[
                    0] and 0 <= new_c < self._layout.shape[1]:
                # Remove old robot
                self._layout[rob_r, rob_c, robot_type] = 0
                # Add new robot
                self._layout[new_r, new_c, robot_type] = 1
                # Update local vars
                rob_r, rob_c = new_r, new_c
        assert rob_r is not None, "Missing robot in grid"

        # Handle water pickup
        if self._layout[rob_r, rob_c,
                        self.ROBOT] and self._layout[rob_r, rob_c, self.WATER]:
            # Make robot have water
            self._layout[rob_r, rob_c, self.ROBOT_WITH_WATER] = 1
            self._layout[rob_r, rob_c, self.ROBOT] = 0
            # Remove water from grid
            self._layout[rob_r, rob_c, self.WATER] = 0
            # Reward for water pickup
            reward += self.WATER_PICKUP_REWARD

        # Handle people quenching
        if self._layout[rob_r, rob_c,
                        self.ROBOT_WITH_WATER] and self._layout[rob_r, rob_c,
                                                                self.PERSON]:
            # Quench person
            self._layout[rob_r, rob_c, self.QUENCHED_PERSON] = 1
            self._layout[rob_r, rob_c, self.PERSON] = 0
            # Reward for quenching
            reward += self.QUENCH_REWARD

        # Check done: all people quenched
        done = (len(np.argwhere(self._layout[..., self.PERSON])) == 0)

        return self.get_state(), reward, done, {}

    def render(self, dpi=150):
        return render_from_layout(self._layout,
                                  self._get_token_images,
                                  dpi=dpi)

    def _get_token_images(self, obs_cell):
        images = []
        for token in [
                self.ROBOT, self.ROBOT_WITH_WATER, self.WATER, self.PERSON,
                self.QUENCHED_PERSON
        ]:
            if obs_cell[token]:
                images.append(self.TOKEN_IMAGES[token])
        return images

    def state_to_str(self, state):
        layout = np.full(self._initial_layout.shape[:2], "O", dtype=object)
        for i, j, k in state:
            layout[i, j] = self.OBJECT_CHARS[k]
        return '\n' + '\n'.join(''.join(row) for row in layout)

    def get_state(self):
        return tuple(sorted(map(tuple, np.argwhere(self._layout))))

    def set_state(self, state):
        self._layout = np.zeros_like(self._initial_layout)
        for i, j, k in state:
            self._layout[i, j, k] = 1

    @functools.lru_cache(maxsize=1000)
    def compute_reward(self, state, action):
        original_state = self.get_state()
        self.set_state(state)
        _, reward, _, _ = self.step(action)
        self.set_state(original_state)
        return reward

    @functools.lru_cache(maxsize=1000)
    def compute_transition(self, state, action):
        original_state = self.get_state()
        self.set_state(state)
        next_state, _, _, _ = self.step(action)
        self.set_state(original_state)
        return next_state

    @functools.lru_cache(maxsize=1000)
    def compute_done(self, state, action):
        original_state = self.get_state()
        self.set_state(state)
        _, _, done, _ = self.step(action)
        self.set_state(original_state)
        return done

    @functools.lru_cache(maxsize=1000)
    def check_goal(self, state):
        for i, j, k in state:
            if k == self.PERSON:
                return False
        return True
Exemplo n.º 5
0
    def load_assets(self):
        model_manager = self.gameworld.model_manager
        emitter_system = self.ids.emitter
        projectile_system = self.ids.projectiles
        weapon_system = self.ids.weapons
        sound_manager = self.gameworld.sound_manager
        asteroid_system = self.ids.asteroids
        physics_system = self.ids.physics
        shield_system = self.ids.shields
        explosion_system = self.ids.explosions
        texture_manager.load_atlas(
            get_asset_path('assets', 'particles', 'particles.atlas'))
        texture_manager.load_image(
            get_asset_path('assets', 'objects', 'asteroid1.png'))
        texture_manager.load_image(
            get_asset_path('assets', 'objects', 'asteroid1-radar.png'))
        texture_manager.load_image(
            get_asset_path('assets', 'particles', 'particle3.png'))

        asteroid_model = model_manager.load_textured_rectangle(
            'vertex_format_4f',
            64,
            64,
            'asteroid1',
            '4f_asteroid1',
        )
        asteroid_radar_model = model_manager.load_textured_rectangle(
            'vertex_format_4f',
            64,
            64,
            'asteroid1-radar',
            '4f_asteroid1_radar',
        )
        asteroid_collision_type = physics_system.register_collision_type(
            'asteroids')
        ship_collision_type = physics_system.register_collision_type('ships')
        projectile_system.add_origin_collision_type(asteroid_collision_type)
        projectile_system.add_origin_collision_type(ship_collision_type)
        self.load_weapons()

        ship_hit_asteroid = sound_manager.load_sound('ship_hit_asteroid',
                                                     get_asset_path(
                                                         'assets', 'soundfx',
                                                         'shiphit.wav'),
                                                     track_count=2)
        asteroid_hit_asteroid = sound_manager.load_sound(
            'asteroid_hit_asteroid',
            get_asset_path('assets', 'soundfx', 'asteroidhitasteroid.wav'),
            track_count=2)
        emitter_system.load_effect(
            get_asset_path('assets', 'vfx', 'asteroidexplosion.kep'))
        emitter_system.load_effect(
            get_asset_path('assets', 'vfx', 'shipexplosion.kep'))
        explosion_system.register_template('ship_explosion', 'shipexplosion',
                                           3.0, 1.5)
        asteroid_system.register_template(
            'asteroid1',
            asteroid_collision_type,
            mass=125.,
            radius=30.,
            texture='asteroid1',
            model_key=asteroid_model,
            health=15.,
            armor=4.,
            ship_collision_sound=ship_hit_asteroid,
            asteroid_collision_sound=asteroid_hit_asteroid,
            radar_model=asteroid_radar_model,
            radar_texture='asteroid1-radar')

        explosion_system.register_template('asteroid_explosion',
                                           'asteroidexplosion', 1.5, 1.0)
        physics_system.add_collision_handler(
            asteroid_collision_type,
            ship_collision_type,
            begin_func=asteroid_system.on_collision_begin_asteroid_ship)
        physics_system.add_collision_handler(
            asteroid_collision_type,
            asteroid_collision_type,
            begin_func=asteroid_system.on_collision_begin_asteroid_asteroid)
        physics_system.add_collision_handler(
            asteroid_collision_type,
            shield_system.shield_collision_type,
            begin_func=shield_system.on_collision_begin_asteroid_shield)
        physics_system.add_collision_handler(
            shield_system.shield_collision_type,
            shield_system.shield_collision_type,
            begin_func=shield_system.on_collision_begin_shield_shield)
        physics_system.add_collision_handler(
            ship_collision_type,
            shield_system.shield_collision_type,
            begin_func=shield_system.on_collision_begin_ship_shield)
        projectile_system.add_custom_collision_type(
            shield_system.shield_collision_type,
            shield_system.on_collision_begin_bullet_shield)
        self.load_ships(ship_collision_type)
Exemplo n.º 6
0
    def load_weapons(self):
        emitter_system = self.ids.emitter
        projectile_system = self.ids.projectiles
        sound_manager = self.gameworld.sound_manager
        weapon_system = self.ids.weapons
        model_manager = self.gameworld.model_manager
        explosion_system = self.ids.explosions
        emitter_system.load_effect(
            get_asset_path('assets', 'vfx', 'blaster_projectile.kep'))
        blaster_hit_sound = sound_manager.load_sound('blaster_hit',
                                                     get_asset_path(
                                                         'assets', 'soundfx',
                                                         'blaster', 'hit.wav'),
                                                     track_count=2)
        blaster_bullet_type = projectile_system.register_projectile_template(
            'blaster_projectile',
            10.,
            1.,
            1,
            None,
            None,
            12,
            12,
            1.,
            550.,
            50.,
            main_effect="blaster_projectile",
            hit_sound=blaster_hit_sound,
            destruction_callback=self.spawn_explosion_for_blaster)
        blaster_begin = sound_manager.load_sound(
            'blaster-reload-begin',
            get_asset_path('assets', 'soundfx', 'blaster', 'reload-laser.wav'),
            track_count=2)
        blaster_end = sound_manager.load_sound(
            'blaster-reload-end',
            get_asset_path('assets', 'soundfx', 'blaster', 'reload-end.wav'),
            track_count=2)
        blaster_fire_sound = sound_manager.load_sound(
            'blaster-shoot',
            get_asset_path('assets', 'soundfx', 'blaster', 'shoot.wav'),
            track_count=2)
        emitter_system.load_effect(
            get_asset_path('assets', 'vfx', 'orb_explosion.kep'))
        explosion_system.register_template('orb_explosion', 'orb_explosion',
                                           .3, .6)

        weapon_system.register_weapon_template(
            'ship1_blaster',
            'Blaster',
            reload_time=3.5,
            projectile_type=1,
            ammo_count=100,
            rate_of_fire=.4,
            clip_size=14,
            barrel_offsets=[(46., 59.), (-46., 59.)],
            barrel_count=2,
            ammo_type=blaster_bullet_type,
            projectile_width=12.,
            projectile_height=12.,
            accel=500,
            reload_begin_sound=blaster_begin,
            reload_end_sound=blaster_end,
            fire_sound=blaster_fire_sound,
            spread=radians(0.),
            shot_count=1,
            time_between_shots=0.35,
        )
        rifle_hit_sound = sound_manager.load_sound('blaster_hit',
                                                   get_asset_path(
                                                       'assets', 'soundfx',
                                                       'rifle', 'hit.wav'),
                                                   track_count=2)

        bullet_tex = texture_manager.load_image(
            get_asset_path('assets', 'projectiles', 'bullet-14px.png'))
        bullet_model = model_manager.load_textured_rectangle(
            'vertex_format_4f', 28., 14., 'bullet-14px', '4f_bullet-14px')
        rifle_bullet_type = projectile_system.register_projectile_template(
            'rifle_projectile',
            12.,
            1.,
            1,
            'bullet-14px',
            bullet_model,
            14.,
            14.,
            10,
            750.,
            50.,
            hit_sound=rifle_hit_sound)

        rifle_begin = sound_manager.load_sound(
            'rifle-reload-begin',
            get_asset_path('assets', 'soundfx', 'rifle', 'reload-begin.wav'),
            track_count=2)
        rifle_end = sound_manager.load_sound('rifle-reload-end',
                                             get_asset_path(
                                                 'assets', 'soundfx', 'rifle',
                                                 'reload-end.wav'),
                                             track_count=2)
        rifle_fire_sound = sound_manager.load_sound('rifle-shoot',
                                                    get_asset_path(
                                                        'assets', 'soundfx',
                                                        'rifle', 'shoot.wav'),
                                                    track_count=2)
        weapon_system.register_weapon_template(
            'ship1_rifle',
            'Rifle',
            reload_time=5.0,
            projectile_type=3,
            ammo_count=100,
            rate_of_fire=.5,
            clip_size=8,
            barrel_offsets=[(46., 59.), (-46., 59.)],
            barrel_count=2,
            ammo_type=rifle_bullet_type,
            projectile_width=12.,
            projectile_height=12.,
            accel=10000.,
            reload_begin_sound=rifle_begin,
            reload_end_sound=rifle_end,
            fire_sound=rifle_fire_sound,
            spread=radians(0.),
            shot_count=2,
            time_between_shots=.1,
        )

        shotgun_begin = sound_manager.load_sound(
            'shotgun-reload-begin',
            get_asset_path('assets', 'soundfx', 'shotgun', 'reload-begin.wav'))
        shotgun_end = sound_manager.load_sound(
            'shotgun-reload-end',
            get_asset_path('assets', 'soundfx', 'shotgun', 'reload-end.wav'))
        shotgun_fire_sound = sound_manager.load_sound(
            'shotgun-shoot',
            get_asset_path('assets', 'soundfx', 'shotgun', 'shoot.wav'))

        shotgun_bullet_tex = texture_manager.load_image(
            get_asset_path('assets', 'projectiles', 'bullet-6px.png'))
        shotgun_bullet_model = model_manager.load_textured_rectangle(
            'vertex_format_4f', 6., 6., 'bullet-6px', '4f_bullet-6px')
        shotgun_bullet_type = projectile_system.register_projectile_template(
            'shotgun_projectile',
            7.,
            1.,
            1,
            'bullet-6px',
            shotgun_bullet_model,
            4.5,
            4.5,
            2.5,
            750.,
            50.,
            lifespan=2.0,
            hit_sound=rifle_hit_sound)
        weapon_system.register_weapon_template(
            'ship1_shotgun',
            'Shotgun',
            reload_time=2.5,
            projectile_type=1,
            ammo_count=100,
            rate_of_fire=.70,
            clip_size=8,
            barrel_offsets=[(46., 59.), (-46., 59.)],
            barrel_count=2,
            ammo_type=shotgun_bullet_type,
            projectile_width=4.,
            projectile_height=4.,
            accel=3000,
            reload_begin_sound=shotgun_begin,
            reload_end_sound=shotgun_end,
            fire_sound=shotgun_fire_sound,
            spread=radians(15.),
            shot_count=5,
            time_between_shots=0.,
        )
Exemplo n.º 7
0
    def load_ships(self, ship_collision_type):
        ship_system = self.ids.ship_system
        emitter_system = self.ids.emitter
        physics_system = self.ids.physics
        model_manager = self.gameworld.model_manager
        sound_manager = self.gameworld.sound_manager
        player_system = self.ids.player
        radar_texture = texture_manager.load_image(
            get_asset_path('assets', 'ships', 'ship1-radar.png'))
        texture_name = texture_manager.load_image(
            get_asset_path('assets', 'ships', 'ship1.png'))
        radar_model_name = model_manager.load_textured_rectangle(
            'vertex_format_4f', 104, 128, 'ship1-radar', '4f_ship1_radar')
        model_name = model_manager.load_textured_rectangle(
            'vertex_format_4f',
            104,
            128,
            'ship1',
            '4f_ship1',
        )
        effect_name = emitter_system.load_effect(
            get_asset_path('assets', 'vfx', 'engine1.kep'))
        shield_model_data = generate_shield_model(85., 10.)
        shield_model = model_manager.load_model(
            'vertex_format_2f4ub',
            shield_model_data['vert_count'],
            shield_model_data['ind_count'],
            'shield_model',
            indices=shield_model_data['indices'],
            vertices=shield_model_data['vertices'],
            do_copy=False)

        explosion_sound = sound_manager.load_sound(
            'explosion_sound',
            get_asset_path('assets', 'soundfx', 'explosion.wav'))
        ship_system.register_template('ship1',
                                      'Bulldog',
                                      model_name,
                                      'ship1',
                                      ship_collision_type,
                                      health=100.,
                                      mass=250.,
                                      max_speed=200.,
                                      max_turn_speed=200.,
                                      accel=15000.,
                                      angular_accel=45.,
                                      boost_force=25000.,
                                      boost_drain=25.,
                                      max_boost_speed=300.,
                                      armor=5.,
                                      boost_reserve=50.,
                                      boost_regen=10.,
                                      width=96.,
                                      height=108.,
                                      weapons=['ship1_shotgun'],
                                      emitters=[effect_name],
                                      emitter_speed_base=90.,
                                      scale_base=2.2,
                                      emitter_scaling_factor=150.,
                                      explosion_sound=explosion_sound,
                                      has_shield=True,
                                      shield_model=shield_model,
                                      shield_health=100.,
                                      shield_radius=90.,
                                      shield_timeout=1.25,
                                      shield_recharge=20.,
                                      radar_model_name=radar_model_name,
                                      radar_texture='ship1-radar')
        ship_engine_rumble = sound_manager.load_sound(
            'engine_rumble',
            get_asset_path('assets', 'soundfx', 'shipengine.wav'),
        )
Exemplo n.º 8
0
 def _init_token_images(self):
     for obj in self.OBJECTS:
         self.TOKEN_IMAGES[obj.value] = plt.imread(
             get_asset_path(str(self.NAMES[obj.value]) + '.png'))
    def prepare_assets(self):
        # self.background = pygame.image.load(utils.get_asset_path("background_01.png")).convert()
        # self.background.set_colorkey(constants.WHITE)
        self.level_limit = -2500

        self.tiled_map = load_pygame(utils.get_asset_path(self.file_name))
        print(self.tiled_map)

        tile_width = self.tiled_map.tilewidth
        tile_height = self.tiled_map.tileheight
        map_width = self.tiled_map.width * tile_width
        map_height = self.tiled_map.height * tile_height

        self.world_offset_y = constants.SCREEN_HEIGHT - map_height

        order = 1
        for layer in self.tiled_map.layers:
            order += 1
            zindex = 200
            # zindex = order

            paralax = 1
            if "zindex" in layer.properties:
                zindex = int(layer.zindex)

            if "paralax" in layer.properties:
                paralax = int(layer.paralax) + 1

            # paralax = order

            # print("layer name", layer.name, "order", order, "zindex", zindex, "paralax vaue", paralax, zindex)
            if isinstance(layer, TiledTileLayer):

                for x, y, image in layer.tiles():
                    # sprite = Block(image, x*tile_width, y*tile_height + self.world_offset_y)
                    sprite = Block(image.convert_alpha(), x * tile_width,
                                   y * tile_height + self.world_offset_y)
                    if "background" in layer.properties and layer.properties[
                            'background'] == "true":
                        sprite._layer = zindex
                        if "solid" in layer.properties and layer.properties[
                                'solid'] == "true":
                            self.add_solid_sprite(sprite)
                        else:
                            self.add_background_sprite(sprite)

            elif isinstance(layer, TiledObjectGroup):
                for object in layer:
                    if "solid" in layer.properties and layer.solid == "true":
                        sprite = Block(object.image.convert_alpha(), object.x,
                                       object.y + self.world_offset_y)
                        sprite._layer = zindex
                        self.add_solid_sprite(sprite)
                    elif "enemy" in layer.properties and layer.enemy == "true":
                        hp = randint(20, 50)
                        if "hp" in layer.properties:
                            hp = int(layer.properties['hp'])

                        can_shoot = bool(random.getrandbits(1))
                        if "can_shoot" in layer.properties:
                            can_shoot = True if layer.properties[
                                'can_shoot'] == "true" else False

                        can_jump = bool(random.getrandbits(1))
                        if "can_jump" in layer.properties:
                            can_jump = True if layer.properties[
                                'can_jump'] == "true" else False

                        sprite = Enemy(
                            self.get_images_from_object(
                                self.tiled_map, object), object.x,
                            object.y + self.world_offset_y, hp)
                        sprite.can_shoot = can_shoot
                        sprite.can_jump = can_jump
                        sprite.level = self
                        self.add_enemy(sprite)
                        print("adding enemy")

                    elif "collectible" in layer.properties:
                        sprite = Collectible(object.image.convert_alpha(),
                                             object.x,
                                             object.y + self.world_offset_y,
                                             200)
                        sprite._layer = zindex + 200
                        self.add_collectible(sprite)
                        print("adding collectible")

                    elif "exit_condition" in layer.properties:
                        print("adding exit")
                        sprite = ExitBlock(object.image.convert_alpha(),
                                           object.x,
                                           object.y + self.world_offset_y)
                        sprite._layer = zindex + 200
                        self.add_exit(sprite)
                    else:
                        # print("PARALAX ", paralax)
                        sprite = ParalaxBlock(object.image.convert_alpha(),
                                              object.x,
                                              object.y + self.world_offset_y,
                                              paralax)
                        sprite._layer = zindex
                        self.add_background_sprite(sprite)
from utils import get_asset_path
from jnius import autoclass
from android.runnable import run_on_ui_thread
import kivent_core
import os

os.environ['KIVY_AUDIO'] = 'sdl2'

# sound_manager
sound_manager = self.gameworld.sound_manager

# Load sound
track = 'track1'
address = get_asset_path(track + '.ogg')
track_name = sound_manager.load_sound(track, address, track_count=1)

# Play sound
sound_manager.play_loop('track1', 1)

# Stop sound
sound_manager.stop('track1')

PythonActivity = autoclass('org.kivy.android.PythonActivity')
Context = autoclass('android.content.Context')
activity = PythonActivity.mActivity

# Accessing Vibrator_Service through Pyjnius
vibrator = activity.getSystemService(Context.VIBRATOR_SERVICE)

#Vibrate
if vibrator.hasVibrator():