3
Name: 'GameLogic Example'
5
Group: 'ScriptTemplate'
6
Tooltip: 'Script template with examples of how to use game logic'
9
from Blender import Window
14
# GameLogic has been added to the global namespace no need to import
16
# for keyboard event comparison
19
# support for Vector(), Matrix() types and advanced functions like AngleBetweenVecs(v1,v2) and RotationMatrix(...)
22
# for functions like getWindowWidth(), getWindowHeight()
26
cont = GameLogic.getCurrentController()
28
# The KX_GameObject that owns this controller.
31
# for scripts that deal with spacial logic
32
own_pos = own.getPosition()
35
# Some example functions, remove to write your own script.
36
# check for a positive sensor, will run on any object without errors.
37
print 'Logic info for KX_GameObject', own.getName()
40
for sens in cont.getSensors():
41
# The sensor can be on another object, we may want to use it
42
own_sens = sens.getOwner()
43
print ' sensor:', sens.getName(),
50
for actu in cont.getActuators():
51
# The actuator can be on another object, we may want to use it
52
own_actu = actu.getOwner()
53
print ' actuator:', sens.getName()
55
# This runs the actuator or turns it off
56
# note that actuators will continue to run unless explicitly turned off.
58
GameLogic.addActiveActuator(actu, True)
60
GameLogic.addActiveActuator(actu, False)
62
# Its also good practice to get sensors and actuators by names
63
# so any changes to their order wont break the script.
65
# sens_key = cont.getSensor('key_sensor')
66
# actu_motion = cont.getActuator('motion')
69
# Loop through all other objects in the scene
70
sce = GameLogic.getCurrentScene()
71
print 'Scene Objects:', sce.getName()
72
for ob in sce.getObjectList():
73
print ' ', ob.getName(), ob.getPosition()
76
# Example where collision objects are checked for their properties
77
# adding to our objects "life" property
79
actu_collide = cont.getSensor('collision_sens')
80
for ob in actu_collide.getHitObjectList():
81
# Check to see the object has this property
82
if hasattr(ob, 'life'):
90
new_text = bpy.data.texts.new('gamelogic_example.py')
91
new_text.write(script_data)
92
bpy.data.texts.active = new_text