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 27KB

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