Shuvit game release repo.
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

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