예제 #1
0
파일: items.py 프로젝트: fabr1z10/glib3
 def f(*args):
     key = args[0]
     desc = args[1]
     cio = desc.get('create_if_owned', False)
     if (not cio) and key in vars.inventory:
         # item is in inventory. don't create it
         return None
     pos = desc.get('pos')
     model = desc.get('model', None)
     #text = monkey.engine.read(desc.get('text'))
     s = None
     if model:
         anim = monkey.engine.read(desc.get('anim', None))
         s = entity.Sprite(model=model, pos=pos, anim=anim)
     else:
         s = entity.Entity(pos=pos)
     #s.tag = desc.get('tag', None)
     s.tag = key
     # if a size is provided, add a hotspot
     size = desc.get('size', None)
     if size:
         print('size is ' + str(size))
         s.add_component(
             compo.HotSpot(shape=shapes.Rect(width=size[0], height=size[1]),
                           onenter=func.hover_on(key),
                           onleave=func.hover_off(key),
                           onclick=func.prova()))
     return s
예제 #2
0
파일: items.py 프로젝트: fabr1z10/glib3
 def f(*args):
     desc = args[1]
     pos = desc.get('pos')
     size = desc.get('size')
     s = entity.Entity(pos=pos)
     fu = getattr(scripts.actions, desc.get('func'))
     s.add_component(
         compo.HotSpot(shape=shapes.Rect(width=size[0], height=size[1]),
                       onclick=fu))
     return s
예제 #3
0
파일: items.py 프로젝트: fabr1z10/glib3
 def f(*args):
     desc = args[1]
     pos = desc.get('pos')
     size = desc.get('size')
     s = entity.Entity(pos=pos)
     s.add_component(
         compo.Collider(flag=vars.Collision.Flags.other,
                        mask=vars.Collision.Flags.player,
                        tag=vars.Collision.Tags.trap,
                        shape=shapes.Rect(width=size[0], height=size[1]),
                        debug=True))
     s.add_component(compo.Info(func=desc.get('func')))
     return s
예제 #4
0
파일: items.py 프로젝트: fabr1z10/glib3
 def f(*args):
     key = args[0]
     is_player = key == data.current_player
     desc = args[1]
     model = desc.get('model', None)
     text_color = monkey.engine.read(
         desc.get('text_color', [255, 255, 255, 255]))
     #text_color =
     text_offset = desc.get('text_offset', [0, 60])
     pos = monkey.engine.read(desc.get('pos'))
     tag = desc.get('tag', key)
     speed = desc.get('speed', 100)
     print(tag + " pos is " + str(pos))
     s = None
     dir = desc.get('dir', 's')
     if model:
         s = entity.Sprite(model=model,
                           pos=pos,
                           tag='player' if is_player else tag)
         s.add_component(
             compo.Collider(debug=True,
                            flag=data.Collision.Flags.player,
                            mask=data.Collision.Flags.other,
                            tag=data.Collision.Tags.player,
                            shape=shapes.Rect(width=8,
                                              height=2,
                                              offset=[-4, 0])))
         if is_player:
             s.add_component(compo.Follow())
     else:
         s = entity.Entity(pos=pos, tag='player' if is_player else tag)
     s.add_component(
         scumm.components.CharacterController(dir=dir,
                                              speed=speed,
                                              text_color=text_color,
                                              text_offset=text_offset))
     # if a size is provided, add a hotspot
     size = desc.get('size', None)
     if size:
         print('size is ' + str(size))
         s.add_component(
             compo.HotSpot(shape=shapes.Rect(width=size[0],
                                             height=size[1],
                                             offset=[-0.5 * size[0], 0]),
                           onenter=func.hover_on(key),
                           onleave=func.hover_off(key),
                           onclick=func.prova()))
     return s
예제 #5
0
파일: items.py 프로젝트: fabr1z10/glib3
 def f(*args):
     key = args[0]
     desc = args[1]
     pos = desc.get('pos')
     size = desc.get('size')
     text = monkey.engine.read(desc.get('text'))
     s = entity.Entity(pos=pos)
     s.add_component(
         compo.HotSpot(shape=shapes.Rect(width=size[0],
                                         height=size[1],
                                         offset=(-size[0] * 0.5,
                                                 -size[1] * 0.5)),
                       onenter=func.hover_on_map_hotspot(text),
                       onleave=func.hover_off_map_hotspot(),
                       onclick=func.click_on_map_hotspot(key)))
     return s
예제 #6
0
파일: items.py 프로젝트: fabr1z10/glib3
 def f(*args):
     e = entity.Entity(pos=(args[0], args[1], args[2]))
     e.tag = kwargs.get('id')
     shape = None
     if 'outline' in kwargs:
         # shape is a polygon
         shape = shapes.Poly(kwargs.get('outline'))
         if 'holes' in kwargs:
             for hole in kwargs['holes']:
                 shape.holes.append(hole)
     else:
         # shape is a polyline
         shape = shapes.PolyLine(kwargs.get('nodes'), kwargs.get('edges'))
     walkarea = scumm.components.Walkarea(shape=shape)
     walkarea.depth = kwargs.get('depth', None)
     walkarea.scale = kwargs.get('scale', None)
     walls = kwargs.get('walls', None)
     if walls:
         for w in walls:
             active = monkey.engine.read(w[4] if w[4:] else True)
             print('fottimi ' + str(active))
             walkarea.add_wall([w[0], w[1]], [w[2], w[3]], active)
     e.add_component(walkarea)
     return e
예제 #7
0
파일: items.py 프로젝트: fabr1z10/glib3
 def f(*args):
     e = entity.Entity(pos=(args[0], args[1], args[2]))
     e.add_component(compo.Gfx(image=kwargs['image']))
     return e
예제 #8
0
파일: room.py 프로젝트: fabr1z10/glib3
def default_room(desc: dict):
    id = desc['id']
    width = desc['width']
    height = desc['height']
    r = room.Room(id)#, width, height)
    r.add_runner(runners.Scheduler())

    if 'on_start' in desc:
        r.on_start = getattr(scripts, desc['on_start'])

    # setup collision engine
    ce = runners.CollisionEngine(80, 80)
    ce.add_response(data.Collision.Tags.player, data.Collision.Tags.trap, runners.CollisionResponse(on_enter=func.on_enter_trap))
    r.add_runner(ce)
    print('uisize is ' + str(data.ui_height))
    device_size = monkey.engine.device_size
    cam_width = device_size[0]
    cam_height = device_size[1] - data.ui_height
    print ('device size is ' + str(monkey.engine.device_size))
    # # add the main node
    main = entity.Entity(tag='main')
    main.camera = cam.OrthoCamera(width, height, cam_width, cam_height, [0, data.ui_height, cam_width, cam_height], tag='maincam')
    main.add_component(compo.HotSpotManager(lmbclick=func.walkto))
    r.add(main)
    # # main.add (e.Text(font='ui', text='ciao', color = [255, 255, 255, 255], align = e.TextAlignment.bottom, pos = [camWidth/2, 16, 0]))
    verb_set = desc.get('verb_set', 0)
    # get current verb set
    vset = data.verb_sets[verb_set]
    dv = data.verbs[vset['default_verb']]
    data.current_verb = vset['default_verb']
    data.current_item_1 = ''
    data.current_item_2 = ''

    ui = entity.Entity(tag='ui')
    ui.camera = cam.OrthoCamera(cam_width, data.ui_height, cam_width, data.ui_height, [0, 0, cam_width, data.ui_height], tag='uicam')
    #monkey.engine.read(dv['text']
    ui.add(entity.Text(font='ui', size=8, text='mierda', color=data.Colors.current_action,
      align=entity.TextAlignment.bottom, tag='current_verb', pos=(cam_width / 2, 48, 0)))
    ui.add_component(compo.HotSpotManager())
    r.init.append(func.refresh_inventory)
    on_load = desc.get('on_load', None)
    if on_load:
        r.init.append(getattr(scripts, on_load))

    r.add(ui)
    cy = data.ui_height - 2 * data.font_size
    count = 0
    shift = 0
    shift_applied = 46
    for i in vset['verbs']:
        cx = (count // 4) * shift_applied
        cy = data.ui_height - (2 + count % 4) * data.font_size
        e = factories.items.make_verb_button(i, (cx, cy, 0))
        shift = max(shift, 1 + len(monkey.engine.read(data.verbs[i]['text'])))
        ui.add(e)
        count += 1
    # inventory node
    inventory_node = entity.TextView(factory=factories.items.make_inventory_button, pos=(160, 0), size=(160, 48),
                                     font_size=8, lines=6, delta_x=26, tag='inventory')
    inventory_node.add_component(compo.HotSpotManager())
    ui.add(inventory_node)

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


#     inventory_node.addComponent(compo.HotSpotManager())


    # now add all items
    if 'items' in desc:
        for item in desc['items']:
            factory_id = item['factory']
            factory = monkey.engine.get_item_factory(factory_id[0])
            if factory is None:
                print('Unable to find factory for item: ' + factory_id[0])
                exit(1)
            else:
                props = {} if len(factory_id) == 1 else factory_id[1]
                f = factory(**props)
                parent = item.get('parent', 'main')
                for a in item['d']:
                    e = f(*a)
                    r.add(e, parent)

    # add dynamic items
    if id in data.items_in_room:
        for key in data.items_in_room[id]:
            item_desc = data.items[key]
            tp = item_desc.get('type', None)
            if tp is None:
                print ('item ' + key + ' does not have type!')
                exit(1)
            print ('ciao ' + key)
            factory = getattr(factories.items, tp)
            e = factory()(key, item_desc)
            if e is not None:
                parent = item_desc.get('parent', 'main')
                print('adding ' + key)
                r.add(e, parent)
    return r
예제 #9
0
파일: room.py 프로젝트: fabr1z10/glib3
def map_room(desc: dict):
    id = desc['id']
    width = desc['width']
    height = desc['height']
    r = room.Room(id)#, width, height)
    r.add_runner(runners.Scheduler())

    # setup collision engine
    ce = runners.CollisionEngine(80, 80)
    ce.add_response(data.Collision.Tags.player, data.Collision.Tags.trap,
                    runners.CollisionResponse(on_enter=func.on_enter_trap))
    r.add_runner(ce)
    device_size = monkey.engine.device_size
    cam_width = device_size[0]
    cam_height = device_size[1]
    # # add the main node
    main = entity.Entity(tag='main')
    main.camera = cam.OrthoCamera(width, height, cam_width, cam_height, [0, 0, cam_width, cam_height],
                                  tag='maincam')
    main.add_component(compo.HotSpotManager(lmbclick=func.walkto))
    r.add(main)
    # # main.add (e.Text(font='ui', text='ciao', color = [255, 255, 255, 255], align = e.TextAlignment.bottom, pos = [camWidth/2, 16, 0]))
    on_load = desc.get('on_load', None)
    if on_load:
        r.init.append(getattr(scripts, on_load))

    # now add all items
    if 'items' in desc:
        for item in desc['items']:
            factory_id = item['factory']
            factory = monkey.engine.get_item_factory(factory_id[0])
            if factory is None:
                print('Unable to find factory for item: ' + factory_id[0])
                exit(1)
            else:
                props = {} if len(factory_id) == 1 else factory_id[1]
                f = factory(**props)
                parent = item.get('parent', 'main')
                for a in item['d']:
                    e = f(*a)
                    r.add(e, parent)

    cursor = entity.Text(font='monkey', size=8, text='', color=(255,255,255,255), tag='_cursor')
    cursor.add_component(compo.Cursor())

    main.add(cursor)
    # add dynamic items
    if id in data.items_in_room:
        for key in data.items_in_room[id]:
            item_desc = data.items[key]
            tp = item_desc.get('type', None)
            if tp is None:
                print('item ' + key + ' does not have type!')
                exit(1)
            print('ciao ' + key)
            factory = getattr(factories.items, tp)
            e = factory()(key, item_desc)
            if e is not None:
                parent = item_desc.get('parent', 'main')
                print('adding ' + key)
                r.add(e, parent)
    return r