Exemplo n.º 1
0
def map_room(desc: dict):
    gl = mopy.monkey.engine.data.globals
    room = ScummRoom(desc)
    room.add_runner(Scheduler())
    width = desc['width']
    height = desc['height']
    device_size = mopy.monkey.engine.device_size
    cam_width = device_size[0]
    cam_height = device_size[1]
    # add the main node
    room.default_item = 'main'
    main = Entity(tag='main')
    main.camera = OrthoCamera(width,
                              height,
                              cam_width,
                              cam_height, [0, 0, cam_width, cam_height],
                              tag='maincam')
    main.add_component(HotSpotManager(lmbclick=walk_to))
    room.add(main)
    cursor = Text(font=gl.default_font,
                  size=8,
                  text='#',
                  color=(255, 255, 255, 255),
                  tag='_cursor')
    cursor.add_component(Cursor())
    main.add(cursor)
    # add static items
    room.add_items(desc)
    # add dynamic items
    room.load_dynamic_items()
    return room
Exemplo n.º 2
0
def brick(ciao):
    e = Entity()
    e.model = ciao.get('model', None)
    hits_left = ciao.get('hits_left', 1)
    bonus_item = ciao.get('item', None)
    collision_tag = data.CollisionTags.bonus_brick_sensor if bonus_item else data.CollisionTags.basic_brick_sensor
    tile_size = getattr(monkey.engine.data.globals, 'tile_size', [1, 1])
    hidden = ciao.get('hidden', False)
    if hidden:
        collision_tag = data.CollisionTags.hidden_brick_sensor
    e.components.append({
        'type': 'components.collider',
        'shape': {
            'type': 'rect',
            'width': tile_size[0],
            'height': tile_size[1],
        },
        'tag': 0,
        'flag': 0 if hidden else 2,
        'mask': 0,
        'debug': True
    })
    e.components.append({
        'type': 'components.info',
        'stuff': {
            'hits_left': hits_left,
            'item': bonus_item
        }
    })
    e.components.append({'type': 'components.dynamics'})
    e.components.append({'type': 'components.platform'})
    e.components.append({
        'type': 'components.line_dynamic_mover',
        'direction': (0, 1),
        'acceleration': (0, -data.globals.gravity),
        'min': 0
    })
    # add brick sensor
    sensor = Entity()
    sensor.pos = [0.1 * tile_size[0], -0.1 * tile_size[1], 0]
    sensor.components.append({
        'type': 'components.collider',
        'shape': {
            'type': 'shape3d.aabb',
            'size': [0.8 * tile_size[0], 0.2 * tile_size[1], 0]
        },
        'tag': collision_tag,
        'mask': data.CollisionFlags.player,
        'flag': data.CollisionFlags.foe,
        'debug': True
    })

    e.add(sensor)
    return e
Exemplo n.º 3
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
Exemplo n.º 4
0
def dialogue_room(desc: dict):
    gl = mopy.monkey.engine.data.globals
    room = ScummRoom(desc)
    room.add_runner(Scheduler())
    room.init.append([refresh_inventory])
    # read world size
    width = desc['width']
    height = desc['height']

    device_size = mopy.monkey.engine.device_size
    cam_width = device_size[0]
    cam_height = device_size[1] - gl.ui_height

    # add the main node
    room.default_item = 'main'
    main = Entity(tag='main')
    main.camera = OrthoCamera(width,
                              height,
                              cam_width,
                              cam_height,
                              [0, gl.ui_height, cam_width, cam_height],
                              tag='maincam')
    room.add(main)

    # add the ui node
    ui = Entity(tag='ui')
    ui.camera = OrthoCamera(cam_width,
                            gl.ui_height,
                            cam_width,
                            gl.ui_height, [0, 0, cam_width, gl.ui_height],
                            tag='uicam')
    room.add(ui)

    # dialogue node
    dialogue_node = TextView(factory=make_dialogue_button,
                             pos=(0, 0),
                             size=(320, 56),
                             font_size=8,
                             lines=7,
                             delta_x=26,
                             tag='dialogue')
    dialogue_node.add_component(HotSpotManager())
    room.add(dialogue_node)

    inventory_node = Entity(tag='inventory')
    ui.add(inventory_node)

    # add static items
    room.add_items(desc)
    room.load_dynamic_items()
    return room
Exemplo n.º 5
0
def brick(ciao):
    e = Entity()
    tile_size = getattr(monkey.engine.data.globals, 'tile_size', [1, 1])
    e.components.append({
        'type': 'components.collider',
        'shape': {
            'type': 'rect',
            'width': tile_size[0],
            'height': tile_size[1],
        },
        'tag': 0,
        'flag': 2,
        'mask': 0,
        'debug': True
    })
    e.components.append({'type': 'components.dynamics'})
    e.components.append({'type': 'components.platform'})
    e.components.append({
        'type': 'components.line_dynamic_mover',
        'direction': (0, 1),
        'acceleration': (0, -data.globals.gravity),
        'min': 0
    })
    # add brick sensor
    sensor = Entity()
    sensor.pos = [0.1 * tile_size[0], -0.1 * tile_size[1], 0]
    sensor.components.append({
        'type': 'components.collider',
        'shape': {
            'type': 'shape3d.aabb',
            'size': [0.8 * tile_size[0], 0.2 * tile_size[1], 0]
        },
        'tag': data.CollisionTags.brick_sensor,
        'mask': data.CollisionFlags.player,
        'flag': data.CollisionFlags.foe,
        'debug': True
    })

    e.add(sensor)
    return e
Exemplo n.º 6
0
def sierra_room(desc: dict):
    gl = mopy.monkey.engine.data.globals
    room = ScummRoom(desc)

    # read world size
    width = desc['width']
    height = desc['height']

    device_size = mopy.monkey.engine.device_size
    cam_width = device_size[0]
    cam_height = device_size[1]

    # add the main node
    room.default_item = 'main'
    main = Entity(tag='main')
    main.camera = OrthoCamera(width,
                              height,
                              gl.sci_viewport[2],
                              gl.sci_viewport[3],
                              gl.sci_viewport,
                              tag='maincam')
    main.add_component(
        HotSpotManager(lmbclick=sierra_walk_to, rmbclick=toggle_cursor))
    room.add(main)

    # add the ui node
    ui = Entity(tag='ui')
    ui.camera = OrthoCamera(cam_width, cam_height, cam_width, cam_height,
                            [0, 0, cam_width, cam_height])
    ui.add(
        Text(text=mopy.monkey.engine.title,
             color=gl.ui_txt_color,
             pos=(0, cam_height),
             align=TextAlignment.top_left,
             font=gl.msg_font,
             size=8))
    ui.add(
        Text(text=str(gl.score) + ' of ' + str(gl.max_score),
             color=gl.ui_txt_color,
             pos=(cam_width, cam_height),
             align=TextAlignment.top_right,
             font=gl.msg_font,
             size=8))
    room.add(ui)

    a = Sprite(model='01.cursor', tag='cursor')
    a.add_component(Cursor())
    a.pos = (0, 0, 5)
    main.add(a)
    # add static items
    room.add_items(desc)
    # add dynamic items
    room.load_dynamic_items()
    return room
Exemplo n.º 7
0
def default_room(desc: dict):
    gl = mopy.monkey.engine.data.globals
    room = ScummRoom(desc)
    room.add_runner(Scheduler())
    room.init.append([refresh_inventory])
    # read world size
    width = desc['width']
    height = desc['height']

    device_size = mopy.monkey.engine.device_size
    cam_width = device_size[0]
    cam_height = device_size[1] - gl.ui_height

    # add the main node
    room.default_item = 'main'
    main = Entity(tag='main')
    main.camera = OrthoCamera(width,
                              height,
                              cam_width,
                              cam_height,
                              [0, gl.ui_height, cam_width, cam_height],
                              tag='maincam')
    main.add_component(HotSpotManager(lmbclick=walk_to))
    room.add(main)
    # get the verb set from the description. If not specified, verb set 0 will be used
    verb_set = desc.get('verb_set', 0)
    vset = gl.verb_sets[verb_set]
    dv = gl.verbs[vset['default_verb']]
    gl.current_verb = vset['default_verb']
    gl.current_item_1 = ''
    gl.current_item_2 = ''

    # add the ui node
    ui = Entity(tag='ui')
    ui.camera = OrthoCamera(cam_width,
                            gl.ui_height,
                            cam_width,
                            gl.ui_height, [0, 0, cam_width, gl.ui_height],
                            tag='uicam')
    ui.add(
        Text(font='fonts.ui',
             size=gl.font_size,
             text=mopy.monkey.engine.read(dv['text']),
             color=gl.Colors.current_action,
             align=TextAlignment.bottom,
             tag='current_verb',
             pos=(cam_width / 2, 48, 0)))
    ui.add_component(HotSpotManager())
    cy = gl.ui_height - 2 * gl.font_size
    count = 0
    shift = 0
    shift_applied = 46
    for i in vset['verbs']:
        cx = (count // 4) * shift_applied
        cy = gl.ui_height - (2 + count % 4) * gl.font_size
        e = make_verb_button(i, (cx, cy, 0))
        shift = max(shift,
                    1 + len(mopy.monkey.engine.read(gl.verbs[i]['text'])))
        ui.add(e)
        count += 1
    room.add(ui)
    # inventory node
    inventory_node = TextView(factory=make_inventory_button,
                              pos=(160, 0),
                              size=(160, 48),
                              font_size=8,
                              lines=6,
                              delta_x=26,
                              tag='inventory')
    inventory_node.add_component(HotSpotManager())
    ui.add(inventory_node)

    # dialogue node
    dialogue_node = TextView(factory=make_dialogue_button,
                             pos=(0, 0),
                             size=(320, 56),
                             font_size=8,
                             lines=7,
                             delta_x=26,
                             tag='dialogue')
    dialogue_node.add_component(HotSpotManager())
    room.add(dialogue_node)

    # add static items
    room.add_items(desc)
    # add dynamic items
    room.load_dynamic_items()
    # print (' ### looking up for dynamic items in room ' + desc['id'])
    # for r in mopy.monkey.engine.data.r2i.get(desc['id'], []):
    #     print('QUI')
    #     entity = create_dynamic(r)
    #     item = mopy.monkey.engine.data.items.get(r)
    #     print(item.get('parent', room.default_item) +' facomi')
    #     room.add(entity, item.get('parent', room.default_item))
    return room
Exemplo n.º 8
0
def scoreboard(args):
    glo = mopy.monkey.engine.data.globals
    font = 'sprites.mario_font'
    board = Entity()
    board.add(
        Text(font=font,
             size=8,
             text='MARIO',
             color=(1, 1, 1, 1),
             align=TextAlignment.top_left,
             pos=(32, 224, 0)))
    board.add(
        Text(font=font,
             size=8,
             text=str(glo.score),
             color=(1, 1, 1, 1),
             align=TextAlignment.top_left,
             pos=(32, 216, 0),
             tag='label_score'))
    board.add(
        Text(font=font,
             size=8,
             text='WORLD',
             color=(1, 1, 1, 1),
             align=TextAlignment.top_left,
             pos=(136, 224, 0)))
    board.add(
        Text(font=font,
             size=8,
             text='x',
             color=(1, 1, 1, 1),
             align=TextAlignment.bottom,
             pos=(158, 208, 0),
             tag='label_world'))
    board.add(
        Text(font=font,
             size=8,
             text='TIME',
             color=(1, 1, 1, 1),
             align=TextAlignment.bottom_right,
             pos=(224, 216, 0)))
    board.add(
        Text(font=font,
             size=8,
             text='0',
             color=(1, 1, 1, 1),
             align=TextAlignment.bottom_right,
             pos=(224, 208, 0),
             tag='label_time'))
    return board