~ubuntu-branches/ubuntu/maverick/blender/maverick

« back to all changes in this revision

Viewing changes to release/scripts/scripttemplate_gamelogic.py

  • Committer: Bazaar Package Importer
  • Author(s): Khashayar Naderehvandi, Khashayar Naderehvandi, Alessio Treglia
  • Date: 2009-01-22 16:53:59 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090122165359-v0996tn7fbit64ni
Tags: 2.48a+dfsg-1ubuntu1
[ Khashayar Naderehvandi ]
* Merge from debian experimental (LP: #320045), Ubuntu remaining changes:
  - Add patch correcting header file locations.
  - Add libvorbis-dev and libgsm1-dev to Build-Depends.
  - Use avcodec_decode_audio2() in source/blender/src/hddaudio.c

[ Alessio Treglia ]
* Add missing previous changelog entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!BPY
 
2
"""
 
3
Name: 'GameLogic Example'
 
4
Blender: 245
 
5
Group: 'ScriptTemplate'
 
6
Tooltip: 'Script template with examples of how to use game logic'
 
7
"""
 
8
 
 
9
from Blender import Window
 
10
import bpy
 
11
 
 
12
script_data = \
 
13
'''
 
14
# GameLogic has been added to the global namespace no need to import
 
15
 
 
16
# for keyboard event comparison
 
17
# import GameKeys 
 
18
 
 
19
# support for Vector(), Matrix() types and advanced functions like AngleBetweenVecs(v1,v2) and RotationMatrix(...)
 
20
# import Mathutils 
 
21
 
 
22
# for functions like getWindowWidth(), getWindowHeight()
 
23
# import Rasterizer
 
24
 
 
25
def main():
 
26
        cont = GameLogic.getCurrentController()
 
27
        
 
28
        # The KX_GameObject that owns this controller.
 
29
        own = cont.getOwner()
 
30
        
 
31
        # for scripts that deal with spacial logic
 
32
        own_pos = own.getPosition() 
 
33
        
 
34
        
 
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()
 
38
        input = False
 
39
        
 
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(),
 
44
                if sens.isPositive():
 
45
                        print '(true)'
 
46
                        input = True
 
47
                else:
 
48
                        print '(false)'
 
49
        
 
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()
 
54
                
 
55
                # This runs the actuator or turns it off
 
56
                # note that actuators will continue to run unless explicitly turned off.
 
57
                if input:
 
58
                        GameLogic.addActiveActuator(actu, True)
 
59
                else:
 
60
                        GameLogic.addActiveActuator(actu, False)
 
61
        
 
62
        # Its also good practice to get sensors and actuators by names
 
63
        # so any changes to their order wont break the script.
 
64
        
 
65
        # sens_key = cont.getSensor('key_sensor')
 
66
        # actu_motion = cont.getActuator('motion')
 
67
        
 
68
        
 
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()
 
74
        
 
75
        
 
76
        # Example where collision objects are checked for their properties
 
77
        # adding to our objects "life" property
 
78
        """
 
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'):
 
83
                        own.life += ob.life
 
84
                        ob.life = 0
 
85
        print own.life
 
86
        """
 
87
main()
 
88
'''
 
89
 
 
90
new_text = bpy.data.texts.new('gamelogic_example.py')
 
91
new_text.write(script_data)
 
92
bpy.data.texts.active = new_text
 
93
Window.RedrawAll()