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

Source Code for Module MyGameActiveParts

  1  from MyGameObjects import MY_GameObjectActive, MY_GameObjectActiveHidden 
  2  from MyScene import MY_SingleScene 
  3  from math import sqrt, cos, sin, pi, fabs, floor 
  4  from time import clock 
  5  from Mathutils import RotationMatrix, Vector, Matrix 
  6  from MyGameTimer import MY_SingleTimer 
  7  from MySpecialLists import MY_InventoryList 
  8  from MyScene import MY_SingleScene 
  9  from MyGameWorld import MY_SingleGameWorld 
 10  from MyControlKeys import MY_SingleControlKeys 
 11  from MyConfigConnector import MY_SingleConfigConnector 
 12  import GameLogic 
 13  
 
 14  # character class       
 
15 -class MY_GameCharacter(MY_GameObjectActive):
16 """ 17 class of the main game character, which the user has to play 18 19 @ivar isJumping: True if player is jumping 20 @type isJumping: Boolean 21 @ivar isCrouching: True if player is crouching 22 @type isCrouching: Boolean 23 @ivar stepUp: True if payer wants to go upstairs 24 @type stepUp: Boolean 25 @ivar stepDown: Amount of the time to get the player back to ground 26 @type stepDown: Integer 27 @ivar zLook: amount of the rotation angle around the z-axis 28 @type zLook: Float 29 @ivar wallStartTime: the start time of a wallturn 30 @type wallStartTime: Float 31 @ivar wallTurn: True if player makes a ninety or oneighty turn 32 @type wallTurn: Boolean 33 @ivar wallTurnEnd: True if a turn just ended 34 @type wallTurnEnd: Boolean 35 @ivar turnDuration: the duration of a turn 36 @type turnDuration: Integer 37 @ivar worldPlane: the players current plane 38 @type worldPlane: Integer (0,1,2) 39 @ivar oppositePlane: True if player is on one of the planes which gravity vector goes in th direction of z, -x or -y 40 @type oppositePlane: Boolean 41 @ivar globalRotationX: the rotation amount about x-axis when turning 42 @type globalRotationX: Integer 43 @ivar globalRotationY: the rotation amount about y-axis when turning 44 @type globalRotationY: Integer 45 @ivar zTurn: the rotation about z-axis; just for calculating the wallturn while turning 46 @type zTurn: Float 47 @ivar cosX: the cosinus amount of looking up and down 48 @type cosX: Float 49 @ivar sinX: the sinus amount of looking up and down 50 @type sinX: Float 51 @ivar angleXTotal: the global rotation about the x-axis of the player (player rotates finally just about x and y) 52 @type angleXTotal: Integer 53 @ivar angleYTotal: the global rotation about the y-axis of the player (player rotates finally just about x and y) 54 @type angleYTotal: Integer 55 @ivar angleX: just a temporary variable to leave the angleXTotal variable untouched 56 @type angleX: Float 57 @ivar angleY: just a temporary variable to leave the angleYTotal variable untouched 58 @type angleY: Float 59 @ivar groundObject: the object that is right under the player's feet 60 @type groundObject: MY_GameObject 61 @ivar inventoryList: a list that contains all amounts of your inventoriy items 62 @type inventoryList: MY_InventoryList 63 @ivar shotTime: the time when you shot a bullet 64 @type shotTime: Float 65 @ivar shotInterval: the interval of shots 66 @type shotInterval: Float 67 @ivar flyTime: the time when you began to leave the ground 68 @type flyTime: Float 69 @ivar mag: the total amount of the player's mag 70 @type mag: Integer 71 @ivar ammo: the amount of bullets the player has in his gun 72 @type ammo: Integer 73 @ivar aim: True if player aims at a target, otherwise False 74 @type aim: Boolean 75 @ivar hasVisor: True if player uses visor, else False 76 @type hasVisor: Boolean 77 @ivar visorAnimStart: the time when player clicked the v-key to get his visor 78 @type visorAnimStart: Float 79 @ivar godMode: True if player is in godmode; normally after a hurdle hit to stay alive and not to lose all your health 80 @type godMode: Boolean 81 @ivar godStartTime: the time when the player godmode started 82 @type godStartTime: Float 83 @ivar rotationPointObject: the object to set at the center of a rotation object while doing a oneighty 84 @type rotationPointObject: KX_GameObject 85 @ivar visualInput: the object to set at the screen to let the player know what orientation he/she/it has 86 @type visualInput: KX_GameObject 87 @ivar visualInputObject: the actual object the payer will see as visual feedback for his/her orientation 88 @type visualInputObject: KX_GameObject 89 @ivar lookCamera: the camera object the player uses for looking around (for example: first person or third person) 90 @type lookCamera: KX_Camera 91 @ivar superGun: the player has collected the rare super gun in the game 92 @type superGun: Boolean 93 @ivar useSuperGun: True if the player is currently using the super gun, else False 94 @type useSuperGun: Boolean 95 """ 96
97 - def __init__(self, scene, element):
98 MY_GameObjectActive.__init__(self, scene, element) 99 self.isJumping = True 100 self.isCrouching = False 101 self.stepUp = False 102 self.stepDown = 0 103 self.zLook = 0.0 104 self.wallStartTime = 0.0 105 self.wallTurn = False 106 self.wallTurnEnd = True 107 self.turnDuration = 0 108 self.worldPlane = 0 109 self.oppositePlane = False 110 self.globalRotationX = 0 111 self.globalRotationY = 0 112 self.zTurn = 0 113 self.cosX = 1.0 114 self.sinX = 0.0 115 self.angleXTotal = 0 116 self.angleX = 0 117 self.angleYTotal = 0 118 self.angleY = 0 119 self.groundObject = None 120 self.inventoryList = MY_InventoryList() 121 self.shotTime = 0 122 self.shotInterval = 0 123 self.flyTime = 0 124 self.mag = 0 125 self.ammo = 0 126 self.aim = False 127 self.hasVisor = False 128 self.visorAnimStart = 0.0 129 self.godMode = False 130 self.godStartTime = 0.0 131 self.rotationPointObject = None 132 self.visualInput = scene.objects["OBvisual_input"] 133 self.visualInputObject = scene.objects["OBvisual_input_object"] 134 self.lookCamera = scene.objects["OBfpc"] 135 self.superGun = False 136 self.useSuperGun = False 137 138 self.inventoryList.fillWithConfigValues() 139 140 for i in self.inventoryList.inventoryList: 141 real_name = "OB" + i[1] 142 gauge_icon = scene.objects[real_name] 143 gauge_icon.visible = True 144 itemGauge = MY_GameGauge(scene, i[1]) 145 itemGauge.setPosition(Vector(gauge_icon.worldPosition) - Vector([-0.007, 0, 0.045])) 146 itemGauge.theText = i[0] 147 itemGauge.setText() 148 if i[1] == "sniper": 149 if i[0] == 0: 150 gauge_icon.visible = False 151 else: 152 self.superGun = True 153 itemGauge.gObject.visible = gauge_icon.visible 154 155 if self.gObject: 156 myScene = MY_SingleScene() 157 myScene.addObject(self)
158
159 - def setView(self, window_metric):
160 """ 161 sets the players view. to switch between first person and third persion view 162 163 @type window_metric: List [Integer, Integer] 164 @param window_metric: a list of thw width and height of the game window 165 """ 166 167 window_width = window_metric[0] 168 window_height = window_metric[1] 169 self.lookCamera.setViewport(0, 0, window_width, window_height) 170 self.lookCamera.useViewport = True
171
172 - def jump(self, speed, force):
173 """ 174 sets the jump digit of the speed vector with the given force 175 176 @type speed: Vector 177 @param speed: the speed vector of the player 178 @type force: Integer 179 @param force: the power of the jump 180 181 @rtype: Vector 182 @return: the prepared speed vector 183 """ 184 185 self.isJumping = True 186 speed[2] += force 187 step_down_amount = 6 188 189 return speed
190
191 - def marioJump(self, hurdle_pos):
192 """ 193 sets the mario jump, to get out of the way of an enemy after get hurt once 194 195 @type hurdle_pos: Vector 196 @param hurdle_pos: the global position of the hurdle 197 """ 198 199 force_up = 10 200 jump = MY_SingleGameWorld().gravityVector * -force_up 201 202 max_ground_speed = 10 203 204 direction_vector = self.getPosition() - hurdle_pos 205 ground_speed = [] 206 207 for i,k in enumerate(MY_SingleGameWorld().gravityVector): 208 if fabs(k) < 1: # ground movement 209 ground_speed.append([i, direction_vector[i]]) 210 211 full_ground_speed = fabs(ground_speed[0][1]) + fabs(ground_speed[1][1]) 212 sign = 1 213 if ground_speed[0][1] < 0: 214 sign = -1 215 jump[ground_speed[0][0]] = fabs(ground_speed[0][1]) / full_ground_speed * sign * max_ground_speed 216 sign = 1 217 if ground_speed[1][1] < 0: 218 sign = -1 219 jump[ground_speed[1][0]] = fabs(ground_speed[1][1]) / full_ground_speed * sign * max_ground_speed 220 221 self.gObject.setLinearVelocity(jump)
222
223 - def move(self, fwd, back, left, right, force):
224 """ 225 calculates the movement of the object, dependent on given input parameters (direction and force) 226 227 @type fwd: Boolean 228 @param fwd: the power of forward movement 229 @type back: Boolean 230 @param back: the power of backward movement 231 @type left: Boolean 232 @param left: the power of left movement 233 @type right: Boolean 234 @param right: the power of right movement 235 @type force: Integer 236 @param force: the speed of the player's total movement 237 238 @rtype: Vector 239 @return: the prepared speed vector for the player's character 240 """ 241 242 sqrt2over2 = sqrt(2)/2 243 244 fspeed = force * (fwd - back) 245 sspeed = force * (right - left) 246 247 if fspeed and sspeed: 248 fspeed *= sqrt2over2 249 sspeed *= sqrt2over2 250 251 speed = [sspeed, fspeed, 0] 252 253 return speed
254
255 - def look(self, mouse_screen_pos, dtime, sensitivity):
256 """ 257 sets the players actual camera view dependent on user's mouse input, elapsed time and sensitivity 258 259 @type mouse_screen_pos: List [Integer, Integer] 260 @param mouse_screen_pos: the position of the mouse on the screen related to the window metric 261 @type dtime: Float 262 @param dtime: the delta of time between two logical ticks 263 @type sensitivity: Float 264 @param sensitivity: the speed of turning your eyes around 265 """ 266 267 if self.wallTurn: 268 self.planeTurn() 269 else: 270 # Mouse sensitivity 271 xsensitivity = -sensitivity 272 ysensitivity = sensitivity 273 274 ## z axis rotation of character 275 oz = self.zLook 276 zrot = 180 * xsensitivity * dtime * mouse_screen_pos[0] 277 self.zLook = oz + zrot 278 279 # x axis rotation of cam 280 osx = self.sinX 281 ocx = self.cosX 282 xrot = (pi * ysensitivity) * dtime * mouse_screen_pos[1] 283 sxrot = sin(xrot) 284 cxrot = cos(xrot) 285 self.cosX = -osx * sxrot + ocx * cxrot 286 self.sinX = osx * cxrot + ocx * sxrot 287 288 # prevent looking top or bottom 289 if self.cosX < 0.5: 290 self.cosX = ocx 291 self.sinX = osx 292 293 wall_rotx = RotationMatrix(self.angleXTotal, 3, "x") 294 wall_roty = RotationMatrix(self.angleYTotal, 3, "y") 295 wall_rotz = RotationMatrix(self.zLook, 3, "z") 296 MY_SingleGameWorld().planeRotationMatrix = wall_rotx * wall_roty 297 self.gObject.localOrientation = wall_rotx * wall_roty * wall_rotz 298 299 self.lookCamera.localOrientation = Matrix( [1, 0, 0], 300 [0, -self.sinX, -self.cosX], 301 [0, self.cosX, -self.sinX] ) 302 303 if MY_SingleGameWorld().specialKeys: 304 self.visualInputObject.setVisible(True, True) 305 self.visualInputObject.worldPosition = self.visualInput.worldPosition 306 else: 307 self.visualInputObject.setVisible(False, True)
308
309 - def initOneighty(self, turn_duration):
310 """ 311 initialize the 'Oneighty' with the right parameters and given duration 312 it sets the used member variables with the right values to know how to rotate and the local rotation of the player afterwards 313 and parents the player to the rotating ground object 314 315 @type turn_duration: Integer 316 @param turn_duration: how fast/slow the turn shall be 317 """ 318 319 self.godMode = True 320 self.wallStartTime = MY_SingleTimer().NOW * 1000 321 self.wallTurn = True 322 self.turnDuration = turn_duration 323 324 print "world plane: ", 325 print self.worldPlane 326 print "angle x: ", 327 print self.angleXTotal 328 print "angle y: ", 329 print self.angleYTotal 330 print "opposite: ", 331 print self.oppositePlane 332 333 myGroundObject = self.groundObject 334 335 direction = myGroundObject.worldDirection 336 name = myGroundObject.name 337 338 if self.worldPlane == 0: 339 if direction == 0 or direction == 2: 340 if name == "single_step": 341 self.globalRotationY = 180 342 elif name == "stair": 343 self.globalRotationX = 180 344 else: 345 if name == "single_step": 346 self.globalRotationX = 180 347 elif name == "stair": 348 self.globalRotationY = 180 349 elif self.worldPlane == 1: 350 if direction == 0 or direction == 2: 351 if name == "single_step": 352 self.zTurn = 180 353 self.globalRotationX = 180 354 else: 355 if name == "stair": 356 self.zTurn = 180 357 self.globalRotationX = 180 358 elif self.worldPlane == 2: 359 if direction == 0 or direction == 2: 360 if name == "single_step": 361 self.zTurn = 180 362 self.globalRotationY = 180 363 else: 364 if name == "stair": 365 self.zTurn = 180 366 self.globalRotationY = 180 367 368 self.wallTurnEnd = False 369 370 if self.oppositePlane: 371 self.oppositePlane = False 372 else: 373 self.oppositePlane = True 374 375 if self.globalRotationX == 180 and self.angleYTotal != 0: 376 self.angleXTotal = self.angleYTotal 377 self.angleYTotal = 0 378 elif self.globalRotationY == 180 and self.angleXTotal != 0: 379 self.angleYTotal = -self.angleXTotal 380 self.angleXTotal = 0 381 382 self.rotationPointObject.worldPosition = myGroundObject.midPoint 383 if self.groundObject != None: 384 self.groundObject.gObject.setParent(self.rotationPointObject, 0, 1) 385 self.gObject.setParent(self.rotationPointObject, 0, 1) 386 if self.groundObject.hurdleObject != None: 387 self.groundObject.hurdleObject.gObject.setParent(self.rotationPointObject, 0, 1) 388 self.gObject.setLinearVelocity([0, 0, 0]) 389 GameLogic.setGravity([0,0,0])
390
391 - def initWallRun(self, global_collision_side, hit_plane, turn_duration):
392 """ 393 initialize the wall turn. it sets the used member variables with the right values 394 395 @type global_collision_side: Integer (0,1,2,3) 396 @param global_collision_side: where is the wall globally? (at least to know rotation axis) 397 @type hit_plane: Integer (0,1,2) 398 @param hit_plane: the plane of the hit object, to know the player's world plane after rotation 399 @type turn_duration: Integer 400 @param turn_duration: time to rotate 401 """ 402 403 self.godMode = True 404 self.wallStartTime = MY_SingleTimer().NOW * 1000 405 self.wallTurn = True 406 self.turnDuration = turn_duration 407 408 print "world plane: ", 409 print self.worldPlane 410 print "angle x: ", 411 print self.angleXTotal 412 print "angle y: ", 413 print self.angleYTotal 414 print "opposite: ", 415 print self.oppositePlane 416 417 sign = 1 418 if self.oppositePlane: 419 sign = -1 420 421 if self.worldPlane == 0: 422 if global_collision_side == "front": 423 self.globalRotationX = sign * -90 424 self.oppositePlane = False 425 elif global_collision_side == "right": 426 self.globalRotationY = sign * 90 427 self.oppositePlane = False 428 elif global_collision_side == "back": 429 self.globalRotationX = sign * 90 430 self.oppositePlane = True 431 elif global_collision_side == "left": 432 self.globalRotationY = sign * -90 433 self.oppositePlane = True 434 elif self.worldPlane == 1: 435 if global_collision_side == "front": 436 self.globalRotationX = sign * -90 437 self.oppositePlane = True 438 elif global_collision_side == "right": 439 self.globalRotationY = 90 440 self.zTurn = sign * 90 441 self.oppositePlane = False 442 elif global_collision_side == "back": 443 self.globalRotationX = sign * 90 444 self.oppositePlane = False 445 elif global_collision_side == "left": 446 self.globalRotationY = -90 447 self.zTurn = sign * -90 448 self.oppositePlane = True 449 elif self.worldPlane == 2: 450 if global_collision_side == "front": 451 self.globalRotationY = sign * 90 452 self.oppositePlane = True 453 elif global_collision_side == "right": 454 self.globalRotationX = 90 455 self.zTurn = sign * 90 456 self.oppositePlane = True 457 elif global_collision_side == "back": 458 self.globalRotationY = sign * -90 459 self.oppositePlane = False 460 elif global_collision_side == "left": 461 self.globalRotationX = -90 462 self.zTurn = sign * -90 463 self.oppositePlane = False 464 465 if fabs(self.globalRotationX) == 90 and self.angleYTotal == -180: 466 self.angleXTotal = self.angleYTotal * (self.globalRotationX/90) 467 self.angleYTotal = 0 468 self.zLook -= 180 469 elif fabs(self.globalRotationX) == 90 and self.angleYTotal == 180: 470 self.angleXTotal = -self.angleYTotal * (self.globalRotationX/90) 471 self.angleYTotal = 0 472 self.zLook -= 180 473 elif fabs(self.globalRotationY) == 90 and self.angleXTotal == 180: 474 self.angleYTotal = -self.angleXTotal * (self.globalRotationY/90) 475 self.angleXTotal = 0 476 self.zLook -= 180 477 elif fabs(self.globalRotationY) == 90 and self.angleXTotal == -180: 478 self.angleYTotal = self.angleXTotal * (self.globalRotationY/90) 479 self.angleXTotal = 0 480 self.zLook -= 180 481 482 self.zLook %= 360 483 484 self.wallTurnEnd = False 485 self.worldPlane = hit_plane 486 487 self.rotationPointObject.worldPosition = self.getPosition() 488 self.gObject.setParent(self.rotationPointObject, 0, 1) 489 self.gObject.setLinearVelocity([0, 0, 0]) 490 GameLogic.setGravity([0,0,0])
491
492 - def planeTurn(self):
493 """ 494 do the Oneighty 495 """ 496 497 timer_now = MY_SingleTimer().NOW * 1000 498 499 wall_rot = RotationMatrix(0, 3, "x") 500 501 if timer_now < self.wallStartTime + self.turnDuration and not self.wallTurnEnd: 502 perc = (timer_now - self.wallStartTime) / self.turnDuration 503 pangle = 0 504 505 if self.zTurn != 0: 506 pangle = self.zTurn * perc 507 508 axis = "z" 509 else: 510 axis = "x" 511 if self.globalRotationX != 0: 512 pangle = self.globalRotationX * perc 513 else: 514 pangle = self.globalRotationY * perc 515 axis = "y" 516 517 wall_rot_vis = RotationMatrix(pangle, 3, axis) 518 519 elif not self.wallTurnEnd: 520 521 if self.zTurn != 0: 522 pangle = self.zTurn 523 axis = "z" 524 else: 525 axis = "x" 526 if self.globalRotationX != 0: 527 pangle = self.globalRotationX 528 else: 529 pangle = self.globalRotationY 530 axis = "y" 531 532 self.rotationPointObject.localOrientation = RotationMatrix(pangle, 3, axis) 533 534 if self.globalRotationX != 0: 535 self.angleXTotal += self.globalRotationX 536 else: 537 self.angleXTotal = 0 538 539 if self.globalRotationY != 0: 540 self.angleYTotal += self.globalRotationY 541 else: 542 self.angleYTotal = 0 543 544 if self.angleXTotal < -180: 545 self.angleXTotal += 360 546 elif self.angleXTotal > 180: 547 self.angleXTotal -= 360 548 549 if self.angleYTotal < -180: 550 self.angleYTotal += 360 551 elif self.angleYTotal > 180: 552 self.angleYTotal -= 360 553 554 print "" 555 print "world plane: ", 556 print self.worldPlane 557 print "angle x: ", 558 print self.angleXTotal 559 print "angle y: ", 560 print self.angleYTotal 561 print "opposite: ", 562 print self.oppositePlane 563 print "end_rot" 564 print "------------------" 565 566 wall_rotx = RotationMatrix(self.angleXTotal, 3, "x") 567 wall_roty = RotationMatrix(self.angleYTotal, 3, "y") 568 569 wall_rot = wall_roty * wall_rotx 570 571 self.zLook += self.zTurn 572 self.zTurn = 0 573 574 self.globalRotationX = 0 575 self.globalRotationY = 0 576 577 self.wallTurnEnd = True 578 579 self.wallStartTime = 0 580 self.wallTurn = False 581 582 if self.groundObject != None: 583 self.groundObject.gObject.removeParent() 584 if self.groundObject.hurdleObject != None: 585 self.groundObject.hurdleObject.gObject.removeParent() 586 self.gObject.removeParent() 587 588 wall_rot_vis = RotationMatrix(0, 3, "z") 589 MY_SingleGameWorld().setGravityDirection(wall_rot) 590 591 self.godMode = False 592 593 self.rotationPointObject.localOrientation = wall_rot_vis 594 595 self.gObject.setLinearVelocity([0,0,0]) 596 597 if MY_SingleGameWorld().specialKeys: 598 MY_SingleControlKeys().setControlKeysEffect(self.worldPlane, self.oppositePlane)
599
600 - def setInventoryItem(self, item_name, add):
601 """ 602 sets or removes given item into the inventory 603 604 @type item_name: String 605 @param item_name: the name of the item that was used/collected 606 @type add: Boolean 607 @param add: True if the item was collected, False if it was used 608 609 @rtype: Boolean 610 @return: 'True' if item is in inventory, else 'False' 611 """ 612 if MY_SingleGameWorld().isUnusual: 613 exist = True 614 else: 615 exist = self.inventoryList.useItem(item_name, add) 616 self.setInventoryGauge() 617 618 return exist
619
620 - def setInventoryGauge(self):
621 """ 622 refresh the inventory gauge on the screen and in the config parser 623 """ 624 if MY_SingleGameWorld().isUnusual: 625 for i in self.inventoryList.inventoryList: 626 if i[1] != "sniper": 627 itemGauge = MY_SingleScene()[i[1]] 628 itemGauge.gObject.visible = False 629 MY_SingleScene().scene.objects["OB" + i[1] + "_inf"].visible = True 630 else: 631 for i in self.inventoryList.inventoryList: 632 itemGauge = MY_SingleScene()[i[1]] 633 MY_SingleScene().scene.objects["OB" + i[1] + "_inf"].visible = False 634 itemGauge.gObject.visible= True 635 itemGauge.theText = i[0] 636 itemGauge.setText() 637 if i[1] == "sniper": 638 if i[0] > 0: 639 GameLogic.getCurrentScene().objects["OB" + i[1]].visible = True 640 self.superGun = True 641 else: 642 GameLogic.getCurrentScene().objects["OB" + i[1]].visible = False 643 self.superGun = False 644 itemGauge.gObject.visible = GameLogic.getCurrentScene().objects["OB" + i[1]].visible
645
646 - def getItemLifeTime(self, name):
647 """ 648 sets the lifetime of an used item 649 650 @type name: String 651 @param name: the name of the used item to get its lifetime 652 653 @rtype: Boolean 654 @return: 'True' if item is still alive, else 'False' 655 """ 656 657 item = self.inventoryList[name] 658 if item[2] != item[3]: 659 myTimer = MY_SingleTimer() 660 if floor(myTimer.NOW) > floor(myTimer.AGO): 661 if item[2] <= 0: 662 item[2] = item[3] 663 else: 664 item[2] -= 1 665 666 return True 667 668 return False
669
670 - def setMerchItem(self, merch_name):
671 """ 672 adds a given merchandise item into the inventory 673 674 @type merch_name: String 675 @param merch_name: the name of the merch item that was collected 676 """ 677 678 self.inventoryList.addMerchItem(merch_name)
679
680 - def setWarp(self):
681 """ 682 do a space warp 683 """ 684 685 pass
686
687 - def reloadAmmo(self):
688 """ 689 reloads your ammo 690 """ 691 692 self.ammo = self.mag
693 694 695 # sky sphere class
696 -class MY_SkySphere(MY_GameObjectActive):
697 """ 698 class of the unversum sphere which centers on the player 699 """ 700
701 - def __init__(self, scene, element):
702 """ 703 @type scene: KX_Scene 704 @param scene: the blender scene object which holds all objects 705 @type element: String 706 @param element: the name of the object which shall included into the MY_SingleScene class 707 """ 708 709 MY_GameObjectActive.__init__(self, scene, element) 710 711 if self.gObject: 712 myScene = MY_SingleScene() 713 myScene.addObject(self)
714
715 - def setAction(self, axis, location):
716 """ 717 sets the sky dome rotation 718 719 @type axis: Integer (0,1,2) 720 @param axis: the rotation axis of the sky sphere 721 @type location: Vector 722 @param location: the new position of the sphere's centre 723 """ 724 725 rad = ((clock()*0.001) % 2) * pi 726 727 cosa = cos(rad) 728 sina = sin(rad) 729 730 self.gObject.position = location 731 self.gObject.orientation = [ [cosa, -sina, 0], [sina, cosa, 0], [0, 0, 1] ]
732 733 734 # gauge class
735 -class MY_GameGauge(MY_GameObjectActiveHidden):
736 """ 737 class of the gauge elements, like inventory, health etc. 738 739 @ivar name: the object's name 740 @type name: String 741 @ivar theText: the text the gauge shall display (Integer for gauge_num and String for gauge_text) 742 @type theText: String or Integer 743 """ 744
745 - def __init__(self, scene, element, text=False):
746 """ 747 @type scene: KX_Scene 748 @param scene: the blender scene object which holds all objects 749 @type text: Boolean 750 @param text: True if it is a text otherwise it is a number 751 """ 752 753 if text: 754 MY_GameObjectActiveHidden.__init__(self, scene, "gauge_text") 755 self.gObject.setParent(scene.objects["OB" + element], 0, 0) 756 self.gObject.orientation = RotationMatrix(-90, 3, "x") 757 else: 758 MY_GameObjectActiveHidden.__init__(self, scene, "gauge_num") 759 self.gObject.setParent(scene.objects["OB" + element], 0, 0) 760 self.gObject.localScale = [0.015, 0.015, 0.015] 761 self.gObject.orientation = RotationMatrix(-90, 3, "x") 762 763 self.name = element 764 self.theText = 0 765 766 if self.gObject: 767 myScene = MY_SingleScene() 768 myScene.addObject(self)
769
770 - def setText(self):
771 """ 772 sets the text to be displayed in the player's gauge 773 """ 774 775 self.gObject["Text"] = self.theText
776
777 - def setVisible(self, visible):
778 """ 779 sets the visibility of a gauge item 780 781 @type visible: Boolean 782 @param visible: sets the visibility of the text (True = visible; False = not visible) 783 """ 784 785 self.gObject.setVisible(visible, False)
786
787 - def setPosition(self, position):
788 """ 789 sets the world position 790 791 @type position: Vector 792 @param position: the new world position of the text 793 """ 794 795 self.gObject.worldPosition = position
796