Exemple #1
0
    def __init__(self, uid: str, width, height, world_width: int,
                 world_height: int, start_pos):
        super().__init__(uid, width, height)

        keyl = runners.KeyListener()
        # adding pause button
        keyl.add_key(key=32, func=func.toggle_pause)
        # restart on F10
        keyl.add_key(key=299, func=func.restart)
        self.add_runner(keyl)

        # self.keyl.addKey(key=264, func = checkWarp)

        main = Entity(tag='main')
        #main.camera = camera.OrthoCamera(world_width=world_width * vars.tile_size,
        #                                 world_height=world_height * vars.tile_size,
        #                                 cam_width=width, cam_height=height, viewport=[0, 0, width, height],
        #                                 tag='maincam')
        main.camera = camera.PerspectiveCamera(viewport=[0, 0, width, height],
                                               tag='maincam')
        main.camera.pos = (0, 1, 0)
        self.main = main
        self.add(main)

        # create the collision engine
        ce = runners.CollisionEngine(85, 85)
        self.add_runner(ce)

        self.add_runner(runners.Scheduler())

        self.dw = runners.DynamicWorld(256, 256, 'maincam')
        self.add_runner(self.dw)

        diag = Entity(tag='diag')
        diag.camera = camera.OrthoCamera(world_width=width,
                                         world_height=height,
                                         cam_width=width,
                                         cam_height=height,
                                         viewport=[0, 0, width, height],
                                         tag='diagcam')

        fps_count = Text('main',
                         8,
                         '0', [255, 255, 255, 255],
                         align=TextAlignment.top_left,
                         tag='fps',
                         pos=(0, 256, 2))
        fps_count.add_component(comp.FPSCounter())
        diag.add(fps_count)

        self.add(diag)
        e = Entity()
        e.add_component(Road())
        e.add_component(comp.KeyInput())
        main.add(e)
Exemple #2
0
    def __init__(self, uid: str, width, height, world_width: int,
                 world_height: int, start_pos):
        super().__init__(uid, width, height)

        keyl = runners.KeyListener()
        # adding pause button
        keyl.add_key(key=32, func=func.toggle_pause)
        # restart on F10
        keyl.add_key(key=299, func=func.restart)
        self.add_runner(keyl)

        # self.keyl.addKey(key=264, func = checkWarp)

        main = Entity(tag='main')
        main.camera = camera.OrthoCamera(
            world_width=world_width * vars.tile_size,
            world_height=world_height * vars.tile_size,
            cam_width=width,
            cam_height=height,
            viewport=[0, 0, width, height],
            tag='maincam')
        self.main = main
        self.add(main)

        # create the collision engine
        ce = runners.CollisionEngine(80, 80)
        ce.add_response(
            vars.tags.player, vars.tags.brick_sensor,
            runners.CollisionResponse(on_enter=func.brick_response))
        ce.add_response(
            vars.tags.player, vars.tags.bonus_brick_sensor,
            runners.CollisionResponse(on_enter=func.bonus_brick_response))
        ce.add_response(
            vars.tags.player, vars.tags.mushroom,
            runners.CollisionResponse(on_enter=func.mushroom_response))
        ce.add_response(
            vars.tags.player, vars.tags.warp,
            runners.CollisionResponse(on_enter=func.on_warp_enter,
                                      on_leave=func.on_warp_exit))
        ce.add_response(
            vars.tags.player, vars.tags.hotspot,
            runners.CollisionResponse(on_enter=func.on_hotspot_enter))
        ce.add_response(vars.tags.player, vars.tags.coin,
                        runners.CollisionResponse(on_enter=func.coin_response))
        ce.add_response(
            vars.tags.player, vars.tags.goomba,
            runners.CollisionResponse(on_enter=func.goomba_response))
        ce.add_response(
            vars.tags.player, vars.tags.koopa,
            runners.CollisionResponse(on_enter=func.koopa_response))
        ce.add_response(
            vars.tags.player, vars.tags.plant,
            runners.CollisionResponse(on_enter=func.plant_response))
        ce.add_response(vars.tags.player, vars.tags.spawn,
                        runners.CollisionResponse(on_enter=func.on_spawn))
        ce.add_response(
            vars.tags.player, vars.tags.key,
            runners.CollisionResponse(on_enter=func.on_collect_item))
        ce.add_response(
            vars.tags.player, vars.tags.generic_hotspot,
            runners.CollisionResponse(on_enter=func.on_enter_hotspot,
                                      on_leave=func.on_leave_hotspot))

        ce.add_response(vars.tags.goomba, vars.tags.player_fire,
                        runners.CollisionResponse(on_enter=func.fire_hits_foe))
        self.add_runner(ce)

        self.add_runner(runners.Scheduler())

        self.dw = runners.DynamicWorld(256, 256, 'maincam')
        self.add_runner(self.dw)

        diag = Entity(tag='diag')
        diag.camera = camera.OrthoCamera(world_width=width,
                                         world_height=height,
                                         cam_width=width,
                                         cam_height=height,
                                         viewport=[0, 0, width, height],
                                         tag='diagcam')
        diag.add(
            Text('main',
                 8,
                 monkey.engine.read('$mario'), [255, 255, 255, 255],
                 TextAlignment.top_left,
                 pos=(24, 248, 2)))
        diag.add(
            Text('main',
                 8,
                 '{:06d}'.format(vars.score), [255, 255, 255, 255],
                 TextAlignment.top_left,
                 tag='score_label',
                 pos=(24, 240, 2)))
        diag.add(
            Text('main',
                 8,
                 monkey.engine.read('$world'), [255, 255, 255, 255],
                 TextAlignment.top_left,
                 pos=(144, 248, 2)))
        diag.add(
            Text('main',
                 8,
                 uid, [255, 255, 255, 255],
                 TextAlignment.top,
                 pos=(164, 240, 2)))
        diag.add(
            Text('main',
                 8,
                 monkey.engine.read('$time'), [255, 255, 255, 255],
                 TextAlignment.top_right,
                 pos=(232, 248, 2)))
        diag.add(
            Text('main',
                 8,
                 str(vars.time), [255, 255, 255, 255],
                 TextAlignment.top_right,
                 tag='score_label',
                 pos=(232, 240, 2)))
        diag.add(Sprite(model='sprites/01/coin_counter', pos=(96, 232, 2)))
        diag.add(Text('main', 8, 'x', [255, 255, 255, 255], pos=(108, 240, 2)))
        diag.add(
            Text('main',
                 8,
                 '{:02d}'.format(vars.coins), [255, 255, 255, 255],
                 TextAlignment.top_left,
                 tag='coin_label',
                 pos=(116, 240, 2)))
        fps_count = Text('main',
                         8,
                         '0', [255, 255, 255, 255],
                         align=TextAlignment.top_left,
                         tag='fps',
                         pos=(0, 256, 2))
        fps_count.add_component(comp.FPSCounter())
        diag.add(fps_count)

        self.add(diag)

        # add player
        mario = monkey.engine.get_item_factory('player')()(start_pos[0],
                                                           start_pos[1], 0)
        #mario = build.makePlayer(vars.stateInfo[vars.state], startPos[0], startPos[1])
        main.add(mario)
Exemple #3
0
    def __init__(self, uid: str, world_bounds):
        super().__init__(uid, 384, 224)
        #width =
        #height = 240
        device_width = monkey.engine.device_size[0]
        device_height = monkey.engine.device_size[1]

        keyl = runners.KeyListener()
        # adding pause button
        #keyl.add_key(key=32, func=func.toggle_pause)
        # restart on F10
        keyl.add_key(key=299, func=func.restart)
        self.add_runner(keyl)

        main = Entity(tag='main')
        cam = camera.Camera25(5216, 736, device_width, device_height,
                              [0, 0, device_width, device_height])
        #cam = camera.PerspectiveCamera(viewport=[0, 0, 320, 240])
        cam.tag = 'maincam'
        cam.pos = (5, 0, 1)
        #cam.bounds = world_bounds
        #cam.boundsz = [-100, 22]
        main.camera = cam

        self.main = main
        self.add(main)

        ce = runners.CollisionEngine3D(80, 80, 80)  # this will be a 3d engine
        ce.add_response(
            vars.tags.player, vars.tags.ladder,
            runners.CollisionResponse(on_enter=func.on_enter_ladder_area,
                                      on_leave=func.on_leave_ladder_area))
        ce.add_response(vars.tags.player, vars.tags.spawn,
                        runners.CollisionResponse(on_enter=func.spawn))

        #ce.add_response(vars.tags.foe_attack, vars.tags.player, runners.CollisionResponse(on_enter=func.foe_hits_player))
        ce.add_response(
            vars.tags.player_attack, vars.tags.foe,
            runners.CollisionResponse(on_enter=func.player_hits_foe))
        ce.add_response(
            vars.tags.foe_attack, vars.tags.player,
            runners.CollisionResponse(on_enter=func.foe_hits_player))
        # ce.add_response(vars.tags.player, vars.tags.foe, runners.CollisionResponse(on_enter=func.stomp_enemy))
        # ce.add_response(vars.tags.player, vars.tags.bonus, runners.CollisionResponse(on_enter=func.collect_bonus))
        # ce.add_response(vars.tags.player_attack, vars.tags.foe, runners.CollisionResponse(on_enter=func.player_hits_foe))
        # ce.add_response(vars.tags.player_attack, vars.tags.platform_destructible, runners.CollisionResponse(on_enter=func.player_hits_block))
        # ce.add_response(vars.tags.gib, vars.tags.platform, runners.CollisionResponse(on_enter=func.gib_lands))
        # ce.add_response(vars.tags.gib, vars.tags.platform_destructible, runners.CollisionResponse(on_enter=func.gib_lands))
        #
        # ce.add_response(vars.tags.fire, vars.tags.foe, runners.CollisionResponse(on_enter=func.fire_hits_foe))
        # ce.add_response(vars.tags.crusher, vars.tags.player, runners.CollisionResponse(on_enter=func.on_crusher_hit))

        self.add_runner(ce)
        self.add_runner(runners.Scheduler())

        diag = Entity(tag='diag')
        fsize = 8
        pad = 3 * fsize
        w = 320
        h = 240
        diag.camera = camera.OrthoCamera(world_width=w,
                                         world_height=h,
                                         cam_width=w,
                                         cam_height=h,
                                         viewport=[0, 0, w, h],
                                         tag='diagcam')
        #diag.add(Text('main', fsize, monkey.engine.read('$energy'), [255, 255, 255, 255], TextAlignment.top_left, pos=(pad, h-fsize, 2)))
        #diag.add(Text('main', fsize, str(vars.energy), [255, 255, 255, 255], TextAlignment.top_left, tag='energy_label', pos=(pad, h-fsize*2, 2)))
        # diag.add(Text('main', fsize, monkey.engine.read('$world'), [255, 255, 255, 255], TextAlignment.top_left, pos=(fsize*10, height-fsize, 2)))
        # diag.add(Text('main', fsize, uid, [255, 255, 255, 255], TextAlignment.top_left, pos=(fsize*10, height-2*fsize, 2)))
        #diag.add(Text('main', fsize, monkey.engine.read('$height'), [255, 255, 255, 255], TextAlignment.top_right, pos=(width-pad, height-fsize, 2)))
        #diag.add(Text('main', fsize, str(vars.height), [255, 255, 255, 255], TextAlignment.top_right, tag='height_label', pos=(width-pad, height-fsize*2, 2)))
        # fps_count = Text('main', fsize, '0', [255, 255, 255, 255], align=TextAlignment.top_left, tag='fps', pos=(0, height, 2))
        # fps_count.add_component(comp.FPSCounter())
        # diag.add(fps_count)

        self.add(diag)
Exemple #4
0
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())

    # setup collision engine
    ce = runners.CollisionEngine(80, 80)
    ce.add_response(
        vars.Collision.Tags.player, vars.Collision.Tags.trap,
        runners.CollisionResponse(on_enter=func.on_enter_trap,
                                  on_leave=func.on_leave_trap))
    r.add_runner(ce)
    print('uisize is ' + str(vars.ui_height))
    device_size = monkey.engine.device_size
    cam_width = device_size[0]
    cam_height = device_size[1] - vars.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,
        vars.main_height, [0, vars.ui_height, cam_width, vars.main_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 = vars.verb_sets[verb_set]
    dv = vars.verbs[vset['default_verb']]
    vars.current_verb = vset['default_verb']
    vars.current_item_1 = ''
    vars.current_item_2 = ''

    ui = entity.Entity(tag='ui')
    ui2 = entity.Entity(tag='ui2')

    ui.camera = cam.OrthoCamera(cam_width,
                                vars.ui_height,
                                cam_width,
                                vars.ui_height,
                                [0, 0, cam_width, vars.ui_height],
                                tag='uicam')
    ui2.camera = cam.OrthoCamera(cam_width,
                                 vars.ui_height,
                                 cam_width,
                                 vars.ui_height,
                                 [0, 0, cam_width, vars.ui_height],
                                 tag='uicam')
    #monkey.engine.read(dv['text']

    ui.add(
        entity.Text(font='ui',
                    size=8,
                    text='mierda',
                    color=vars.Colors.current_action,
                    align=entity.TextAlignment.bottom,
                    tag='current_verb',
                    pos=(cam_width / 2, 48, 0)))
    ui.add_component(compo.HotSpotManager())
    ui2.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.actions, on_load))

    r.add(ui)
    r.add(ui2)
    cy = vars.ui_height - 2 * vars.font_size
    count = 0
    shift = 0
    shift_applied = [0, 40, 100]
    nverbs = 5
    for i in vset['verbs']:
        cx = shift_applied[count // nverbs]  # * shift_applied
        cy = vars.ui_height - (2 + count % nverbs) * vars.font_size
        e = factories.items.make_verb_button(i, (cx, cy, 0))
        shift = max(shift, 1 + len(monkey.engine.read(vars.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())
    r.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 vars.items_in_room:
        for key in vars.items_in_room[id]:
            item_desc = vars.items[key]
            tp = item_desc.get('type', None)
            if tp is None:
                print('item ' + key + ' does not have type!')
                exit(1)
            print('ciao ' + tp)
            factory = getattr(factories.items, tp)
            e = factory()(key, item_desc)
            if e is not None:
                parent = item_desc.get('parent', 'main')
                r.add(e, parent)
    return r