def unit_from_dict(unit_dict): if unit_dict["ClassName"] == "Key": new_unit = unit.Key(number=unit_dict["number"], obj_id=unit_dict["obj_id"], load_from=unit_dict) else: try: new_unit = getattr(unit, unit_dict["ClassName"])(load_from=unit_dict) except: print "Did not load", unit_dict["ClassName"] return None env.bind_keys(unit_dict["key_bindings"], new_unit) return new_unit
def init_player(x, y, angle, config='normal'): global player if config == 'enhanced_1' or config == 'enhanced_3': ot = (10, 48) rt = 15 elif config == 'enhanced_2': ot = (10, 48) rt = 45 else: ot = (15, 45) rt = 0 thruster_left_bottom = unit.Thruster(None, (-32,33), -rt, obj_id=-5) thruster_right_bottom = unit.Thruster(None, (-32,-33), rt, obj_id=-4) thruster_left_top = unit.Thruster(None, (ot[0], ot[1]), 180, obj_id=-3) thruster_right_top = unit.Thruster(None, (ot[0], -ot[1]), 180, obj_id=-2) if config == 'enhanced_3': brain = unit.Brain2(None, (0,0), 90, obj_id=-1) else: brain = unit.Brain(None, (0,0), 90, obj_id=-1) new_shapes = [brain, thruster_left_bottom, thruster_right_bottom, thruster_left_top, thruster_right_top] if config == 'enhanced_1' or config == 'enhanced_3': repair = unit.Repair(None, (40, 0), 0, obj_id=-6) gun_left = unit.NormalTurretA(None, (55, 30), 10, obj_id=-7) gun_right = unit.NormalTurretA(None, (55, -30), -10, obj_id=-8) new_shapes.extend([repair, gun_left, gun_right]) env.bind_keys([key.SPACE], gun_left) env.bind_keys([key.SPACE], gun_right) if config == 'enhanced_2': repair = unit.Repair(None, (40, 0), 0, obj_id=-6) gun_left = unit.NormalTurretA(None, (55, 30), 10, obj_id=-7) gun_right = unit.NormalTurretA(None, (55, -30), -10, obj_id=-8) thruster_left_out = unit.Thruster(None, (-27,81), -20, obj_id=-9) thruster_right_out = unit.Thruster(None, (-27,-81), 20, obj_id=-10) new_shapes.extend([repair, thruster_right_out, thruster_left_out, gun_left, gun_right]) env.bind_keys([key.SPACE], gun_left) env.bind_keys([key.SPACE], gun_right) env.bind_keys([key.RIGHT, key.UP], thruster_left_out) env.bind_keys([key.LEFT, key.UP], thruster_right_out) env.bind_keys([key.RIGHT, key.UP], thruster_left_bottom) env.bind_keys([key.LEFT, key.UP], thruster_right_bottom) env.bind_keys([key.LEFT, key.DOWN], thruster_left_top) env.bind_keys([key.RIGHT, key.DOWN], thruster_right_top) player = body.GlueBody((x, y), angle, new_shapes)