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
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
def trap(key, desc): pos = desc.get('pos') s = Entity(pos=pos) s.tag = key size = desc.get('size') s.add_component( Collider(flag=2, mask=1, tag=2, shape=Rect(size[0], size[1]), debug=True)) return s
def bg(args): e = Entity() asset = copy.deepcopy(monkey.engine.get_asset(args.get('model', None))) e.anim = args.get('anim', None) e.tag = args.get('tag') if 'tile_size' not in asset: asset['tile_size'] = [16, 16] e.model = asset print('THE TAG IS ' + str(e.tag)) e.read_children(args) return e
def walkarea(data): e = Entity() e.tag = 'walkarea_' + str(data.get('id', 0)) walkarea = { 'type': 'components.walkarea', 'depth': data.get('depth', None), 'scale': data.get('scale', None), 'walls': data.get('walls', None) } if 'poly' in data: walkarea['shape'] = { 'type': 'shape.polygon', 'outline': data['poly'], 'holes': data.get('holes') } else: walkarea['shape'] = { 'type': 'shape.polyline', 'nodes': data['nodes'], 'edges': data['edges'] } e.add_component(walkarea) return e
def player2D(ciao): e = Entity() e.model = ciao.get('model', None) tile_size = getattr(monkey.engine.data.globals, 'tile_size', [1, 1]) size = tiles_to_world(ciao.get('size'), tile_size) max_speed = ciao.get('max_speed') time_acc = ciao.get('time_acc') show_boxes = getattr(monkey.engine.data.globals, 'show_boxes', False) jump_height = ciao.get('jump_height') time_to_jump_apex = ciao.get('time_to_jump_apex') gravity = (2.0 * jump_height) / (time_to_jump_apex * time_to_jump_apex) jump_speed = abs(gravity) * time_to_jump_apex e.tag = ciao.get('tag', None) e.components.append({ 'type': 'components.controller2D', 'size': [size[0], size[1], 0], 'offset': [0, size[1] * 0.5, 0], 'mask_up': 2, 'mask_down': 2 | 32, 'debug': show_boxes }) e.components.append({'type': 'components.dynamics'}) e.components.append({'type': 'components.keyinput'}) e.components.append({ 'type': 'components.smart_collider', 'flag': monkey.engine.data.CollisionFlags.player, 'mask': monkey.engine.data.CollisionFlags.foe, 'tag': monkey.engine.data.CollisionTags.player, 'cast_mask': monkey.engine.data.CollisionFlags.foe, 'cast_tag': getattr(monkey.engine.data.CollisionTags, 'player_attack'), 'debug': True }) e.components.append({ 'type': 'components.follow', 'cam': 'maincam', 'relativepos': [0, 0, 5], 'up': [0, 1, 0] }) e.components.append({ 'type': 'components.state_machine', 'initial_state': 'jump', 'states': [{ 'id': 'jump', 'type': 'state.player_jump', 'max_speed': max_speed, 'time_acc': time_acc, 'gravity': gravity, 'walk_state': 'walk', }, { 'id': 'walk', 'type': 'state.player_walk', 'max_speed': max_speed, 'time_acc': time_acc, 'gravity': gravity, 'jump_state': 'jump', 'jump_speed': jump_speed }] }) return e