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

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