SHARE
TWEET

Untitled

a guest Aug 12th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import GameLogic
  2. # needs to: recieve variable saying which ship is loaded for example 'red'
  3. # then loads dictionary 'red' as 'ship'
  4.  
  5. # get the controller
  6. controller = GameLogic.getCurrentController()
  7. # get a list of sensors connected to the python controller
  8. senList = controller.sensors
  9. # get a list of actuators connected to the python controller
  10. actList = controller.actuators
  11. # get the motion actuator named Move
  12. move = actList["Move"]
  13.  
  14. shipobject = controller.owner
  15.  
  16. red = { "accelForward" : 1500,
  17.         "forwardRoll" : 200,
  18.         "accelBackward" : 200,
  19.         "backwardRoll" : 600,
  20.         "accelBoost" : 1000,
  21.         "boostRoll" : 400,
  22.         "turnRotate" : 500,
  23.         "turnRoll" : 200,
  24.         "turnSlide" : 600,
  25.         "shipWeight" : 800,
  26.         "boostDrain" : 1,
  27.         "regenSpeed" : .5,
  28.         "shieldStrength" : 30,
  29.         "hoverHeight" : 5 }
  30. shipdata = red
  31.  
  32. def hover ():
  33.     #constrain ship to certain height above property:ground
  34.     shipobject.applyForce([0 , 0 , -shipdata["shipWeight"]] , False)
  35.     hoverdetect = senList["hover"]
  36.     if hoverdetect.hitObject:
  37.         hoverdistance = shipobject.getVectTo(hoverdetect.hitObject)
  38. #        print((abs(hoverdistance[0])+abs(hoverdistance[1])+abs(hoverdistance[2])))
  39.     if hoverdetect.range < shipdata["hoverHeight"]:hoverdetect.range = hoverdetect.range + 0.1
  40. #    print(hoverdetect.rayDirection)
  41. #    print(hoverdetect.range)
  42.     if hoverdetect.triggered: shipobject.applyForce([0 , 0 , 1000],True)
  43.  
  44. def accelerate ():
  45.     #add to speed and nose down
  46.     shipobject.applyForce([0 , -(shipdata["accelForward"]) , 0] , True)
  47.     shipobject.applyTorque([(shipdata["forwardRoll"]), 0 , 0] , True)
  48.    
  49. def decelerate ():
  50.     #subtract from speed and nose up
  51.     shipobject.applyForce([0 , (shipdata["accelBackward"]) , 0] , True)
  52.     shipobject.applyTorque([-(shipdata["backwardRoll"]), 0 , 0] , True)
  53.  
  54. def boost ():
  55.     #add to speed, nose up and drain energy
  56.     shipobject.applyForce([0 , -(shipdata["accelBoost"]) , 0] , True)
  57.     shipobject.applyTorque([(shipdata["boostRoll"]), 0 , 0] , True)
  58.     shipobject["health"] = shipobject["health"]-shipdata["boostDrain"]
  59.     if shipobject["health"] < 0: shipobject["health"] = 0
  60.  
  61. def turnLeft ():
  62.     #rotate left, roll left, and slide left
  63.     shipobject.applyForce([(shipdata["turnSlide"]) , 0 , 0] , True)
  64.     shipobject.applyTorque([0 , (shipdata["turnRoll"]), (shipdata["turnRotate"])] , True)
  65.  
  66. def turnRight ():
  67.     #rotate right, roll right, and slide right
  68.     shipobject.applyForce([-(shipdata["turnSlide"]) , 0 , 0] , True)
  69.     shipobject.applyTorque([0 , -(shipdata["turnRoll"]), -(shipdata["turnRotate"])] , True)
  70.  
  71. def hitWall ():
  72.     #activate sheild, subtract damage amount from health
  73.     print(hitwall)
  74.  
  75. def regen ():
  76.     #regenerates health
  77.     shipobject["health"] = shipobject["health"] + shipdata["regenSpeed"]
  78.     if shipobject["health"] > 100: shipobject["health"] = 100
  79.  
  80. def shipdie ():
  81.     print("you have died")
  82.    
  83. def sendvariables ():
  84.     GameLogic.speed = shipobject["speed"]
  85.     GameLogic.health = shipobject["health"]
  86.     GameLogic.checkpointnumber = shipobject["checkpointnumber"]
  87.     GameLogic.lapnumber = shipobject["lapnumber"]
  88.  
  89. #main section - recieves keys, updates health/speed counter, hovers ship
  90.  
  91. moveforward = senList["forward"]
  92. movebackward = senList["down"]
  93. moveleft = senList["left"]
  94. moveright = senList["right"]
  95. moveboost = senList["boost"]
  96.  
  97. shipobject["speed"] = ((abs(shipobject.getLinearVelocity(1)[1]) + abs(shipobject.getLinearVelocity(1)[0]) + abs(shipobject.getLinearVelocity(1)[2])) * 3 * 60 * 60)/5280
  98. hover()
  99. regen()
  100.  
  101. if moveforward.positive == True: accelerate()
  102. if movebackward.positive == True: decelerate()
  103. if moveleft.positive == True: turnLeft()
  104. if moveright.positive == True: turnRight()
  105. if moveboost.positive == True: boost()
  106.  
  107. sendvariables()
  108.  
  109. if shipobject["health"] < 0: shipdie()
RAW Paste Data
Top