Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import GameLogic
- # needs to: recieve variable saying which ship is loaded for example 'red'
- # then loads dictionary 'red' as 'ship'
- # get the controller
- controller = GameLogic.getCurrentController()
- # get a list of sensors connected to the python controller
- senList = controller.sensors
- # get a list of actuators connected to the python controller
- actList = controller.actuators
- # get the motion actuator named Move
- move = actList["Move"]
- shipobject = controller.owner
- red = { "accelForward" : 1500,
- "forwardRoll" : 200,
- "accelBackward" : 200,
- "backwardRoll" : 600,
- "accelBoost" : 1000,
- "boostRoll" : 400,
- "turnRotate" : 500,
- "turnRoll" : 200,
- "turnSlide" : 600,
- "shipWeight" : 800,
- "boostDrain" : 1,
- "regenSpeed" : .5,
- "shieldStrength" : 30,
- "hoverHeight" : 5 }
- shipdata = red
- def hover ():
- #constrain ship to certain height above property:ground
- shipobject.applyForce([0 , 0 , -shipdata["shipWeight"]] , False)
- hoverdetect = senList["hover"]
- if hoverdetect.hitObject:
- hoverdistance = shipobject.getVectTo(hoverdetect.hitObject)
- # print((abs(hoverdistance[0])+abs(hoverdistance[1])+abs(hoverdistance[2])))
- if hoverdetect.range < shipdata["hoverHeight"]:hoverdetect.range = hoverdetect.range + 0.1
- # print(hoverdetect.rayDirection)
- # print(hoverdetect.range)
- if hoverdetect.triggered: shipobject.applyForce([0 , 0 , 1000],True)
- def accelerate ():
- #add to speed and nose down
- shipobject.applyForce([0 , -(shipdata["accelForward"]) , 0] , True)
- shipobject.applyTorque([(shipdata["forwardRoll"]), 0 , 0] , True)
- def decelerate ():
- #subtract from speed and nose up
- shipobject.applyForce([0 , (shipdata["accelBackward"]) , 0] , True)
- shipobject.applyTorque([-(shipdata["backwardRoll"]), 0 , 0] , True)
- def boost ():
- #add to speed, nose up and drain energy
- shipobject.applyForce([0 , -(shipdata["accelBoost"]) , 0] , True)
- shipobject.applyTorque([(shipdata["boostRoll"]), 0 , 0] , True)
- shipobject["health"] = shipobject["health"]-shipdata["boostDrain"]
- if shipobject["health"] < 0: shipobject["health"] = 0
- def turnLeft ():
- #rotate left, roll left, and slide left
- shipobject.applyForce([(shipdata["turnSlide"]) , 0 , 0] , True)
- shipobject.applyTorque([0 , (shipdata["turnRoll"]), (shipdata["turnRotate"])] , True)
- def turnRight ():
- #rotate right, roll right, and slide right
- shipobject.applyForce([-(shipdata["turnSlide"]) , 0 , 0] , True)
- shipobject.applyTorque([0 , -(shipdata["turnRoll"]), -(shipdata["turnRotate"])] , True)
- def hitWall ():
- #activate sheild, subtract damage amount from health
- print(hitwall)
- def regen ():
- #regenerates health
- shipobject["health"] = shipobject["health"] + shipdata["regenSpeed"]
- if shipobject["health"] > 100: shipobject["health"] = 100
- def shipdie ():
- print("you have died")
- def sendvariables ():
- GameLogic.speed = shipobject["speed"]
- GameLogic.health = shipobject["health"]
- GameLogic.checkpointnumber = shipobject["checkpointnumber"]
- GameLogic.lapnumber = shipobject["lapnumber"]
- #main section - recieves keys, updates health/speed counter, hovers ship
- moveforward = senList["forward"]
- movebackward = senList["down"]
- moveleft = senList["left"]
- moveright = senList["right"]
- moveboost = senList["boost"]
- shipobject["speed"] = ((abs(shipobject.getLinearVelocity(1)[1]) + abs(shipobject.getLinearVelocity(1)[0]) + abs(shipobject.getLinearVelocity(1)[2])) * 3 * 60 * 60)/5280
- hover()
- regen()
- if moveforward.positive == True: accelerate()
- if movebackward.positive == True: decelerate()
- if moveleft.positive == True: turnLeft()
- if moveright.positive == True: turnRight()
- if moveboost.positive == True: boost()
- sendvariables()
- if shipobject["health"] < 0: shipdie()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement