Shuvit game master repo. http://shuvit.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bike.py 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. import bge
  2. from mathutils import Vector
  3. dict = bge.logic.globalDict
  4. scene = bge.logic.getCurrentScene()
  5. skater = scene.objects["Char4"]
  6. TURN_SENS = .04
  7. TURNAMT = .03
  8. ACCEL_AMT = .05
  9. def get_physics_action(cont, own):
  10. #print(dict['lLR'])
  11. action = 'None'
  12. lLR = dict['lLR']
  13. lUD = dict['lUD']
  14. rLR = dict['rLR']
  15. rUD = dict['rUD']
  16. lTrig = dict['lTrig']
  17. rTrig = dict['rTrig']
  18. aBut = dict['aBut']
  19. bBut = dict['bBut']
  20. xBut = dict['xBut']
  21. yBut = dict['yBut']
  22. lBump = dict['lBump']
  23. rBump = dict['rBump']
  24. bkBut = dict['bkBut']
  25. stBut = dict['stBut']
  26. xbBut = dict['xbBut']
  27. ltsBut = dict['ltsBut']
  28. rtsBut = dict['rtsBut']
  29. ldPad = dict['ldPad']
  30. rdPad = dict['rdPad']
  31. udPad = dict['udPad']
  32. ddPad = dict['ddPad']
  33. q1oncd = own["Q1oncd"]
  34. q2oncd = own["Q2oncd"]
  35. q3oncd = own["Q3oncd"]
  36. q4oncd = own["Q4oncd"]
  37. q5oncd = own["Q5oncd"]
  38. q6oncd = own["Q6oncd"]
  39. q7oncd = own["Q7oncd"]
  40. q8oncd = own["Q8oncd"]
  41. q1oncdl = own["Q1oncdl"]
  42. q2oncdl = own["Q2oncdl"]
  43. q3oncdl = own["Q3oncdl"]
  44. q4oncdl = own["Q4oncdl"]
  45. q5oncdl = own["Q5oncdl"]
  46. q6oncdl = own["Q6oncdl"]
  47. q7oncdl = own["Q7oncdl"]
  48. q8oncdl = own["Q8oncdl"]
  49. q1on = 0
  50. q2on = 0
  51. q3on = 0
  52. q4on = 0
  53. q5on = 0
  54. q6on = 0
  55. q7on = 0
  56. q8on = 0
  57. lq1on = 0
  58. lq2on = 0
  59. lq3on = 0
  60. lq4on = 0
  61. lq5on = 0
  62. lq6on = 0
  63. lq7on = 0
  64. lq8on = 0
  65. countdown = 20
  66. ##################
  67. ###realcontrols###
  68. ##################
  69. # q1
  70. # q8 q2
  71. # q7 q3
  72. # q6 q4
  73. # q5
  74. ##################
  75. if lUD > .04 and lLR < -0.04 :
  76. lq6on = 1
  77. q6oncdl = countdown
  78. own["Q6oncdl"] = q6oncdl
  79. #print("lq6on")
  80. elif q6oncdl > 0:
  81. lq6on = 0
  82. q6oncdl = q6oncdl - 1
  83. own["Q6oncdl"] = q6oncdl
  84. #lq8
  85. if lUD < -.04 and lLR < -0.04 :
  86. lq8on = 1
  87. q8oncdl = countdown
  88. own["Q8oncdl"] = q8oncdl
  89. #print("lq8on")
  90. elif q8oncdl > 0:
  91. lq8on = 0
  92. q8oncdl = q8oncdl - 1
  93. own["Q8oncdl"] = q8oncdl
  94. #lq2
  95. if lUD < -.04 and lLR > 0.04 :
  96. lq2on = 1
  97. q2oncdl = countdown
  98. own["Q2oncdl"] = q2oncdl
  99. #print("lq2on")
  100. elif q2oncdl > 0:
  101. lq2on = 0
  102. q2oncdl = q2oncdl - 1
  103. own["Q2oncdl"] = q2oncdl
  104. #q4
  105. if lUD > 0.04 and lLR > 0.04 :
  106. lq4on = 1
  107. q4oncdl = countdown
  108. own["Q4oncdl"] = q4oncdl
  109. #print("lq4on")
  110. elif q4oncdl > 0:
  111. lq4on = 0
  112. q4oncdl = q4oncdl - 1
  113. own["Q4oncdl"] = q4oncdl
  114. #q5
  115. if lUD > .070 and lq4on == 0 and lq6on == 0:
  116. lq5on = 1
  117. q5oncdl = countdown
  118. own["Q5oncdl"] = q5oncdl
  119. #print("lq5on")
  120. elif q5oncdl > 0:
  121. lq5on = 0
  122. q5oncdl = q5oncdl - 1
  123. own["Q5oncdl"] = q5oncdl
  124. #q1
  125. if lUD < -0.070 and lq8on !=1 and lq2on != 1:
  126. lq1on = 1
  127. q1oncdl = countdown
  128. own["Q1oncdl"] = q1oncdl
  129. #print("lq1on")
  130. elif q1oncdl > 0:
  131. lq1on = 0
  132. q1oncdl = q1oncdl - 1
  133. own["Q1oncdl"] = q1oncdl
  134. #q7
  135. if lLR < -0.070 and lq8on != 1 and lq6on != 1:
  136. lq7on = 1
  137. q7oncdl = countdown
  138. own["Q7oncdl"] = q7oncdl
  139. #print("lq7on")
  140. elif q7oncdl > 0:
  141. lq7on = 0
  142. q7oncdl = q7oncdl - 1
  143. own["Q7oncdl"] = q7oncdl
  144. #q3
  145. if lLR > 0.070 and lq2on !=1 and lq4on != 1:
  146. lq3on = 1
  147. q3oncdl = countdown
  148. own["Q3oncdl"] = q3oncdl
  149. #print("lq3on")
  150. elif q3oncdl > 0:
  151. lq3on = 0
  152. q3oncdl = q3oncdl - 1
  153. own["Q3oncdl"] = q3oncdl
  154. ################
  155. #q6
  156. if rUD > .04 and rLR < -0.04 :
  157. q6on = 1
  158. q6oncd = countdown
  159. own["Q6oncd"] = q6oncd
  160. #print("q6on")
  161. elif q6oncd > 0:
  162. q6on = 0
  163. q6oncd = q6oncd - 1
  164. own["Q6oncd"] = q6oncd
  165. #q8
  166. if rUD < -.04 and rLR < -0.04 :
  167. q8on = 1
  168. q8oncd = countdown
  169. own["Q8oncd"] = q8oncd
  170. #print("q8on")
  171. elif q8oncd > 0:
  172. q8on = 0
  173. q8oncd = q8oncd - 1
  174. own["Q8oncd"] = q8oncd
  175. #q2
  176. if rUD < -.04 and rLR > 0.04 :
  177. q2on = 1
  178. q2oncd = countdown
  179. own["Q2oncd"] = q2oncd
  180. #print("q2on")
  181. elif q2oncd > 0:
  182. q2on = 0
  183. q2oncd = q2oncd - 1
  184. own["Q2oncd"] = q2oncd
  185. #q4
  186. if rUD > 0.04 and rLR > 0.04 :
  187. q4on = 1
  188. q4oncd = countdown
  189. own["Q4oncd"] = q4oncd
  190. #print("q4on")
  191. elif q4oncd > 0:
  192. q4on = 0
  193. q4oncd = q4oncd - 1
  194. own["Q4oncd"] = q4oncd
  195. #q5
  196. if rUD > .070 or dict['kb_space'] == 2:
  197. if q4on == 0 and q6on == 0:
  198. q5on = 1
  199. q5oncd = countdown
  200. own["Q5oncd"] = q5oncd
  201. elif q5oncd > 0:
  202. q5on = 0
  203. q5oncd = q5oncd - 1
  204. own["Q5oncd"] = q5oncd
  205. #q1
  206. if rUD < -0.070:
  207. if q2on == 0 and q8on == 0:
  208. #print("q1on")
  209. q1on = 1
  210. q1oncd = countdown
  211. own["Q1oncd"] = q1oncd
  212. elif q1oncd > 0:
  213. q1on = 0
  214. q1oncd = q1oncd - 1
  215. own["Q1oncd"] = q1oncd
  216. #q7
  217. if rLR < -0.070:
  218. if q8on == 0 and q6on == 0:
  219. q7on = 1
  220. q7oncd = countdown
  221. own["Q7oncd"] = q7oncd
  222. elif q7oncd > 0:
  223. q7on = 0
  224. q7oncd = q7oncd - 1
  225. own["Q7oncd"] = q7oncd
  226. #q3
  227. if rLR > 0.070:
  228. if q4on == 0 and q2on == 0:
  229. q3on = 1
  230. q3oncd = countdown
  231. own["Q3oncd"] = q3oncd
  232. elif q3oncd > 0:
  233. q3on = 0
  234. q3oncd = q3oncd - 1
  235. own["Q3oncd"] = q3oncd
  236. if dict['aBut'] == True:
  237. action = 'forward'
  238. if dict['lLR'] > TURN_SENS:
  239. action = 'turnR'
  240. if dict['lLR'] < -TURN_SENS:
  241. action = 'turnL'
  242. if q5oncd > 0 and q1oncd > 0 and q5oncd < q1oncd:
  243. action = 'jump'
  244. return action
  245. def do_physics_action(cont, own, action):
  246. if action == 'turnR':
  247. own.applyRotation([0,0,-TURNAMT], True)
  248. if action == 'turnL':
  249. own.applyRotation([0,0,TURNAMT], True)
  250. if action == 'forward':
  251. own.linearVelocity.x = own.linearVelocity.x - ACCEL_AMT
  252. if action == 'jump':
  253. own.applyForce([0,0,100], False)
  254. print('jump')
  255. gray = cont.sensors['r_Ground']
  256. if gray.positive:
  257. own.alignAxisToVect(Vector(gray.hitNormal)*1, 2, .25)
  258. else:
  259. own.alignAxisToVect(Vector([0,0,1]),2,.25)
  260. own.linearVelocity.y = 0
  261. if gray.positive:
  262. own.linearVelocity.z = own.linearVelocity.z -.05
  263. def do_anims(cont, own):
  264. skater = scene.objects["Char4"]
  265. skater.playAction("reg_bike.001", 20,20, layer=2, play_mode=1, speed=1)
  266. def main(cont):
  267. own = cont.owner
  268. try:
  269. bike = scene.objects['player_bike']
  270. #print('biking')
  271. if dict['yBut'] == True and dict['last_yBut'] == False:
  272. cont.activate(cont.actuators['walk'])
  273. pbike = scene.addObject('prop_bike', own, 0)
  274. pbike.localScale = [4.6, 4.6, 4.6]
  275. pbike.localScale = [1, 1, 1]
  276. pbike.applyRotation([0,0,1.570796], False)
  277. pbike.worldPosition.y = pbike.worldPosition.y - 1.
  278. bike.endObject()
  279. skater.stopAction(9)
  280. action = get_physics_action(cont, own)
  281. do_physics_action(cont, own, action)
  282. do_anims(cont,own)
  283. except:
  284. pass