Beispiel #1
0
def entity(ciao):
    e = Entity()
    e.model = ciao.get('model', None)
    e.scale = ciao.get('scale')
    e.components = ciao.get('components', [])
    e.tag = ciao.get('tag', None)
    children = ciao.get('children')
    if children:
        tile_size = getattr(
            monkey.engine.data.globals, 'tile_size',
            [1, 1])  # monkey.engine.room_vars.get('tile_size', [1, 1])
        for c in children:
            entity_desc = c
            positions = c.get('pos', [0, 0, 0])
            if 'ref' in c:
                entity_desc = monkey.engine.get_asset(entity_desc, c['ref'])
            factory = monkey.engine.get_item_factory(entity_desc['type'])
            if not factory:
                print('Don' 't have factory for item: ' + entity_desc['type'])
                exit(1)
            for ip in range(0, len(positions), 3):
                pos = positions[ip:ip + 3]
                child = factory(entity_desc)
                child.pos = tiles_to_world(pos, tile_size)
                e.children.append(child)

    return e
Beispiel #2
0
def common3D(ciao):
    dt = monkey.engine.data.globals

    e = Entity()
    e.layer = 1
    e.tag = ciao.get('tag', None)
    scale = ciao.get('scale', 1)
    e.scale = (scale, scale, 1)
    e.model = ciao.get('model', None)
    energy = ciao.get('energy', 1)
    if isinstance(e.model, dict):
        ciao = copy.deepcopy(mopy.monkey.engine.get_asset(e.model['template']))
        f = getattr(mopy.monkey.engine.data.scripts, ciao['builder'])
        if not f:
            print("hey I need a function: " + f + " to create the model")
        e.model = f(ciao, e.model['args'])
    size = ciao.get('size', dt.default_size)

    show_boxes = getattr(monkey.engine.data.globals, 'show_boxes', False)

    e.components.append({
        'type': 'components.controller3D',
        'maxClimbAngle': 80,
        'maxDescendAngle': 80,
        'size': size,
        'offset': [0, size[1] * 0.5, 0],
        'mask_up': 2,
        'mask_down': 2 | 32,
        'debug': show_boxes
    })
    e.add_component({'type': 'components.dynamics3D'})
    e.add_component({
        'type': 'components.info',
        'stuff': {
            'energy': energy,
            'attacks': ciao.get('attacks', None)
        }
    })

    # scaling should be applied only if current room has a scaling associated
    if dt.room_scaling:
        e.add_component({
            'type': 'components.scaler',
            'p0': dt.room_scaling[0],
            'p1': dt.room_scaling[1]
        })
    # shadow
    apply_shadow = getattr(dt, 'apply_shadow', False)
    if apply_shadow:
        shadow = Entity()
        shadow.add_component(ShadowRenderer(**dt.shadow))
        e.add(shadow)
    return e