本文整理汇总了Python中GameLogic.getCurrentController方法的典型用法代码示例。如果您正苦于以下问题:Python GameLogic.getCurrentController方法的具体用法?Python GameLogic.getCurrentController怎么用?Python GameLogic.getCurrentController使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameLogic
的用法示例。
在下文中一共展示了GameLogic.getCurrentController方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def main():
if GameLogic.Object['closed']:
return
# get controller
controller = GameLogic.getCurrentController()
gu.keep_conn([conn1, conn2])
obj = controller.owner
pos = obj.localPosition
ori = obj.localOrientation
try:
arduino = serial.Serial('/dev/arduino_ethernet', 9600)
if x1_in <= pos[0] <= x_out and y_in <= pos[1] <= y_out:
arduino.write(b'A')
elif -x1_in >= pos[0] >= -x_out and -y_in >= pos[1] >= -y_out:
arduino.write(b'B')
else:
arduino.write(b'L')
except:
print("No reward")
if conn1 is not None:
# get mouse movement
t1, dt1, x1, y1 = gu.read32(conn1)
t2, dt2, x2, y2 = gu.read32(conn2)
else:
t1, dt1, x1, y1 = np.array([0,]), np.array([0,]), np.array([0,]), np.array([0,])
t2, dt2, x2, y2 = np.array([0,]), np.array([0,]), np.array([0,]), np.array([0,])
# move according to ball readout:
movement(controller, (x1, y1, x2, y2, t1, t2, dt1, dt2))
示例2: quit
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def quit():
""" Cleanly quit the simulation
"""
contr = GameLogic.getCurrentController()
main_close(contr)
main_terminate(contr)
示例3: default_action
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def default_action(self):
""" Change the 'Severity' property of a nearby victim
When the victim is fully healed, set its status as not Injured
"""
contr = GameLogic.getCurrentController()
radar = contr.sensors["Radar"]
if self.local_data["heal"]:
if radar.triggered and radar.positive:
victim = radar.hitObject
# Restore the health to the victim
if victim["Severity"] > 0:
victim["Severity"] = victim["Severity"] - 1
# Set the colors depending on the severity of the injuries
red = 1 - victim["Severity"] * 0.05
green = 0.5 + red
victim.color = [red, green, 0.5, 1.0]
# Change the status
if victim["Severity"] == 0:
victim["Injured"] = False
# Reset the healing flag
self.local_data["heal"] = 0
示例4: default_action
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def default_action(self):
""" Look for nearby victims, and heal when instructed to """
# Look for victims in the cone of the sensor
contr = GameLogic.getCurrentController()
radar = contr.sensors['Radar']
if radar.triggered and radar.positive:
for victim_obj in radar.hitObjectList:
victim_position = victim_obj.worldPosition
# Fill the data structure for the victim
victim_coordinate = OrderedDict([
('x', victim_position[0]),
('y', victim_position[1]),
('z', victim_position[2]) ])
victim_data = OrderedDict([
('coordinate', victim_coordinate),
('requirements', victim_obj['Requirements']),
('severity', victim_obj['Severity']) ])
self.local_data['victim_dict'][victim_obj.name] = victim_data
# Find the closest victim and its distance
new_distance = self.blender_obj.getDistanceTo(victim_obj)
if new_distance < self._nearest_distance:
self._nearest_victim = victim_obj
self._nearest_distance = new_distance
# When instructed to do so, help a victim
if self._healing:
self._heal_victim()
if radar.triggered and not radar.positive:
# Clear the variables for the victims
self.local_data['victim_dict'] = {}
self._nearest_victim = None
self._nearest_distance = 999999
示例5: default_action
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def default_action(self):
""" Look for nearby victims, and heal when instructed to """
# Look for victims in the cone of the sensor
contr = GameLogic.getCurrentController()
radar = contr.sensors['Radar']
if radar.triggered and radar.positive:
for victim_obj in radar.hitObjectList:
victim_position = victim_obj.worldPosition
self.local_data['victim_dict'][victim_obj.name] = [victim_position[0], victim_position[1], victim_position[2]]
# Find the closest victim and its distance
new_distance = self.blender_obj.getDistanceTo(victim_obj)
if new_distance < self._nearest_distance:
self._nearest_victim = victim_obj
self._nearest_distance = new_distance
# When instructed to do so, help a victim
if self._healing:
self._heal_victim()
if radar.triggered and not radar.positive:
# Clear the variables for the victims
self.local_data['victim_dict'] = {}
self._nearest_victim = None
self._nearest_distance = 999999
示例6: main
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def main():
if GameLogic.Object['closed']:
return
# get controller
controller = GameLogic.getCurrentController()
nmouse = 1
mkey = 'm%dconn' % (nmouse)
if mkey in GameLogic.Object.keys():
t1, dt1, x1, y1 = gu.read32(GameLogic.Object[mkey])
gu.keep_conn([GameLogic.Object[mkey]])
else:
t1, dt1, x1, y1 = 0, 0, np.array([0,]), np.array([0,])
nmouse = 2
mkey = 'm%dconn' % (nmouse)
if mkey in GameLogic.Object.keys():
t2, dt2, x2, y2 = gu.read32(GameLogic.Object[mkey])
gu.keep_conn([GameLogic.Object[mkey]])
else:
t2, dt2, x2, y2 = 0, 0, np.array([0,]), np.array([0,])
# move according to ball readout:
movement(controller, (x1, y1, x2, y2, t1, t2, dt1, dt2))
示例7: main
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def main():
# Get owner
controller = GameLogic.getCurrentController()
owner = controller.owner
Host = 'localhost'
ServerPort = 10000
# Set socket server only one time at the first frame
if not owner['OneTime']:
# Set UDP socket
GameLogic.sServer = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Bind the socket to host
GameLogic.sServer.bind((Host, ServerPort))
# If no data are found, pass
GameLogic.sServer.setblocking(0)
# Set prop to pass test
owner['OneTime'] = True
# Get Position and Orientation
PosCar = owner.worldPosition
OriCar = owner.worldOrientation
# New in python 3
stupid = (PosCar[0], PosCar[1], PosCar[2], OriCar[0][0], OriCar[0][1], OriCar[0][2], OriCar[1][0], OriCar[1][1], OriCar[1][2], OriCar[2][0], OriCar[2][1], OriCar[2][2])
print(stupid)
# Serialize data
Data = pickle.dumps(stupid)
# Send Data to client
GameLogic.sServer.sendto(Data, (Host, 10001))
示例8: onMouse
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def onMouse():
Rasterizer.showMouse(True)
cont = GameLogic.getCurrentController()
mouse = cont.sensors["Mouse"]
over = cont.sensors["Over"]
if mouse.positive:
hit = over.hitObject
if hit is None:
return
print(hit.name)
print(hit.children)
if hit.name in buildings:
deselectAll()
hit.children["Base01.Selected"].setVisible(True)
infoPanelShow(hit)
addUnit()
else:
if hit.name in units:
deselectAll()
hit.children["Unit0.Selected"].setVisible(True)
cont.owner["selected"] = hit["id"]
infoPanelShow(hit)
else:
for target in scene.objects:
if "Target" in target.name and target["id"] == cont.owner["selected"]:
target.localPosition = over.hitPosition
示例9: init
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def init(contr):
""" General initialization of MORSE
Here, all components, modifiers and middleware are initialized.
"""
init_logging()
if MULTINODE_SUPPORT:
# Configuration for the multi-node simulation
try:
node_name = scene_config.node_config["node_name"]
server_address = scene_config.node_config["server_address"]
server_port = scene_config.node_config["server_port"]
except (NameError, AttributeError) as detail:
logger.warning("No node configuration found. Using default values for this simulation node.\n\tException: ", detail)
node_name = "temp_name"
server_address = "localhost"
server_port = 65000
GameLogic.node_instance = morse.core.multinode.SimulationNodeClass(node_name, server_address, server_port)
logger.log(SECTION, 'PRE-INITIALIZATION')
# Get the version of Python used
# This is used to determine also the version of Blender
GameLogic.pythonVersion = sys.version_info
GameLogic.blenderVersion = bpy.app.version
logger.info ("Python Version: %s.%s.%s" % GameLogic.pythonVersion[:3])
logger.info ("Blender Version: %s.%s.%s" % GameLogic.blenderVersion)
GameLogic.morse_initialised = False
GameLogic.base_clock = time.clock()
GameLogic.current_time = 0.0
# Variable to keep trac of the camera being used
GameLogic.current_camera_index = 0
init_ok = True
logger.log(SECTION, 'SUPERVISION SERVICES INITIALIZATION')
init_ok = init_supervision_services()
logger.log(SECTION, 'SCENE INITIALIZATION')
init_ok = init_ok and create_dictionaries()
init_ok = init_ok and add_modifiers()
init_ok = init_ok and link_middlewares()
init_ok = init_ok and link_services()
init_ok = init_ok and load_overlays()
if init_ok:
logger.log(ENDSECTION, 'SCENE INITIALIZED')
check_dictionaries()
GameLogic.morse_initialised = True
else:
logger.critical('INITIALIZATION FAILED!')
logger.info("Exiting now.")
contr = GameLogic.getCurrentController()
close_all(contr)
quit(contr)
示例10: reset_objects
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def reset_objects():
""" Restore all simulation objects to their original position
Upon receiving the request using sockets, call the
'reset_objects' function located in morse/blender/main.py
"""
contr = GameLogic.getCurrentController()
main_reset(contr)
return "Objects restored to initial position"
示例11: switchScene
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def switchScene():
G.loc = "1"
if G.menuState == "car":
G.UIScene.active_camera = G.UIScene.objects["OBCameraCar"]
elif G.menuState == "loc":
G.UIScene.active_camera = G.UIScene.objects["OBCameraLoc"]
else:
cont = G.getCurrentController()
cont.actuators["load"].fileName = G.loc+".blend"
cont.activate("load")
示例12: main
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def main():
# Set init
ip = '127.0.0.1' ### escucha a routerOSC.pd
port = 8888
data = 0
# Get controller and owner
controller = GameLogic.getCurrentController()
owner = controller.owner
# Connect Blender only one time
if not owner['connected']:
owner['connected'] = True
print ("Blender Connected Ori")
GameLogic.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
GameLogic.socket.bind((ip, port))
GameLogic.socket.setblocking(0)
GameLogic.socket.settimeout(0.02)
# If Blender connected, get osc
else:
# Get hand wii osc from pd
data = receive_osc(data, port)
if data != 0:
d = OSC.decodeOSC(data)
print(d)
'''if d[2][8] == "/ori":
ori,ox,oz =d[2][9], d[2][10], d[2][11]
scn = bge.logic.getCurrentScene()
player = scn.objects["player"]
player['ori'] = ori
if d[2][12] == "/norte":
nx,ny =d[2][13],d[2][14]
scn = bge.logic.getCurrentScene()
player = scn.objects["player"]
player['tracker_n'] = nx,ny
# solo si hay 2 kinects!!!!!!
if d[2][15] == "/sur":
sx,sy =d[2][16],d[2][17]
scn = bge.logic.getCurrentScene()
player = scn.objects["player"]
player['tracker_s'] = sx,sy '''
if d[0] == "/norte":
nx,ny =d[2],d[3]
print(nx,ny)
scn = bge.logic.getCurrentScene()
player = scn.objects["player"]
player['tracker_n'] = nx,ny
示例13: addCredit
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def addCredit():
## setup aliases
cont = G.getCurrentController()
add = cont.actuators["add"]
own = cont.owner
## add a sequence of objects, then repeat
add.object = str(own["counter"])
cont.activate(add)
own["counter"] += 1
if own["counter"] > 10:
own["counter"] = 0
示例14: init
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def init(contr):
""" General initialization of MORSE
Here, all components, modifiers and middleware are initialized.
"""
init_logging()
logger.log(SECTION, "PRE-INITIALIZATION")
# Get the version of Python used
# This is used to determine also the version of Blender
GameLogic.pythonVersion = sys.version_info
GameLogic.blenderVersion = bpy.app.version
logger.info("Python Version: %s.%s.%s" % GameLogic.pythonVersion[:3])
logger.info("Blender Version: %s.%s.%s" % GameLogic.blenderVersion)
GameLogic.morse_initialised = False
GameLogic.base_clock = time.clock()
GameLogic.current_time = 0.0
# Variable to keep trac of the camera being used
GameLogic.current_camera_index = 0
init_ok = True
logger.log(SECTION, "SUPERVISION SERVICES INITIALIZATION")
init_ok = init_supervision_services()
logger.log(SECTION, "SCENE INITIALIZATION")
init_ok = init_ok and create_dictionaries()
init_ok = init_ok and link_services()
init_ok = init_ok and add_modifiers()
init_ok = init_ok and link_middlewares()
init_ok = init_ok and load_overlays()
if init_ok:
logger.log(ENDSECTION, "SCENE INITIALIZED")
check_dictionaries()
GameLogic.morse_initialised = True
else:
logger.critical("INITIALIZATION FAILED!")
logger.info("Exiting now.")
contr = GameLogic.getCurrentController()
close_all(contr)
quit(contr)
if MULTINODE_SUPPORT:
init_multinode()
示例15: main
# 需要导入模块: import GameLogic [as 别名]
# 或者: from GameLogic import getCurrentController [as 别名]
def main():
if GameLogic.Object['closed']:
return
else:
gu.keep_conn([conn1, conn2])
controller = GameLogic.getCurrentController()
obj = controller.owner
ori = obj.localOrientation
pos = obj.localPosition
if conn1 is not None:
t1, dt1, x1, y1 = gu.read32(conn1)
t2, dt2, x2, y2 = gu.read32(conn2)
else:
t1, dt1, x1, y1 = np.array([0,]), np.array([0,]), np.array([0,]), np.array([0,])
t2, dt2, x2, y2 = np.array([0,]), np.array([0,]), np.array([0,]), np.array([0,])
movement(controller, (x1, y1, x2, y2, t1, t2, dt1, dt2))