def f(*args): # the first argument is the callback function # the second, if present, is the model model = kwargs.get('model', None) callback = kwargs.get('func') info = kwargs.get('info', None) pos = makePos2(*args) if model is None: a = entity.Entity(pos=pos) size = [args[2] * vars.tile_size, args[3] * vars.tile_size, 0] a.add_component( comp.Collider(debug=True, flag=vars.flags.foe, mask=vars.flags.player, tag=vars.tags.key, shape=sh3d.AABB(size=size))) a.add_component( comp.Info(func=callback, info=info, args=args, bounds=[0, 0, size[0], size[1]])) else: a = entity.Sprite(model=model, pos=pos) a.add_component( comp.SmartCollider(debug=True, flag=vars.flags.foe, mask=vars.flags.player, tag=vars.tags.key)) a.add_component(comp.Info(func=callback, info=info, args=args)) return a
def f(*args): ym = kwargs.get('y_min') y0 = kwargs.get('y_min_goto') wa: WalkAreaInfo = vars.walk_areas[y0[0]] ymg = wa.transform(y0[1:]) print('y m goto = ' + str(ymg)) yM = kwargs.get('y_max') y1 = kwargs.get('y_max_goto') wa: WalkAreaInfo = vars.walk_areas[y1[0]] yMg = wa.transform(y1[1:]) print('y M goto = ' + str(yMg)) x0 = args[0] depth_y = args[2] * math.sqrt(2.0) y0 = args[1] - args[2] z0 = -depth_y pos = (x0, y0, z0) e = entity.Entity(pos=pos) e.add_component( comp.Collider(debug=True, shape=sh3d.AABB(size=(args[3], args[4], args[5])), flag=vars.flags.foe, mask=vars.flags.player, tag=vars.tags.ladder)) e.add_component( comp.Info(x=522, y_min=ym, y_max=yM, y_min_goto=ymg, y_max_goto=yMg)) return e
def f(*args): pos = makePos(*args) # coords of the top left tile. if (x, y) is the top left # then (x+1, y) is the top right, and (x, y+1) and (x+1, y+1) # the left and right walls of the pipe. sheet = vars.tile_data['tile_sheets']['main'] tl = kwargs.get('top_left') height = args[3] data = [tl[0], tl[1] + 1, tl[0] + 1, tl[1] + 1] * (height - 1) data.extend([tl[0], tl[1], tl[0] + 1, tl[1]]) e = entity.Entity(pos=pos) e.add_component( comp.TiledGfx(tile_sheet=sheet['file'], sheet_size=sheet['sheet_size'], tile_data=data, width=2, height=height, size=vars.tile_size)) shape = sh.Rect(width=2 * vars.tile_size, height=height * vars.tile_size) e.add_component( comp.Collider(flag=vars.flags.platform, mask=1, tag=1, shape=shape)) foe = kwargs.get('foe', None) exit = kwargs.get('exit', None) if foe: foe_tag = monkey.engine.get_next_tag() pct = 1 if exit: if exit not in vars.disable_update_on_start: vars.disable_update_on_start[exit] = [] vars.disable_update_on_start[exit].append(foe_tag) pct = 0.5 p = plant(model=foe, pct=pct)(1, height, -0.1) p.tag = foe_tag plant_id = e.add(p) sensor = entity.Entity(pos=(vars.tile_size, height * vars.tile_size)) size = (8.0, 0.4, 0.0) sensor.add_component( comp.Collider(debug=True, flag=vars.flags.foe, mask=vars.flags.player, tag=vars.tags.generic_hotspot, shape=sh3d.AABB(size=size, offset=(-size[0] * 0.5, 0.0, 0.0)))) sensor.add_component( comp.Info(on_enter=freeze_plant(p.tag, False), on_leave=freeze_plant(p.tag, True))) e.add(sensor) warp_info = kwargs.get('warp', None) if warp_info: w = warp()(1, height, 0, warp_info[0], warp_info[1]) e.add(w) return e
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(on_enter=desc.get('on_enter', None), on_leave=desc.get('on_leave', None))) return s
def f(*args): pos = makePos(*args) pin = entity.Entity(pos=pos, tag=kwargs.get('tag', None)) pin.add_component( comp.Collider(debug=True, flag=vars.flags.foe, mask=vars.flags.player, tag=vars.tags.warp, shape=sh3d.AABB(size=(4, 2, 0), offset=(-2, 0, 0)))) pin.add_component( comp.Info(world=args[3], start=args[4], bounds=[0, 0, 4, 2])) return pin
def f(*args): x0 = args[0] depth_y = args[2] * math.sqrt(2.0) y0 = args[1] - args[2] z0 = -depth_y pos = (x0, y0, z0) e = entity.Entity(pos=pos) e.add_component( comp.Collider(debug=True, shape=sh3d.AABB(size=(args[3], args[4], args[5] * sqrt2)), flag=vars.flags.foe, mask=vars.flags.player, tag=vars.tags.spawn)) e.add_component(comp.Info(enemies=args[6])) return e
def f(*args): pos = makePos(*args) w = args[3] h = args[4] a = entity.Entity(pos=pos) img = kwargs.get('image', None) if img: a.add_component(comp.Gfx(image=img, repeat=[w, h])) a.add_component( comp.Info(bounds=[0, 0, w * vars.tile_size, h * vars.tile_size])) a.add_component( comp.Collider(flag=vars.flags.platform, mask=vars.flags.player, tag=1, shape=sh.Rect(width=w * vars.tile_size, height=h * vars.tile_size))) return a
def f(*args): x = args[0] * vars.tile_size y = args[1] * vars.tile_size ax = args[2] * vars.tile_size ay = args[3] * vars.tile_size bx = args[4] * vars.tile_size by = args[5] * vars.tile_size minx = min(ax, bx) maxx = max(ax, bx) miny = min(ay, by) maxy = max(ay, by) a = entity.Entity() a.add_component( comp.Collider(flag=vars.flags.platform, mask=vars.flags.player, tag=1, shape=sh.Line(a=[ax, ay, 0], b=[bx, by, 0]))) a.add_component(comp.Info(bounds=[minx, miny, maxx, maxy])) a.pos = (x, y, 0) return a
def _brick(x, y, model, hits, callback): pos = makePos2(x, y) a = entity.Sprite(model=model, pos=pos) a.add_component( comp.Collider(flag=vars.flags.platform, mask=0, tag=0, shape=sh.Rect(width=vars.tile_size, height=vars.tile_size))) a.add_component(comp.Info(hitsLeft=hits, callback=callback)) b = entity.Entity() b.pos = (2, -0.5, 0) b.add_component( comp.Collider(flag=vars.flags.foe, mask=vars.flags.player, tag=vars.tags.bonus_brick_sensor, debug=True, shape=sh3d.AABB(size=(vars.tile_size - 4, 1, 0)) #shape=sh.Rect(width=vars.tile_size - 4, height=1.0) )) a.add(b) return a
def f(*args): model = kwargs.get('model') piece = kwargs.get('piece') pos = makePos2(*args) a = entity.Sprite(model=model, pos=pos) a.add_component( comp.Collider(flag=vars.flags.platform, mask=0, tag=0, shape=sh.Rect(width=vars.tile_size, height=vars.tile_size))) a.add_component(comp.Info(piece=piece)) b = entity.Entity() b.pos = (2, -0.5, 0) b.add_component( comp.Collider(flag=vars.flags.foe, mask=vars.flags.player, tag=vars.tags.brick_sensor, shape=sh3d.AABB(size=(vars.tile_size - 4, 1, 1)) #shape=sh.Rect(width=vars.tile_size-4, height=1.0) )) a.add(b) return a
def foe(pos, info): model = info.get('model') scale = info.get('scale', 1.0) speed = info.get('speed', 50) energy = info.get('energy', 2) p = entity.Sprite(model=model, pos=pos) # shadow = entity.Entity() # shadow.add_component(comp.ShadowRenderer(angle=20.0)) # p.add(shadow) p.layer = 1 p.scale = scale p.add_component( comp.Controller3D(mask_up=vars.flags.platform, mask_down=vars.flags.platform | vars.flags.platform_passthrough, size=[1, 1, 1], shift=[0, 0.5], max_climb_angle=80, max_descend_angle=80, debug=True)) p.add_component(comp.Dynamics2D(gravity=vars.gravity)) p.add_component( comp.SmartCollider(flag=vars.flags.foe, mask=vars.flags.player_attack, tag=vars.tags.foe, cast_tag=vars.tags.foe_attack, cast_mask=vars.flags.player, debug=True)) p.add_component(comp.Info(energy=energy)) sm = comp.StateMachine(initial_state='walk') attacks = [{'state': 'attack0', 'prob': 0, 'in_range': True}] sm.states.append(states.Attack(uid='attack0', anim='punch')) # for i in range(0, n_attacks): # attack_id = 'attack' + str(i+1) # attack_list.append({'state': attack_id, 'prob': patt[i], 'in_range': True}) # sm.states.append(states.Attack(uid=attack_id, anim=attack_id)) # hp_map[attack_id] = hp[i] sm.states.append( pstates.FoeChase3D(uid='walk', walk_anim='walk', idle_anim='idle', speed=speed, acceleration=0.05, attacks=attacks, prob_attack=0)) # prob_attack=prob_attack)) sm.states.append( pstates.IsHit(uid='hit', anim='hit', acceleration=10, dist=4)) v0y = math.sqrt(2 * abs(vars.gravity) * 32) v0x = 64 * abs(vars.gravity) / v0y sm.states.append( pstates.Fly(uid='dead', anim_up='dead_up', anim_down='dead_down', anim_lie='dead_lie', v0=(v0x, v0y))) # sm.states.append(states.SimpleState(uid='dead', anim='hit')) p.add_component(sm) return p