2009-10-29 11:26:44 +00:00
|
|
|
# This script must be assigned to a python controller
|
|
|
|
# where it can access the object that owns it and the sensors/actuators that it connects to.
|
|
|
|
|
2010-10-11 22:25:28 +00:00
|
|
|
import bge
|
2009-10-29 11:26:44 +00:00
|
|
|
|
2010-08-11 16:40:36 +00:00
|
|
|
# support for Vector(), Matrix() types and advanced functions like Matrix.Scale(...) and Matrix.Rotation(...)
|
2010-04-11 14:22:27 +00:00
|
|
|
# import mathutils
|
2009-10-29 11:26:44 +00:00
|
|
|
|
|
|
|
# for functions like getWindowWidth(), getWindowHeight()
|
|
|
|
# import Rasterizer
|
|
|
|
|
|
|
|
def main():
|
2010-10-11 22:25:28 +00:00
|
|
|
cont = bge.logic.getCurrentController()
|
2009-10-31 19:31:45 +00:00
|
|
|
|
|
|
|
# The KX_GameObject that owns this controller.
|
|
|
|
own = cont.owner
|
|
|
|
|
|
|
|
# for scripts that deal with spacial logic
|
|
|
|
own_pos = own.worldPosition
|
|
|
|
|
|
|
|
|
|
|
|
# Some example functions, remove to write your own script.
|
|
|
|
# check for a positive sensor, will run on any object without errors.
|
2009-11-21 17:41:09 +00:00
|
|
|
print('Logic info for KX_GameObject', own.name)
|
2009-10-31 19:31:45 +00:00
|
|
|
input = False
|
|
|
|
|
|
|
|
for sens in cont.sensors:
|
|
|
|
# The sensor can be on another object, we may want to use it
|
|
|
|
own_sens = sens.owner
|
2009-11-21 17:41:09 +00:00
|
|
|
print(' sensor:', sens.name, end=' ')
|
2009-10-31 19:31:45 +00:00
|
|
|
if sens.positive:
|
2009-11-21 17:41:09 +00:00
|
|
|
print('(true)')
|
2009-10-31 19:31:45 +00:00
|
|
|
input = True
|
|
|
|
else:
|
2009-11-21 17:41:09 +00:00
|
|
|
print('(false)')
|
2009-10-31 19:31:45 +00:00
|
|
|
|
|
|
|
for actu in cont.actuators:
|
|
|
|
# The actuator can be on another object, we may want to use it
|
|
|
|
own_actu = actu.owner
|
2009-11-21 17:41:09 +00:00
|
|
|
print(' actuator:', actu.name)
|
2009-10-31 19:31:45 +00:00
|
|
|
|
|
|
|
# This runs the actuator or turns it off
|
|
|
|
# note that actuators will continue to run unless explicitly turned off.
|
|
|
|
if input:
|
|
|
|
cont.activate(actu)
|
|
|
|
else:
|
|
|
|
cont.deactivate(actu)
|
|
|
|
|
|
|
|
# Its also good practice to get sensors and actuators by name
|
|
|
|
# rather then index so any changes to their order wont break the script.
|
|
|
|
|
|
|
|
# sens_key = cont.sensors['key_sensor']
|
|
|
|
# actu_motion = cont.actuators['motion']
|
|
|
|
|
|
|
|
|
|
|
|
# Loop through all other objects in the scene
|
2010-10-11 22:25:28 +00:00
|
|
|
sce = bge.logic.getCurrentScene()
|
2009-11-21 17:41:09 +00:00
|
|
|
print('Scene Objects:', sce.name)
|
2009-10-31 19:31:45 +00:00
|
|
|
for ob in sce.objects:
|
2009-11-21 17:41:09 +00:00
|
|
|
print(' ', ob.name, ob.worldPosition)
|
2009-10-31 19:31:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Example where collision objects are checked for their properties
|
|
|
|
# adding to our objects "life" property
|
|
|
|
"""
|
|
|
|
actu_collide = cont.sensors['collision_sens']
|
|
|
|
for ob in actu_collide.objectHitList:
|
|
|
|
# Check to see the object has this property
|
|
|
|
if ob.has_key('life'):
|
|
|
|
own['life'] += ob['life']
|
|
|
|
ob['life'] = 0
|
2009-11-21 17:41:09 +00:00
|
|
|
print(own['life'])
|
2009-10-31 19:31:45 +00:00
|
|
|
"""
|
2009-10-29 11:26:44 +00:00
|
|
|
|
|
|
|
main()
|