Exemple #1
0
def load(level_name, keep_config=False, keep_velocity=False):
    global current_level, player
    reset()
    current_level = level_name
    
    path = os.path.join(level_dir, level_name+".yaml")
    stream = file(path, 'r')
    yaml_objects = yaml.load(stream)
    stream.close()
    
    load_geometry(yaml_objects)
    load_yaml_objects(yaml_objects)
    
    shapeloaders.add_line(0, 0, width, 0)
    shapeloaders.add_line(width, 0, width, height)
    shapeloaders.add_line(width, height, 0, height)
    shapeloaders.add_line(0, height, 0, 0)
    
    physics.space.resize_static_hash()
    physics.space.resize_active_hash()
    if not keep_config:
        init_player(player_start_x, player_start_y, math.pi/2, player_config)
        player.body.angle = player_start_angle
    else:
        player.body.position.x = player_start_x
        player.body.position.y = player_start_y
        if not keep_velocity:
            player.body.velocity.x = 0.0
            player.body.velocity.y = 0.0
        physics.body_update_list.append(player)
        physics.unit_update_list.extend(player.units)
        physics.space.add(player.body)
        for unit in player.units:
            if hasattr(unit, 'update_patients_now'):
                unit.update_patients_now = True
            unit.add_shapes()
            unit.batch = None
            unit.batch = batch
            unit.migrate()
    resources.wall_sound = resources.metal_against_metal2        
    event.update_player_units(player.units)
    level_module = __import__(level_name)
    if hasattr(level_module, 'init'): level_module.init()
Exemple #2
0
def load_geometry(yaml_objects):
    global width, height
    global background_image, prim_color
    decal.decals = []
    
    for obj in yaml_objects:
        if obj.yaml_tag == u"!Env":
            width, height = obj.width, obj.height
            env.prim_color = tuple([c/255.0 for c in obj.prim_color])
            background_image = pyglet.image.TileableTexture.create_for_image(
                getattr(resources, obj.background_image)
            )
        else:
            try:
                getattr(shapeloaders, obj.yaml_tag[1:])(obj)
            except:
                pass #yeah, I know, bad
    
    shapeloaders.add_line(0, 0, width, 0)
    shapeloaders.add_line(width, 0, width, height)
    shapeloaders.add_line(width, height, 0, height)
    shapeloaders.add_line(0, height, 0, 0)