Module MyGameWorld
[hide private]
[frames] | no frames]

Source Code for Module MyGameWorld

  1  from Mathutils import Matrix, Vector 
  2  from math import fabs 
  3  import GameLogic 
  4  from MyGameTimer import MY_SingleTimer 
  5   
  6   
7 -class MY_SingleGameWorld(object):
8 """ 9 singleton class of the game's world to set all its laws 10 11 @ivar gravityForce: the power of the gravity (default 9.81) 12 @type gravityForce: Float 13 @ivar gravityVector: the standardized vector for gravity direction 14 @type gravityVector: Vector 15 @ivar planeForceDirection: the gravity direction in the current plane (up=1 or down=-1) 16 @type planeForceDirection: Integer (1 or -1) 17 @ivar isPaused: True if the whole world was stopped by an event 18 @type isPaused: Boolean 19 @ivar gravityAxis: the axis of the gravity direction 20 @type gravityAxis: Integer (0,1,2) 21 @ivar nextItemTime: this is the counter variable for setting an item in the game 22 @type nextItemTime: Integer 23 @ivar nextHurdle: True if it is time for a new hurdle 24 @type nextHurdle: Boolean 25 @ivar specialKeys: True if the player has to use special key input dependent on the current plane of the player 26 @type specialKeys: Boolean 27 @ivar numberOfHurdle: the number of all hurdles in the game 28 @type numberOfHurdle: Integer 29 @ivar deleteDelay: the amount of the delay for deleting objects 30 @type deleteDelay: Integer 31 @ivar boxIntro: True if player has to use the power switch to start the game 32 @type boxIntro: Boolean 33 @ivar soundOn: True if the sound in the background is switched on, False for off 34 @type soundOn: Boolean 35 @ivar switchOn: True is player has used the power switch 36 @type switchOn: Boolean 37 @ivar restartGame: True if the game shall be restarted 38 @type restartGame: Boolean 39 @ivar tpcOn: True if the third person camera shall appear in the lower left corner of the window, False if you wish no visible third person camera 40 @type tpcOn: Boolean 41 @ivar planeRotationMatrix: the rotation matrix that holds the information for every object to know how to get the head up in the sky (world coords) 42 @type planeRotationMatrix: Matrix 43 @ivar isUnusual: True if you want the pure stair insanity 44 @type isUnusual: Boolean 45 """ 46 47 __instance = None # the unique instance 48
49 - def __new__(self, *args, **kargs):
50 if self.__instance is None: 51 self.__instance = object.__new__(self, *args, **kargs) 52 53 # __init__ section 54 self.gravityForce = 9.81 55 self.gravityVector = Vector([0, 0, -1]) 56 self.planeForceDirection = -1 57 self.isPaused = True 58 self.gravityAxis = 2 59 self.nextItemTime = 0 60 self.nextHurdle = False 61 self.specialKeys = False 62 self.numberOfHurdle = 0 63 self.deleteDelay = 0 64 self.boxIntro = True 65 self.soundOn = True 66 self.switchOn = False 67 self.restartGame = False 68 self.tpcOn = False 69 self.planeRotationMatrix = 0 70 self.isUnusual = False 71 72 return self.__instance
73
74 - def __init__(self):
75 pass
76
77 - def setDefaultWorld(self):
78 """ 79 resets the whole game world to default values 80 """ 81 82 self.gravityForce = 9.81 83 self.gravityVector = Vector([0, 0, -1]) 84 self.planeForceDirection = -1 85 self.isPaused = True 86 self.gravityAxis = 2 87 self.nextItemTime = 0 88 self.nextHurdle = False 89 self.specialKeys = False 90 self.numberOfHurdle = 0 91 self.deleteDelay = 0 92 self.boxIntro = True 93 self.soundOn = True 94 self.switchOn = False 95 self.restartGame = False 96 self.tpcOn = False 97 self.planeRotationMatrix = 0 98 self.isUnusual = False
99
100 - def setGravityDirection(self, character_orientation):
101 """ 102 sets the direction of gravity by character_orientation 103 104 @type character_orientation: Matrix 105 @param character_orientation: the current orientation of the player character 106 """ 107 108 ori = character_orientation 109 110 gravity_orientation = Matrix(ori[0], ori[1], ori[2]) * Vector([0, 0, -1]) 111 112 for i,k in enumerate(gravity_orientation): 113 if fabs(k) <= 0.5: 114 gravity_orientation[i] = 0 115 self.gravityVector[i] = 0 116 else: 117 self.gravityAxis = i 118 119 if k > 0: 120 gravity_orientation[i] = 9.81 121 self.gravityVector[i] = 1 122 else: 123 gravity_orientation[i] = -9.81 124 self.gravityVector[i] = -1 125 126 self.planeForceDirection = self.gravityVector[i] 127 128 GameLogic.setGravity(gravity_orientation)
129
130 - def setFeedBack(self, controller, feedback_item, anim=False):
131 """ 132 sets the feedback pictures in the middle of the screen 133 134 @type controller: the controler where the ipo actuator is connected to (only useful with anim=True) 135 @param controller: SCA_PythonController 136 @type feedback_item: String 137 @param feedback_item: the name of the feedback that will appear 138 @type anim: Boolean 139 @param anim: True if there will be an animation (use skill items), False for not feasible actions and game options like sound 140 """ 141 142 scene = GameLogic.getCurrentScene() 143 feedback = scene.objects["OBfeedback"] 144 145 if feedback["show_feedback"]: 146 for obj in feedback.children: 147 obj.visible = False 148 149 if not anim: 150 no_action = scene.objects["OB" + feedback_item] 151 no_action.visible = True 152 else: 153 feedback.children["OB" + feedback_item + "_activate"].visible = True 154 anim = controller.actuators[feedback_item + "_activate"] 155 controller.activate(anim) 156 157 feedback["show_feedback"] = True 158 feedback["timer"] = MY_SingleTimer().NOW
159