def main(cont): own = cont.getOwner() sens = cont.getSensor('type_hit') if sens.isPositive(): for ob in sens.getHitObjectList(): if ob.type == 'ram': actu = cont.getActuator('ramDetect') GameLogic.addActiveActuator(actu, True)
def main(cont): own = cont.getOwner() for ob in own.getChildren(): if hasattr(ob, 'carried'): pos = ob.getPosition() ob.carried= 0 ob.removeParent() play_cart_act= cont.getActuators()[0] GameLogic.addActiveActuator(play_cart_act, True)
def main(cont): own = cont.getOwner() carry_sens = cont.getSensor('carry_touch') carry_done = False if carry_sens.isPositive(): for ob in carry_sens.getHitObjectList(): if hasattr(ob, 'carried') and ob.carried == 0: ob.carried = 1 ob.setParent(own) carry_done = True if carry_done: play_carry_act = cont.getActuators()[0] GameLogic.addActiveActuator(play_carry_act, True)
phi_z_Body_Point = M.pi - M.asin(Orientation_Body_Point[0][1]) elif Orientation_Body_Point[0][0] >= 0.0 and Orientation_Body_Point[0][1] <= 0.0: phi_z_Body_Point = 2*M.pi + M.asin(Orientation_Body_Point[0][1]) else: phi_z_Body_Point = 0.0 # -> get phi_z_Body <- if Orientation_Body[0][0] >= 0.0 and Orientation_Body[0][1] >= 0.0: phi_z_Body = M.asin(Orientation_Body[0][1]) elif Orientation_Body[0][0] <= 0.0 and Orientation_Body[0][1] >= 0.0: phi_z_Body = M.pi - M.asin(Orientation_Body[0][1]) elif Orientation_Body[0][0] <= 0.0 and Orientation_Body[0][1] <= 0.0: phi_z_Body = M.pi - M.asin(Orientation_Body[0][1]) elif Orientation_Body[0][0] >= 0.0 and Orientation_Body[0][1] <= 0.0: phi_z_Body = 2*M.pi + M.asin(Orientation_Body[0][1]) else: phi_z_Body = 0.0 # -> calculate corrections <- Correction_phi_x = 0.0 Correction_phi_y = 0.0 Correction_phi_z = - (phi_z_Body - phi_z_Body_Point) * 0.1 if Correction_phi_z > 0.01: Correction_phi_z = 0.0 # -> correct drift <- Rotation_Speed_Body = GL.Globals['Motion_Actuator_Body'].getDRot() GL.Globals['Motion_Actuator_Body'].setDRot(Rotation_Speed_Body[0] + Correction_phi_x,Rotation_Speed_Body[1] + Correction_phi_y,Rotation_Speed_Body[2] + Correction_phi_z,Rotation_Speed_Body[3]) GL.addActiveActuator(GL.Globals['Motion_Actuator_Body'],1)
if GL.Globals['phi_y'] == GL.Globals['Upper_Limit_phi_y']: GL.Globals['phi_y_p'] = min(GL.Globals['phi_y_p'], 0) elif GL.Globals['phi_y'] == GL.Globals['Lower_Limit_phi_y']: GL.Globals['phi_y_p'] = max(GL.Globals['phi_y_p'], 0) # Set speed and rotation for the body GL.Globals['Motion_Actuator_Body_Point'].setDLoc( Blender_Factor * GL.Globals['x_p'], Blender_Factor * GL.Globals['y_p'], Blender_Factor * GL.Globals['z_p'], 1) GL.Globals['Motion_Actuator_Body_Point'].setDRot( 0, 0, -Blender_Factor * GL.Globals['phi_z_p'], 0) GL.Globals['Motion_Actuator_Body'].setDRot( -Blender_Factor * GL.Globals['phi_x_p'], -Blender_Factor * GL.Globals['phi_y_p'], 0, 1) GL.addActiveActuator(GL.Globals['Motion_Actuator_Body_Point'], 1) GL.addActiveActuator(GL.Globals['Motion_Actuator_Body'], 1) # Set rotation for the wheels GL.Globals['Rotation_Actuator_Wheel_1'].setDRot( 0, -Blender_Factor * GL.Globals['omega_1'], 0, 1) GL.addActiveActuator(GL.Globals['Rotation_Actuator_Wheel_1'], 1) GL.Globals['Rotation_Actuator_Wheel_2'].setDRot( 0, -Blender_Factor * GL.Globals['omega_2'], 0, 1) GL.addActiveActuator(GL.Globals['Rotation_Actuator_Wheel_2'], 1) GL.Globals['Rotation_Actuator_Wheel_3'].setDRot( 0, -Blender_Factor * GL.Globals['omega_3'], 0, 1) GL.addActiveActuator(GL.Globals['Rotation_Actuator_Wheel_3'], 1) GL.Globals['Rotation_Actuator_Wheel_4'].setDRot( 0, -Blender_Factor * GL.Globals['omega_4'], 0, 1) GL.addActiveActuator(GL.Globals['Rotation_Actuator_Wheel_4'], 1)
GL.Globals["phi_x_p"] = max(GL.Globals["phi_x_p"], 0) if GL.Globals["phi_y"] == GL.Globals["Upper_Limit_phi_y"]: GL.Globals["phi_y_p"] = min(GL.Globals["phi_y_p"], 0) elif GL.Globals["phi_y"] == GL.Globals["Lower_Limit_phi_y"]: GL.Globals["phi_y_p"] = max(GL.Globals["phi_y_p"], 0) # Set speed and rotation for the body GL.Globals["Motion_Actuator_Body_Point"].setDLoc( Blender_Factor * GL.Globals["x_p"], Blender_Factor * GL.Globals["y_p"], Blender_Factor * GL.Globals["z_p"], 1 ) GL.Globals["Motion_Actuator_Body_Point"].setDRot(0, 0, -Blender_Factor * GL.Globals["phi_z_p"], 0) GL.Globals["Motion_Actuator_Body"].setDRot( -Blender_Factor * GL.Globals["phi_x_p"], -Blender_Factor * GL.Globals["phi_y_p"], 0, 1 ) GL.addActiveActuator(GL.Globals["Motion_Actuator_Body_Point"], 1) GL.addActiveActuator(GL.Globals["Motion_Actuator_Body"], 1) # Set rotation for the wheels GL.Globals["Rotation_Actuator_Wheel_1"].setDRot(0, -Blender_Factor * GL.Globals["omega_1"], 0, 1) GL.addActiveActuator(GL.Globals["Rotation_Actuator_Wheel_1"], 1) GL.Globals["Rotation_Actuator_Wheel_2"].setDRot(0, -Blender_Factor * GL.Globals["omega_2"], 0, 1) GL.addActiveActuator(GL.Globals["Rotation_Actuator_Wheel_2"], 1) GL.Globals["Rotation_Actuator_Wheel_3"].setDRot(0, -Blender_Factor * GL.Globals["omega_3"], 0, 1) GL.addActiveActuator(GL.Globals["Rotation_Actuator_Wheel_3"], 1) GL.Globals["Rotation_Actuator_Wheel_4"].setDRot(0, -Blender_Factor * GL.Globals["omega_4"], 0, 1) GL.addActiveActuator(GL.Globals["Rotation_Actuator_Wheel_4"], 1) # Get inputs Cont = GL.getCurrentController() Left = Cont.getSensor("Left")
else: phi_z_Body_Point = 0.0 # -> get phi_z_Body <- if Orientation_Body[0][0] >= 0.0 and Orientation_Body[0][1] >= 0.0: phi_z_Body = M.asin(Orientation_Body[0][1]) elif Orientation_Body[0][0] <= 0.0 and Orientation_Body[0][1] >= 0.0: phi_z_Body = M.pi - M.asin(Orientation_Body[0][1]) elif Orientation_Body[0][0] <= 0.0 and Orientation_Body[0][1] <= 0.0: phi_z_Body = M.pi - M.asin(Orientation_Body[0][1]) elif Orientation_Body[0][0] >= 0.0 and Orientation_Body[0][1] <= 0.0: phi_z_Body = 2 * M.pi + M.asin(Orientation_Body[0][1]) else: phi_z_Body = 0.0 # -> calculate corrections <- Correction_phi_x = 0.0 Correction_phi_y = 0.0 Correction_phi_z = -(phi_z_Body - phi_z_Body_Point) * 0.1 if Correction_phi_z > 0.01: Correction_phi_z = 0.0 # -> correct drift <- Rotation_Speed_Body = GL.Globals['Motion_Actuator_Body'].getDRot() GL.Globals['Motion_Actuator_Body'].setDRot( Rotation_Speed_Body[0] + Correction_phi_x, Rotation_Speed_Body[1] + Correction_phi_y, Rotation_Speed_Body[2] + Correction_phi_z, Rotation_Speed_Body[3]) GL.addActiveActuator(GL.Globals['Motion_Actuator_Body'], 1)
(".Lo", -40.0, -100.0) ) co = GameLogic.getCurrentController() obj = co.owner act = co.actuators["LOD." + obj.name] cam = GameLogic.getCurrentScene().active_camera def Depth(pos, plane): return pos[0]*plane[0] + pos[1]*plane[1] + pos[2]*plane[2] + plane[3] # Depth is negative and decreasing further from the camera depth = Depth(obj.position, cam.world_to_camera[2]) newmesh = None curmesh = None # Find the lowest detail mesh for depth for mesh in meshes: if depth < mesh[1] and depth > mesh[2]: newmesh = mesh if "ME" + obj.name + mesh[0] == act.getMesh(): curmesh = mesh if newmesh != None and "ME" + obj.name + newmesh[0] != act.getMesh(): # The mesh is a different mesh - switch it. # Check the current mesh is not a better fit. if curmesh == None or curmesh[1] < depth or curmesh[2] > depth: act.mesh = obj.getName() + newmesh[0] GameLogic.addActiveActuator(act, True)
def main(cont): # own.sheep_ids needs to start as an empty string own = cont.getOwner() sens = cont.getSensor('type_hit') if sens.isPositive(): count = 0 for ob in sens.getHitObjectList(): if hasattr(ob, 'type') and ob.type == 'shp': count += 1 if count >= own.sheep_count: # Sheep ground sensor act = cont.getActuator('sheep_caught') # bigStick acti = cont.getActuator('sheep_caughti') # Catapult branch actii = cont.getActuator('sheep_caughtii') # piersheep actiii = cont.getActuator('sheep_caughtiii') # pier littleStick activ = cont.getActuator('sheep_caughtiv') # catapult_rock_door actv = cont.getActuator('sheep_caughtv') # catapult_throw actvi = cont.getActuator('sheep_caughtvi') # rock actvii = cont.getActuator('sheep_caughtvii') GameLogic.addActiveActuator(act, True) GameLogic.addActiveActuator(acti, True) GameLogic.addActiveActuator(actii, True) GameLogic.addActiveActuator(actiii, True) GameLogic.addActiveActuator(activ, True) GameLogic.addActiveActuator(actv, True) GameLogic.addActiveActuator(actvi, True) GameLogic.addActiveActuator(actvii, True)