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.

grindV2.py 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. """controls grind physics and sends results to controller2.py for setting the grind animations."""
  2. import bge
  3. import math
  4. def main():
  5. cont = bge.logic.getCurrentController()
  6. own = cont.owner
  7. player = cont.owner
  8. scene = bge.logic.getCurrentScene()
  9. dict = bge.logic.globalDict
  10. grindEmpty = scene.objects['grindEmpty']
  11. grindDar = grindEmpty.sensors['grindDar2']
  12. rGround = cont.sensors['r_Ground']
  13. control_bottom = scene.objects['control_bottom']
  14. grindTouch = control_bottom.sensors['grindCol_bottom']
  15. invertCol = cont.sensors['invertCol']
  16. invertObjs = invertCol.hitObjectList
  17. invert_on = own['invert_on']
  18. detectedObjects = grindDar.hitObjectList
  19. lastObject = own['grindTrackObj']
  20. nearestObject = None
  21. minDist = None
  22. test = own["test"]
  23. grindold = own["grindOld"]
  24. lgobj = own["lGobj"]
  25. countdown = own['grindCountdown']
  26. ray = cont.sensors["gRay"] # get the ray sensor attached to the controller named GuardDuty
  27. gt_cd = own["gt_cd"]
  28. pos = ray.hitPosition # get position where the game object hit by ray
  29. linVelocity = own.getLinearVelocity(False)
  30. linVelocity2 = own.getLinearVelocity(True)
  31. pos[2] = pos[2] + 1
  32. norm = ray.hitNormal
  33. STANCE = own["stance"]
  34. orientation = own.worldOrientation
  35. test = ray.hitObject
  36. xyz = own.worldOrientation.to_euler()
  37. rotz = math.degrees(xyz[2])
  38. roty = math.degrees(xyz[1])
  39. roty = abs(roty)
  40. sub = 0
  41. align_strength = .1#.3
  42. align_strength2 = .2
  43. touched = grindTouch.triggered
  44. lgf = own['last_grind_frame']
  45. gsf = own['grind_start_frame']
  46. framenum = own['framenum']
  47. last_ground_frame = own['lF_ground_frame']
  48. frames_since_ground = framenum - last_ground_frame
  49. frames_since_grind = framenum - lgf
  50. frames_grinding = framenum - gsf
  51. #if framenum - lgf > 60:
  52. minus = framenum - gsf
  53. grindspeed_rail = .996 #multiplied by current speed
  54. grindspeed_cement = .995 #multiplied by current speed
  55. grindDar_timer = own["grindDar_timer"]
  56. last_grindDar = 0
  57. last_manual = own["manual"]
  58. joinit = 0
  59. rot = own.getAxisVect([0.0, 0.0, 1.0])
  60. dropin = own['dropinTimer']
  61. nearestObject = None
  62. last_hit = own['grindDar_hit']
  63. jump_timer = own['jump_timer']
  64. grind_jump = own['grind_jump']
  65. lastGround = own['lF_ground2']
  66. OG_PLAYER_POS = own.worldPosition
  67. grindvect = None
  68. grindyvect = None
  69. skipcol = 0
  70. try:
  71. no_grind_pull = own['no_grind_pull']
  72. except:
  73. own['no_grind_pull'] = 0
  74. no_grind_pull = 0
  75. since_jumped = framenum - own['last_jump_frame']
  76. #no grind
  77. no_grind = 1
  78. if jump_timer > 50:
  79. own['no_grind_timer'] = 0
  80. if own['no_grind_timer'] > 0:
  81. no_grind = 0
  82. own['no_grind_timer'] -= 1
  83. if (own['fak_nmanual'] == 1 or own['reg_nmanual'] == 1 or own['fak_manual'] == 1 or own['reg_manual'] == 1):
  84. manual = 1
  85. else:
  86. manual = 0
  87. own["nogrindsound"] = 0
  88. no_grind = 1
  89. if (framenum - own['last_vert_frame'] < 40) and own['vert'] == 0:
  90. no_grind = 1
  91. #print('no_grind = 1 last vert = ', (framenum - own['last_vert_frame']))
  92. if dict['rBump'] == 1 or (framenum - own['last_vert_frame'] > 40):
  93. no_grind = 0
  94. if own['LAST_GRIND']:
  95. no_grind = 0
  96. if grindold == 1:
  97. no_grind = 0
  98. if dict['lBump'] and dict['rBump']:
  99. no_grind = 1
  100. elif dict['lBump']:
  101. no_grind = 0
  102. #---------###########___###########-----------
  103. #start new #######
  104. ##----------##############----------############
  105. #grindvect func
  106. grindvect = None
  107. grindyvect = None
  108. lastobj = own["grindTouchobj"]
  109. grindpos = own["grindpos"]
  110. player_e = own.worldOrientation.to_euler()
  111. player_rotz = math.degrees(player_e[2])
  112. velxb = linVelocity2.x
  113. player_e = own.worldOrientation.to_euler()
  114. ogrot = own.orientation
  115. ogrot = player_e
  116. #print(touched, 'touched')
  117. if (framenum - gsf) > 15:
  118. velx = linVelocity2.x
  119. vely = linVelocity2.y
  120. #print("limit speed")
  121. else:
  122. velx = linVelocity2.x
  123. vely = linVelocity2.y
  124. if abs(own['pregrind_vely']) > abs(vely) and own['LAST_GRIND'] == 0:
  125. #convely = own['pregrind_vely']
  126. #print('changing convely')
  127. convely = vely
  128. else:
  129. convely = vely
  130. def grindvect(obj):
  131. STANCE = own['stance']
  132. if obj != None:
  133. grinder_e = obj.worldOrientation.to_euler()
  134. grinder_rotz = math.degrees(grinder_e[2])
  135. rot = player_rotz - grinder_rotz
  136. if rot >= 0 and rot < 45:
  137. grindvect = "pos"
  138. if rot >= 45 and rot < 90:
  139. grindvect = "pos"
  140. grindyvect = "pos"
  141. if rot >= 90 and rot < 135:
  142. grindvect = "neg"
  143. grindyvect = "neg"
  144. if rot >= 135 and rot < 180:
  145. grindvect = "neg"
  146. if rot >= 180 and rot < 225:
  147. grindvect = "neg"
  148. if rot >= 225 and rot < 270:
  149. grindvect = "neg"
  150. grindyvect = "pos"
  151. if rot >= 270 and rot < 315:
  152. grindvect = "pos"
  153. grindyvect = "neg"
  154. if rot >= 315:
  155. grindvect = "pos"
  156. if rot < 0 and rot >= -45:
  157. grindvect = "pos"
  158. if rot < -45 and rot >= -90:
  159. grindvect = "pos"
  160. grindyvect = "neg"
  161. if rot < -90 and rot >= -135:
  162. grindvect = "neg"
  163. grindyvect = "pos"
  164. if rot < -135 and rot >= -180:
  165. grindvect = "neg"
  166. if rot < -180 and rot >= -225:
  167. grindvect = "neg"
  168. if rot < -225 and rot >= -270:
  169. grindvect = "neg"
  170. grindyvect = "neg"
  171. if rot < -270 and rot >= -315:
  172. grindvect = "pos"
  173. grindyvect = "pos"
  174. if rot < -315:
  175. grindvect = "pos"
  176. rot = round((rot * .01), 1)
  177. rot *= 100
  178. #print(own['inverting'])
  179. if frames_grinding > 20 and own['inverting'] == False:
  180. #print("setting stance")
  181. if (rot == 90 or rot == -270) and STANCE == True:
  182. #print("90 fak stance")
  183. own['stance'] = 1
  184. STANCE = 1
  185. if (rot == 90 or rot == -270) and STANCE == False:
  186. #print("90 fak stance")
  187. own['stance'] = 1
  188. STANCE = 1
  189. if (rot == -90 or rot == 270) and STANCE == True:
  190. #print("-90 reg stance")
  191. own['stance'] = 0
  192. STANCE = 0
  193. if (rot == -90 or rot == 270) and STANCE == False:
  194. #print("-90 reg stance")
  195. own['stance'] = 0
  196. STANCE = 0
  197. def grindrotvel(obj):
  198. joinit = 0
  199. grinder_e = obj.worldOrientation.to_euler()
  200. grinder_rotz = math.degrees(grinder_e[2])
  201. grinder_vect = obj.getAxisVect([1, 0, 0])
  202. grinder_vectz = obj.getAxisVect([0, 0, 1])
  203. rot = player_rotz - grinder_rotz
  204. rayhit = ray.hitObject
  205. own['grind_rot'] = rot
  206. vect = obj.getAxisVect([1.0, 0.0, 0.0])
  207. xyzb = obj.worldOrientation.to_euler()
  208. rotzb = math.degrees(xyzb[2])
  209. grindpos = "None"
  210. align = "None"
  211. sub_converted = 0
  212. rotz = math.degrees(xyz[2])
  213. roty = math.degrees(xyz[1])
  214. bsrot = [0.0, 0.0, 1.570796327]
  215. negbsrot = [0.0, 0.0, -1.570796327]
  216. zvel = own.linearVelocity
  217. zvel = zvel.z * .95
  218. if grindold == 0:
  219. if rotz < 0:
  220. rotz = rotz + 360
  221. if rotzb < 0:
  222. rotzb = rotzb + 360
  223. if rotz > rotzb:
  224. sub_converted = rotz - rotzb
  225. if rotz < rotzb:
  226. sub_converted = rotzb - rotz
  227. #z align
  228. stre = .15#.075#.15
  229. player.alignAxisToVect(grinder_vectz, 2, stre)
  230. if rot >= 0 and rot < 45:
  231. player.alignAxisToVect(grinder_vect, 0, align_strength)
  232. grindvect = "pos"
  233. #player.applyForce([0, 0, 0], True)
  234. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  235. grindpos = "reg_5050"
  236. #print("50-1")
  237. elif rot >= 45 and rot < 90:
  238. player.alignAxisToVect([-grinder_vect.y, grinder_vect.x, 0], 0, align_strength)
  239. grindvect = "pos"
  240. align = "pos"
  241. player.setLinearVelocity([0, convely, zvel], 1)
  242. grindpos = "reg_board"
  243. grindyvect = "pos"
  244. elif rot >= 90 and rot < 135:
  245. grinder_vect = grinder_vect * -1
  246. player.alignAxisToVect([grinder_vect.y, -grinder_vect.x, 0], 0, align_strength)
  247. grindvect = "neg"
  248. align = "neg"
  249. grindyvect = "neg"
  250. player.setLinearVelocity([0, convely, zvel], 1)
  251. grindpos = "reg_board"
  252. #print("-bs2, don't switch?")
  253. elif rot >= 135 and rot < 180:
  254. player.alignAxisToVect(-grinder_vect, 0, align_strength)
  255. grindvect = "neg"
  256. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  257. grindpos = "reg_5050"
  258. #print("50-2")
  259. elif rot >= 180 and rot < 225:
  260. player.alignAxisToVect(-grinder_vect, 0, align_strength)
  261. grindvect = "neg"
  262. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  263. grindpos = "reg_5050"
  264. #print("50-3")
  265. elif rot >= 225 and rot < 270:
  266. player.alignAxisToVect([grinder_vect.y, -grinder_vect.x, 0], 0, align_strength)
  267. grindvect = "neg"
  268. align = "pos"
  269. player.setLinearVelocity([0, convely, zvel], 1)
  270. grindpos = "reg_board"
  271. grindyvect = "pos"
  272. #print("bs3")
  273. elif rot >= 270 and rot < 315:
  274. player.alignAxisToVect([grinder_vect.y, -grinder_vect.x, 0], 0, align_strength)
  275. grindvect = "pos"
  276. align = "neg"
  277. player.setLinearVelocity([0, convely, zvel], 1)
  278. grindpos = "reg_board"
  279. grindyvect = "neg"
  280. #print("-bs4")
  281. elif rot >= 315:
  282. player.alignAxisToVect(grinder_vect, 0, align_strength)
  283. grindvect = "pos"
  284. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  285. grindpos = "reg_5050"
  286. #print("50-4")
  287. #-------------------------------------------------------------
  288. elif rot < 0 and rot >= -45:
  289. player.alignAxisToVect(grinder_vect, 0, align_strength)
  290. grindvect = "pos"
  291. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  292. grindpos = "reg_5050"
  293. #print("50-5")
  294. elif rot < -45 and rot >= -90:
  295. grinder_vect = grinder_vect * -1
  296. player.alignAxisToVect([-grinder_vect.y, grinder_vect.x, 0], 0, align_strength)
  297. grindvect = "pos"
  298. align = "neg"
  299. player.setLinearVelocity([0, convely, zvel], 1)
  300. grindpos = "reg_board"
  301. #print("-bs5")
  302. grindyvect = "neg"
  303. elif rot < -90 and rot >= -135:
  304. player.alignAxisToVect([grinder_vect.y, -grinder_vect.x, 0], 0, align_strength)
  305. grindvect = "neg"
  306. align = "pos"
  307. player.setLinearVelocity([0, convely, zvel], 1)
  308. grindpos = "reg_board"
  309. grindyvect = "pos"
  310. #print("bs6")
  311. elif rot < -135 and rot >= -180:
  312. player.alignAxisToVect(-grinder_vect, 0, align_strength)
  313. grindvect = "neg"
  314. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  315. grindpos = "reg_5050"
  316. #print("50-6")
  317. elif rot < -180 and rot >= -225:
  318. player.alignAxisToVect(-grinder_vect, 0, align_strength)
  319. grindvect = "neg"
  320. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  321. grindpos = "reg_5050"
  322. #print("50-7")
  323. elif rot < -225 and rot >= -270:
  324. grinder_vect = grinder_vect * -1
  325. player.alignAxisToVect([grinder_vect.y, -grinder_vect.x, 0], 0, align_strength)
  326. grindvect = "neg"
  327. align = "neg"
  328. player.setLinearVelocity([0, convely, zvel], 1)
  329. grindpos = "reg_board"
  330. grindyvect = "neg"
  331. #print("-bs7")
  332. elif rot < -270 and rot >= -315:
  333. player.alignAxisToVect([-grinder_vect.y, grinder_vect.x, 0], 0, align_strength)
  334. grindvect = "pos"
  335. align = "pos"
  336. player.setLinearVelocity([0, convely, zvel], 1)
  337. grindpos = "reg_board"
  338. grindyvect = "pos"
  339. #print("bs8")
  340. elif rot < -315:
  341. player.alignAxisToVect(grinder_vect, 0, align_strength)
  342. grindvect = "pos"
  343. player.setLinearVelocity([velxb, 0.0, zvel], 1)
  344. grindpos = "reg_5050"
  345. #print("50-8")
  346. own['grindpos'] = grindpos
  347. own['grindvect'] = grindvect
  348. own['grindervect'] = grinder_vect
  349. try:
  350. own['grindyvect'] = grindyvect
  351. except:
  352. pass
  353. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  354. def grind(obj):
  355. try:
  356. grindyvect = own['grindyvect']
  357. except:
  358. grindyvect = 0
  359. grindvect = own['grindvect']
  360. if 'rail' in obj:
  361. own["grindSound"] = "rail"
  362. else:
  363. own["grindSound"] = "concrete"
  364. own['lGobj'] = obj
  365. grinding = 1
  366. framenum = own['framenum']
  367. lastairframe = own['lF_air_frame']
  368. jumpside = 0
  369. if (framenum - lastairframe) < 10:
  370. player_pos = own['jumpPos']
  371. jumpside = 1
  372. else:
  373. player_pos = OG_PLAYER_POS
  374. player_pos = own.worldPosition
  375. try:
  376. if 1 == 1:
  377. grinder_pos = obj.worldPosition
  378. worldVect = [1, 0, 0]
  379. vect = obj.getAxisVect(worldVect)
  380. grinder_axis = [0, 1, 0]
  381. try:
  382. delta = player_pos - grinder_pos
  383. except:
  384. pass
  385. delta = delta.cross(vect)
  386. if delta[2] >= 0:
  387. grindside = "right"
  388. else:
  389. grindside = "left"
  390. edge = 0
  391. if 'edge' in obj:
  392. edge = 1
  393. #print('grind on', grindside, edge)
  394. if (delta[2] > .00001 or delta[2] < -.00001) and (delta[2] < .8 or delta[2] < -.8):
  395. rotation = own.worldOrientation[2] - obj.worldOrientation[2]
  396. player_e = own.worldOrientation.to_euler()
  397. player_rotz = math.degrees(player_e[2])
  398. grinder_e = obj.worldOrientation.to_euler()
  399. grinder_rotz = math.degrees(grinder_e[2])
  400. deltamove = delta[2] * .3
  401. #5050
  402. if own["grindpos"] == "reg_5050":
  403. #print("missing delta")
  404. if (jumpside == 1 or jumpside == 0) and grindvect == "pos":
  405. move = [0, deltamove, 0]
  406. #print("1deltamove", deltamove)
  407. own.applyMovement(move, True)
  408. if (jumpside == 1 or jumpside == 0) and grindvect == "neg":
  409. move = [0, -deltamove, 0]
  410. #print("2deltamove -", deltamove)
  411. own.applyMovement(move, True)
  412. #board
  413. if own["grindpos"] == "reg_board":
  414. if grindvect == "neg":
  415. if (jumpside == 1 or jumpside == 0) and grindyvect == "pos":
  416. move = [-deltamove, 0, 0]
  417. #print("3deltamove", deltamove)
  418. own.applyMovement(move, True)
  419. if (jumpside == 1 or jumpside == 0) and grindyvect == "neg":
  420. move = [deltamove, 0, 0]
  421. #print("4deltamove -", deltamove)
  422. own.applyMovement(move, True)
  423. if grindvect == "pos":
  424. if (jumpside == 1 or jumpside == 0) and grindyvect == "pos":
  425. move = [deltamove, 0, 0]
  426. #print("5deltamove", deltamove)
  427. own.applyMovement(move, True)
  428. if (jumpside == 1 or jumpside == 0) and grindyvect == "neg":
  429. move = [-deltamove, 0, 0]
  430. own.applyMovement(move, True)
  431. own['grindside'] = grindside
  432. except:
  433. print('something in grinding is wrong')
  434. #pass
  435. #speed limit
  436. velo = own.getLinearVelocity(True)
  437. touchobj = obj
  438. if touchobj != None and gt_cd == 0:
  439. if 'rail' in touchobj:
  440. newvelx = velo.x * grindspeed_rail
  441. newvely = velo.y * grindspeed_rail
  442. else:
  443. newvelx = velo.x * grindspeed_cement
  444. newvely = velo.y * grindspeed_cement
  445. player.setLinearVelocity([newvelx, newvely, velo.z], 1)
  446. player_rot = own.worldOrientation[2]
  447. grinder_rot = touchobj.worldOrientation[2]
  448. player_rot = own.getAxisVect([0.0, 0.0, 1.0])
  449. xyz3 = own.worldOrientation.to_euler()
  450. player_rot = math.degrees(xyz3[2])
  451. xyz4 = touchobj.worldOrientation.to_euler()
  452. grinder_rot = math.degrees(xyz4[2])
  453. if player_rot < 0:
  454. player_rot = abs(player_rot) + 180
  455. if grinder_rot < 0:
  456. grinder_rot = abs(grinder_rot) + 180
  457. subtraction = player_rot - grinder_rot
  458. def invertpos(detectedObjects):
  459. minDist = None
  460. nearestObject = None
  461. for obj in detectedObjects:
  462. dist = own.getDistanceTo(obj)
  463. if (minDist is None or dist < minDist):
  464. nearestObject = obj
  465. minDist = dist
  466. if nearestObject != None:
  467. own.linearVelocity.x = 0
  468. own.linearVelocity.y = 0
  469. if grindDar.positive == False and grindTouch.triggered and grindold == 0 and dropin == 0 and grind_jump == 0 and own["grindoutturn"] == 0 and gt_cd == 0 and manual == 0 and no_grind == 0 and nearestObject != lastObject and own['grindjumpturn'] == 0 and own['gt_cd2'] == 0 and own['air_mover'] == False:
  470. #print("touching, no dar")
  471. pass
  472. #print(grindold, "grindold")
  473. skipper = 0
  474. if (grindDar.positive or grindTouch.positive) and no_grind == 0:
  475. if grindDar.positive:
  476. detectedObjects = grindDar.hitObjectList
  477. dist = 0.0
  478. for obj in detectedObjects:
  479. dist = own.getDistanceTo(obj)
  480. if (minDist is None or dist < minDist):
  481. nearestObject = obj
  482. minDist = dist
  483. elif grindTouch.positive:
  484. nearestObject = grindTouch.hitObject
  485. dist = .7
  486. #print('using touch object')
  487. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  488. #init grind
  489. if invert_on:
  490. invertpos(detectedObjects)
  491. own['inverting'] = True
  492. print('calling invert funct')
  493. else:
  494. own['inverting'] = False
  495. grind_dist = .8#.6
  496. skipper = 0
  497. #print(lastobj.worldPosition)
  498. if dist < grind_dist and dropin == 0 and manual == 0 and no_grind == 0 and own['grindoutturn'] == 0 and own['manual'] == 0 and own['gt_cd2'] < 40 and invert_on == False and own['air_mover'] == False and no_grind_pull == 0 and own['last_invert'] == False and own['grindjumpturn'] == 0 and grind_jump == 0 and (own['airup'] == 0 or dict['rBump'] == 1 or dict['lBump'] == 1):
  499. #print("grinding")
  500. grind_height_dif = (own.worldPosition[2] - nearestObject.worldPosition[2]) - .287
  501. if grind_height_dif > -.05:#02:
  502. if own['grinder_rot'] != None:
  503. grot = nearestObject.getAxisVect([1, 0.0, 0.0]).x
  504. dif = (grot - own['grinder_rot'])
  505. if dif > .8 or dif < - .8:
  506. print('skipping grind, angle is', dif)
  507. skipper = 1
  508. own['grinder_rot'] = nearestObject.getAxisVect([1, 0, 0]).x
  509. if skipper != 1:
  510. grindvect(nearestObject)
  511. grindrotvel(nearestObject)
  512. grind(nearestObject)
  513. grindold = True
  514. own['grindold_timer'] = 0
  515. own["grindHit"] = True
  516. own['grindnew_timer'] += 1
  517. if own['grindnew_timer'] < 1:
  518. if grindTouch.triggered:
  519. nearpos = nearestObject.worldPosition
  520. if hitNormal != None:
  521. stre = .15
  522. own.alignAxisToVect(hitNormal, 2, stre)
  523. else:
  524. own['grindold_timer'] += 1
  525. own["grindHit"] = False
  526. own['inverting'] = False
  527. if own['grindold_timer'] > 5:
  528. grindold = False
  529. own['grind_start_frame'] = framenum
  530. own["grindSound"] = None
  531. if own['grindHit'] == False:
  532. own['grindnew_timer'] = 0
  533. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  534. #if you are touching grinder and last_manual is off keep manual off
  535. if (own['fak_nmanual'] == 1 or own['reg_nmanual'] == 1 or own['fak_manual'] == 1 or own['reg_manual'] == 1) and lastGround == True and grindold == False:
  536. manual = 1
  537. if last_manual == 0 and grindTouch.triggered == True:
  538. manual = 0
  539. own["nogrindsound"] = 1
  540. grindhit = own["grindHit"]
  541. if abs(own['pregrind_vely']) > abs(vely) and own['LAST_GRIND'] == 0:
  542. convely = own['pregrind_vely']
  543. else:
  544. convely = vely
  545. off = 0
  546. if touched == True:
  547. own["grindTouchobj"] = grindTouch.hitObject
  548. else:
  549. own["grindTouchobj"] = None
  550. if ray.triggered and dropin == 0:
  551. lgobj = ray.hitObject
  552. own['lGobj'] = lgobj
  553. obj = ray.hitObject
  554. linVelocity3 = own.getLinearVelocity(True)
  555. grindpos2 = own["grindpos"]
  556. if obj is not None:
  557. if 'rail' in ray.hitObject:
  558. own["grindSound"] = "rail"
  559. else:
  560. own["grindSound"] = "concrete"
  561. own['lGobj'] = lgobj
  562. else:
  563. lgobj = "empty"
  564. own['lGobj'] = lgobj
  565. def timer():
  566. countdown = own["grindCountdown"]
  567. if touched == 1:
  568. countdown = 20
  569. else:
  570. countdown = countdown - 1
  571. own['grindCountdown'] = countdown
  572. def aligntimer():
  573. if own['grindOld'] == 0 and ray.triggered == 1:
  574. own['aligntimer'] = 20
  575. if own['grindOld'] == 1 and ray.triggered == 1:
  576. own['aligntimer'] = own['aligntimer'] - 1
  577. if own['grindOld'] == 0 and ray.triggered == 0:
  578. own['aligntimer'] = 0
  579. def invertpos(xyz):
  580. minDist = None
  581. nearestObject = None
  582. print('doing invert funct')
  583. for obj in invertObjs:
  584. dist = own.getDistanceTo(obj)
  585. if (minDist is None or dist < minDist):
  586. nearestObject = obj
  587. minDist = dist
  588. vect = nearestObject.getAxisVect([1.0, 0.0, 0.0])
  589. own.worldPosition = [nearestObject.worldPosition.x, nearestObject.worldPosition.y, nearestObject.worldPosition.z +.1]
  590. def set_pregrind_vel():
  591. if grindDar.triggered == False and ray.triggered == False:
  592. own['pregrind_velx'] = linVelocity2.x
  593. own['pregrind_vely'] = linVelocity2.y
  594. own['pregrind_velz'] = linVelocity2.z
  595. def stop_bounce():
  596. if grindTouch.triggered and no_grind == 0 and grind_jump == 0 and jump_timer < 30:
  597. linVelocity4 = own.getLinearVelocity(True)
  598. if linVelocity4.z > 0:
  599. own.setLinearVelocity([linVelocity4.x, linVelocity4.y, 0], 1)
  600. if jump_timer < 30:
  601. own['grind_jump'] = 0
  602. if grindold == False and ray.triggered:
  603. own['grind_start_frame'] = own['framenum']
  604. if grindDar_timer > 0:
  605. grindDar_timer -= 1
  606. if ray.triggered == False and touched == True and own['footplant_on'] == False and manual == 0 and own['gt_cd2'] < 55 and own['grindoutturn'] == 0 and own['grindjumpturn'] == 0:
  607. obj = grindTouch.hitObject
  608. try:
  609. nearpos = obj.worldPosition
  610. except:
  611. pass
  612. def slow_roty():
  613. constraint = cont.actuators['gConstraint']
  614. if (own['framenum'] - own['grind_start_frame'] < 40) and touched == 1:
  615. cont.activate(constraint)
  616. else:
  617. cont.deactivate(constraint)
  618. timer()
  619. aligntimer()
  620. stop_bounce()
  621. #slow_roty()
  622. own['grindOld'] = grindold
  623. own['test'] = test
  624. own['grindTrackObj'] = nearestObject
  625. own['grindDar_hit'] = grindDar.positive
  626. own['lastTouched'] = touched
  627. own['grindTouch'] = grindTouch.triggered
  628. own["grindDar_timer"] = grindDar_timer
  629. own["last_grindDar"] = last_grindDar
  630. own['last_roty'] = roty
  631. linVelocity3 = own.getLinearVelocity(True)
  632. set_pregrind_vel()
  633. own['last_z'] = own.worldPosition.z
  634. own["manual"] = manual