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

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