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.

walk.py 42KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. #shuvit.org
  2. #walk.py
  3. import bge
  4. import GameLogic
  5. import ctypes
  6. import random
  7. import math
  8. scene = bge.logic.getCurrentScene()
  9. objList = scene.objects
  10. cont = GameLogic.getCurrentController()
  11. obj = bge.logic.getCurrentScene().objects
  12. char = bge.constraints.getCharacter
  13. own = cont.owner
  14. stance = own['stance']
  15. STANCE = own['stance']
  16. r_ground = cont.sensors["r_Ground"]
  17. linvel = own.getLinearVelocity(True)
  18. lasta = own['lasta']
  19. lastx = own['lastx']
  20. last_sit = own['sit']
  21. dict = bge.logic.globalDict
  22. try:
  23. own['walk_timer'] = own['walk_timer'] +1
  24. except:
  25. own['walk_timer'] = 1
  26. truckon = 450
  27. deckon = 460
  28. lLR = dict['lLR']
  29. lUD = dict['lUD']
  30. rLR = dict['rLR']
  31. rUD = dict['rUD']
  32. lTrig = dict['lTrig']
  33. rTrig = dict['rTrig']
  34. aBut = dict['aBut']
  35. bBut = dict['bBut']
  36. xBut = dict['xBut']
  37. yBut = dict['yBut']
  38. lBump = dict['lBump']
  39. rBump = dict['rBump']
  40. bkBut = dict['bkBut']
  41. stBut = dict['stBut']
  42. xbBut = dict['xbBut']
  43. ltsBut = dict['ltsBut']
  44. rtsBut = dict['rtsBut']
  45. ldPad = dict['ldPad']
  46. rdPad = dict['rdPad']
  47. udPad = dict['udPad']
  48. ddPad = dict['ddPad']
  49. #user
  50. sens = .04
  51. fliplay = 30
  52. dropinCol = own.sensors['dropinCol']
  53. skater = scene.objects["Char4"]
  54. deck = scene.objects["deck"]
  55. trucks = scene.objects["trucks"]
  56. throw_deck_empty = scene.objects["throw_deck_empty"]
  57. wheel1 = scene.objects["rollen.000"]
  58. wheel2 = scene.objects["rollen.001"]
  59. wheel3 = scene.objects["rollen.002"]
  60. wheel4 = scene.objects["rollen.003"]
  61. camobj = scene.objects["Camera.003"]
  62. camera = cont.actuators["Camera"]
  63. replayCam = cont.actuators["replayCam"]
  64. timer = own['dropinTimer']
  65. cam = scene.objects["Camera.003"]
  66. freecam = scene.objects["freecam"]
  67. followcam = scene.objects["followcam"]
  68. control_bottom = scene.objects['control_bottom']
  69. cb = control_bottom.sensors['grindCol_bottom']
  70. cb_td = control_bottom.sensors['td_bottom']
  71. noidle = 0
  72. if skater.isPlayingAction(460):
  73. noidle = 1
  74. if own["stance"] == None:
  75. own["stance"] = True
  76. STANCE = own["stance"]
  77. def killact(layer):
  78. if skater.isPlayingAction(layer):
  79. skater.stopAction(layer)
  80. if deck.isPlayingAction(layer):
  81. deck.stopAction(layer)
  82. if trucks.isPlayingAction(layer):
  83. trucks.stopAction(layer)
  84. def killall():
  85. for x in range(5000):
  86. skater.stopAction(x)
  87. deck.stopAction(x)
  88. trucks.stopAction(x)
  89. def trucksisplaying():
  90. for x in range(5000):
  91. if deck.isPlayingAction(x):
  92. print("deck is playing:", x)
  93. def printplaying():
  94. splaying_layers = "S: "
  95. playing_layers = "D: "
  96. tplaying_layers = "T: "
  97. for x in range(9900):
  98. if skater.isPlayingAction(x):
  99. #if trucks.isPlayingAction(x):
  100. #if skater.isPlayingAction(x):
  101. splaying_layers += str(x)
  102. splaying_layers += " "
  103. if deck.isPlayingAction(x):
  104. #if trucks.isPlayingAction(x):
  105. #if skater.isPlayingAction(x):
  106. playing_layers += str(x)
  107. playing_layers += " "
  108. if trucks.isPlayingAction(x):
  109. #if trucks.isPlayingAction(x):
  110. #if skater.isPlayingAction(x):
  111. tplaying_layers += str(x)
  112. tplaying_layers += " "
  113. print(splaying_layers, playing_layers, tplaying_layers)
  114. #printplaying()
  115. ##
  116. if r_ground.positive and xBut == False and lastx == False:
  117. killact(10)
  118. #killact(11)
  119. killact(12)
  120. killact(13)
  121. ######################################
  122. #idle
  123. if stance == 0 and skater.isPlayingAction(fliplay) == False and yBut == False and r_ground.triggered and xBut == False and noidle == 0 and own['walk_idling'] == 0 and own['sit'] == 0 and own['dropinTimer'] == 0 and own['lasty'] == False:
  124. own['requestAction'] = 'reg_idle'
  125. if own['throw_deck'] == True:
  126. own['requestAction'] = 'reg_idle_nb'
  127. if stance == 1 and skater.isPlayingAction(fliplay) == False and yBut == False and r_ground.triggered and xBut == False and noidle == 0 and own['walk_idling'] == 0 and own['sit'] == 0 and own['dropinTimer'] == 0 and own['lasty'] == False:
  128. own['requestAction'] = 'fak_idle'
  129. if own['throw_deck'] == True:
  130. own['requestAction'] = 'fak_idle_nb'
  131. if lUD < -sens:
  132. lup = 1
  133. else:
  134. lup = 0
  135. if lUD > sens:
  136. ldown = 1
  137. else:
  138. ldown = 0
  139. if lLR < -sens:
  140. lLeft = 1
  141. else:
  142. lLeft = 0
  143. if lLR > sens:
  144. lRight = 1
  145. else:
  146. lRight = 0
  147. #walking
  148. #new walking
  149. vel = own.getLinearVelocity(True)
  150. if own['walk_timer'] < 50:
  151. velx = vel.x * .95
  152. own.setLinearVelocity([velx, 0, vel.z], True)
  153. else:
  154. own.setLinearVelocity([0, 0, vel.z], True)
  155. wf = 1
  156. if own['last_walk_frame'] - own['last_roll_frame'] > 55:
  157. wf = 0
  158. if ((lup == 1 and aBut == 0) or (dict['kb_ua'] == 2 and dict['kb_lsh'] == 0)) and (r_ground.positive or own['stair_counter'] > 0) and xBut == 0 and wf == 0 and dict['kb_space'] == 0:
  159. own['walking'] = "regular"
  160. walking = "regular"
  161. elif ((lup == 1 and aBut == 1) or (dict['kb_lsh'] == 2 and dict['kb_ua'] == 2)) and yBut == False and (r_ground.positive or own['stair_counter'] > 0) and xBut == 0 and wf == 0 and dict['kb_space'] != 2:
  162. own['walking'] = "fast"
  163. walking = "fast"
  164. else:
  165. own['walking'] = None
  166. walking = None
  167. if walking == "regular":
  168. cont.deactivate(own.actuators['forward2'])
  169. cont.deactivate(own.actuators['backward2'])
  170. if stance == 0:
  171. cont.activate(own.actuators['forward'])
  172. else:
  173. cont.activate(own.actuators['backward'])
  174. if walking == "fast":
  175. cont.deactivate(own.actuators['forward'])
  176. cont.deactivate(own.actuators['backward'])
  177. if stance == 0:
  178. cont.activate(own.actuators['forward2'])
  179. else:
  180. cont.activate(own.actuators['backward2'])
  181. if walking == None:
  182. cont.deactivate(own.actuators['forward2'])
  183. cont.deactivate(own.actuators['backward2'])
  184. cont.deactivate(own.actuators['forward'])
  185. cont.deactivate(own.actuators['backward'])
  186. if own['walk_timer'] < 50:
  187. velx = vel.x * .95
  188. own.setLinearVelocity([velx, 0, vel.z], True)
  189. else:
  190. own.setLinearVelocity([0, 0, vel.z], True)
  191. #old walking
  192. if (lup == 1 and aBut == 0) or (dict['kb_ua'] == 2 and dict['kb_lsh'] == 0) and yBut == False and (r_ground.positive or own['stair_counter'] > 0) and xBut == 0:
  193. own.actuators["walkondirt"].volume = .2
  194. own.actuators["walkondirt"].pitch = 1
  195. cont.activate(own.actuators["walkondirt"])
  196. if stance == 0 and skater.isPlayingAction(fliplay) == False:
  197. #without deck
  198. if own['throw_deck'] == True:
  199. own['requestAction'] = 'reg_walk_nb'
  200. else:
  201. own['requestAction'] = 'reg_walk'
  202. if stance == 1 and skater.isPlayingAction(fliplay) == False:
  203. #without deck
  204. if own['throw_deck'] == True:
  205. own['requestAction'] = 'fak_walk_nb'
  206. else:
  207. own['requestAction'] = 'fak_walk'
  208. elif ((lup == 1 and aBut == 1) or (dict['kb_lsh'] == 2 and dict['kb_ua'] == 2)) and yBut == False and (r_ground.positive or own['stair_counter'] > 0) and xBut == 0:
  209. own.actuators["walkondirt"].volume = .2
  210. own.actuators["walkondirt"].pitch = 1.3
  211. cont.activate(own.actuators["walkondirt"])
  212. if stance == 0 and skater.isPlayingAction(fliplay) == False:
  213. if own['throw_deck'] == True:
  214. own['requestAction'] = 'reg_walkFast_nb'
  215. else:
  216. own['requestAction'] = 'reg_walkFast'
  217. if stance == 1 and skater.isPlayingAction(fliplay) == False:
  218. if own['throw_deck'] == True:
  219. own['requestAction'] = 'fak_walkFast_nb'
  220. else:
  221. own['requestAction'] = 'fak_walkFast'
  222. else:
  223. vel = own.getLinearVelocity(True)
  224. cont.deactivate(own.actuators["walkondirt"])
  225. #turning
  226. if lRight == 1 or dict['kb_ra'] == 2:
  227. cont.activate(own.actuators['right'])
  228. else:
  229. cont.deactivate(own.actuators['right'])
  230. if lLeft == 1 or dict['kb_la'] == 2:
  231. cont.activate(own.actuators['left'])
  232. else:
  233. cont.deactivate(own.actuators['left'])
  234. #in air
  235. if (lup == 1 or dict['kb_ua'] != 0) and r_ground.positive == False:
  236. if stance == 0:
  237. cont.deactivate(own.actuators['forward'])
  238. cont.deactivate(own.actuators['forward2'])
  239. killact(4)
  240. killact(5)
  241. killact(6)
  242. killact(7)
  243. velx = linvel.x - 1
  244. own.setLinearVelocity([-1.5, linvel.y, linvel.z], 1)
  245. if stance == 1:
  246. cont.deactivate(own.actuators['backward'])
  247. cont.deactivate(own.actuators['backward2'])
  248. killact(4)
  249. killact(5)
  250. killact(6)
  251. killact(7)
  252. velx = linvel.x + 1
  253. own.setLinearVelocity([1.5, linvel.y, linvel.z], 1)
  254. own['lF_air_frame'] = own['framenum']
  255. #---------------
  256. if rLR > .05:
  257. cont.activate(camobj.actuators['camRight'])
  258. else:
  259. cont.deactivate(camobj.actuators['camRight'])
  260. if rLR < -.05:
  261. cont.activate(camobj.actuators['camLeft'])
  262. else:
  263. cont.deactivate(camobj.actuators['camLeft'])
  264. if rUD > .05:
  265. cont.activate(camobj.actuators['camDown'])
  266. else:
  267. cont.deactivate(camobj.actuators['camDown'])
  268. if rUD < -.05:
  269. cont.activate(camobj.actuators['camUp'])
  270. else:
  271. cont.deactivate(camobj.actuators['camUp'])
  272. #----------------
  273. camera.height = .9 #-.4
  274. camera.min = 1.5
  275. camera.max = 2
  276. lasty = own['lasty']
  277. def onboard():
  278. if own['walk'] == 0:
  279. print("start walking")
  280. own['walk_idling'] = 0
  281. if own['framenum'] > 100 and own['fall'] == False:
  282. cont.activate(own.actuators['pop'])
  283. own['getoffboard'] = False
  284. fliplay = 301
  285. fliplay2 = 302
  286. fliplay3 = 303
  287. own['grindcement_vol'] = 0
  288. own['grindcement_pitch'] = 0
  289. own['grindrail_vol'] = 0
  290. own['grindrail_pitch'] = 0
  291. own['sroll_vol'] = 0
  292. own['sroll_pitch'] = 0
  293. try:
  294. vel = own['offboard_vel']
  295. vel = [velx, vel.y, vel.z]
  296. except:
  297. pass
  298. if STANCE == 0:
  299. skater.stopAction(fliplay)
  300. deck.stopAction(deckon)
  301. trucks.stopAction(truckon)
  302. own['requestAction'] = 'reg_offboard'
  303. if STANCE == 1:
  304. skater.stopAction(fliplay)
  305. deck.stopAction(deckon)
  306. trucks.stopAction(truckon)
  307. own['requestAction'] = 'fak_offboard'
  308. def jump():
  309. #limit fall speed
  310. if linvel.z < -10:
  311. own.linearVelocity.z = -10
  312. if xBut == True or dict['kb_space'] == 1:
  313. if own['lastx'] == 0:
  314. killact(3)
  315. killact(4)
  316. killact(5)
  317. killact(6)
  318. killact(7)
  319. if STANCE == 0:
  320. own['requestAction'] ='reg_jump'
  321. print('jump')
  322. if STANCE == 1:
  323. own['requestAction'] ='fak_jump'
  324. print('jump')
  325. JUMPHEIGHT = 1100
  326. force = [ 0.0, 0.0, JUMPHEIGHT]
  327. # use local axis
  328. local = False
  329. # apply force -- limit jump speed
  330. if linvel.z < 10:
  331. own.applyForce(force, local)
  332. own['lastx'] = 1
  333. else:
  334. own['lastx'] = 0
  335. def dropin():
  336. if dropinCol.positive == True:
  337. pass
  338. def getonboard():
  339. #print(dict['kb_q'])
  340. getonboard = own['getonboard']
  341. fliplay2 = 50#8560
  342. if (yBut == True or dict['kb_q'] == 2) and cont.sensors["carNear"].positive == False:
  343. fliplay3 = fliplay2 + 1
  344. if dropinCol.positive == True:
  345. nearestObject = None
  346. grindEmpty = scene.objects['grindEmpty']
  347. grindDar = grindEmpty.sensors['grindDar2']
  348. minDist = None
  349. if grindDar.positive:
  350. detectedObjects = grindDar.hitObjectList
  351. dist = 0
  352. for obj in detectedObjects:
  353. dist = own.getDistanceTo(obj)
  354. if (minDist is None or dist < minDist):
  355. nearestObject = obj
  356. minDist = dist
  357. if nearestObject != None:
  358. print(nearestObject)
  359. obj = nearestObject
  360. player_e = own.worldOrientation.to_euler()
  361. player_pos = own.worldPosition
  362. player_rotz = math.degrees(player_e[2])
  363. grinder_e = obj.worldOrientation.to_euler()
  364. grinder_rotz = math.degrees(grinder_e[2])
  365. rot = player_rotz - grinder_rotz
  366. grinder_pos = obj.worldPosition
  367. worldVect = [1, 0, 0]
  368. vect = obj.getAxisVect(worldVect)
  369. go = obj.worldOrientation
  370. grinder_axis = [1,0,0]
  371. try:
  372. delta = player_pos - grinder_pos
  373. delta = delta.cross(vect)
  374. if delta[2] >= 0:
  375. grindside = "right"
  376. else:
  377. grindside = "left"
  378. deltamove = delta[2] * .1#.25
  379. if STANCE == 0:
  380. move = [-deltamove, 0, 0]
  381. else:
  382. move = [deltamove, 0, 0]
  383. own.applyMovement(move, True)
  384. except:
  385. pass
  386. if STANCE == 0:
  387. own['requestAction'] ='reg_dropin_pos'
  388. own['dropinTimer'] = 60
  389. if STANCE == 1:
  390. own['requestAction'] ='fak_dropin_pos'
  391. own['dropinTimer'] = 60
  392. if getonboard == 1:
  393. fliplay3 = 6000
  394. onboard_speed = .1
  395. own['getonboard'] = 0
  396. own['walk_idling'] = 0
  397. if (yBut == False and lasty == True) or (yBut == True or dict['kb_q'] == 2) and dropinCol.positive:
  398. deckact = deck.actuators["Visibility"]
  399. trucksact = trucks.actuators["Visibility"]
  400. wheel1act = wheel1.actuators["Visibility"]
  401. wheel2act = wheel2.actuators["Visibility"]
  402. wheel3act = wheel3.actuators["Visibility"]
  403. wheel4act = wheel4.actuators["Visibility"]
  404. deckact.visibility = True
  405. trucksact.visibility = True
  406. wheel1act.visibility = True
  407. wheel2act.visibility = True
  408. wheel3act.visibility = True
  409. wheel4act.visibility = True
  410. cont.activate(deck.actuators['Visibility'])
  411. cont.activate(trucks.actuators['Visibility'])
  412. cont.activate(wheel1.actuators['Visibility'])
  413. cont.activate(wheel2.actuators['Visibility'])
  414. cont.activate(wheel3.actuators['Visibility'])
  415. cont.activate(wheel4.actuators['Visibility'])
  416. own['throw_deck'] = False
  417. throw_deck_empty = scene.objects["throw_deck_empty"]
  418. throw_deck_empty['kill_deck'] = 1
  419. if ((yBut == False and lasty == True) or dict['kb_q'] == 3) and cont.sensors["carNear"].positive == False:
  420. own['getonboard'] = 1
  421. own['walk_idling'] = 0
  422. def nextframe():
  423. framenumber = own["framenum"]
  424. framenumber = framenumber + 1
  425. if framenumber == 900000:
  426. framenumber = 0
  427. own["framenum"] = framenumber
  428. own['last_walk_frame'] = framenumber
  429. def checkidle():
  430. idle = cont.sensors["idle"]
  431. idle_frame = own["walk_idle_frame"]
  432. if idle.positive:
  433. own["walk_idle_frame"] = 0
  434. cont.deactivate(camobj.actuators['idle_camRight'])
  435. camera.height = .5
  436. else:
  437. if idle_frame == 0:
  438. own["walk_idle_frame"] = own["framenum"]
  439. diff = own["framenum"] - idle_frame
  440. if (diff > 700 and idle_frame != 0 and dropinCol.positive == False and own['walk'] != 0) or own['sit'] == 1:
  441. cont.activate(camobj.actuators['idle_camRight'])
  442. camera.height = .9
  443. camera.min = 2
  444. camera.max = 2.50
  445. own['walk_idling'] = 1
  446. else:
  447. own['walk_idling'] = 0
  448. def idle_anim():
  449. if own['walk_idling'] == 1 and own['sit'] == 0:
  450. walk_idle_frame = own['walk_idle_frame']
  451. mod_num = (own["framenum"] - walk_idle_frame) % 240
  452. idle_lay = 300
  453. if mod_num == 0:
  454. if own['idle_skipper'] > 0:
  455. own['idle_skipper'] -= 1
  456. ran_num = random.randint(1, 8)
  457. if own['last_idle_num'] == ran_num:
  458. ran_num = 1
  459. if own['idle_skipper'] == 0:
  460. own['last_idle_num'] = ran_num
  461. if ran_num == 1 or ran_num > 7:
  462. killact(3)
  463. if STANCE == 0 and own['throw_deck'] == 0:
  464. own['requestAction'] = 'reg_idle1'
  465. elif STANCE == 0 and own['throw_deck'] == 1:
  466. own['requestAction'] = 'reg_idle1'
  467. elif STANCE == 1 and own['throw_deck'] == 0:
  468. own['requestAction'] = 'fak_idle1'
  469. elif STANCE == 1 and own['throw_deck'] == 1:
  470. own['requestAction'] = 'fak_idle1'
  471. elif ran_num == 2:
  472. killact(3)
  473. if STANCE == 0 and own['throw_deck'] == 0:
  474. own['requestAction'] = 'reg_idle2'
  475. elif STANCE == 0 and own['throw_deck'] == 1:
  476. own['requestAction'] = 'reg_idle2_nb'
  477. elif STANCE == 1 and own['throw_deck'] == 0:
  478. own['requestAction'] = 'fak_idle1'
  479. elif STANCE == 1 and own['throw_deck'] == 1:
  480. own['requestAction'] = 'fak_idle1'
  481. elif ran_num == 3:
  482. killact(3)
  483. if STANCE == 0 and own['throw_deck'] == 0:
  484. own['requestAction'] = 'reg_idle3'
  485. elif STANCE == 0 and own['throw_deck'] == 1:
  486. own['requestAction'] = 'reg_idle3'
  487. elif STANCE == 1 and own['throw_deck'] == 0:
  488. own['requestAction'] = 'fak_idle1'
  489. elif STANCE == 1 and own['throw_deck'] == 1:
  490. own['requestAction'] = 'fak_idle1'
  491. own['idle_skipper'] = 2
  492. elif ran_num == 4:
  493. killact(3)
  494. if STANCE == 0 and own['throw_deck'] == 0:
  495. own['requestAction'] = 'reg_idle4'
  496. elif STANCE == 0 and own['throw_deck'] == 1:
  497. own['requestAction'] = 'reg_idle4'
  498. elif STANCE == 1 and own['throw_deck'] == 0:
  499. own['requestAction'] = 'fak_idle4'
  500. elif STANCE == 1 and own['throw_deck'] == 1:
  501. own['requestAction'] = 'fak_idle4'
  502. elif ran_num == 5:
  503. killact(3)
  504. if STANCE == 0 and own['throw_deck'] == 0:
  505. own['requestAction'] = 'reg_idle5'
  506. elif STANCE == 0 and own['throw_deck'] == 1:
  507. own['requestAction'] = 'reg_idle5'
  508. elif STANCE == 1 and own['throw_deck'] == 0:
  509. own['requestAction'] = 'fak_idle5'
  510. elif STANCE == 1 and own['throw_deck'] == 1:
  511. own['requestAction'] = 'fak_idle5'
  512. elif ran_num == 6:
  513. killact(3)
  514. if STANCE == 0 and own['throw_deck'] == 0:
  515. own['requestAction'] = 'reg_idle6'
  516. elif STANCE == 0 and own['throw_deck'] == 1:
  517. own['requestAction'] = 'reg_idle6'
  518. elif STANCE == 1 and own['throw_deck'] == 0:
  519. own['requestAction'] = 'fak_idle6'
  520. elif STANCE == 1 and own['throw_deck'] == 1:
  521. own['requestAction'] = 'fak_idle6'
  522. elif ran_num == 7:
  523. killact(3)
  524. if STANCE == 0 and own['throw_deck'] == 0:
  525. own['requestAction'] = 'reg_idle7'
  526. elif STANCE == 0 and own['throw_deck'] == 1:
  527. own['requestAction'] = 'reg_idle7'
  528. elif STANCE == 1 and own['throw_deck'] == 0:
  529. own['requestAction'] = 'fak_idle6'
  530. elif STANCE == 1 and own['throw_deck'] == 1:
  531. own['requestAction'] = 'fak_idle6'
  532. def reset_pos():
  533. #reset
  534. if ddPad == 1:
  535. spawn_pos = own['spawn_pos']
  536. spawn_rot = own['spawn_rot']
  537. spawn_cam_pos = own['spawn_cam_pos']
  538. spawn_cam_rot = own['spawn_cam_rot']
  539. try:
  540. own.worldPosition = (spawn_pos[0], spawn_pos[1], (spawn_pos[2] + .1))
  541. own.worldOrientation = [[spawn_rot[0][0],spawn_rot[0][1],spawn_rot[0][2]], [spawn_rot[1][0],spawn_rot[1][1],spawn_rot[1][2]], [0.0, 0.0, 1.0]]
  542. cam.worldPosition = (spawn_cam_pos[0], spawn_cam_pos[1], (spawn_cam_pos[2]))
  543. cam.worldOrientation = [[spawn_cam_rot[0][0],spawn_cam_rot[0][1],spawn_cam_rot[0][2]], [spawn_cam_rot[1][0],spawn_cam_rot[1][1],spawn_cam_rot[1][2]], [0.0, 0.0, 1.0]]
  544. except:
  545. own.worldPosition = (0, 0, .1)
  546. own.worldOrientation = [[1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
  547. own['stance'] = own['spawn_stance']
  548. if own["spawn_stance"] == 1:
  549. own.setLinearVelocity([.1,0,0], 1)
  550. else:
  551. own.setLinearVelocity([-.1,0,0], 1)
  552. if udPad == 1:
  553. own['spawn_pos'] = [own.worldPosition[0], own.worldPosition[1], own.worldPosition[2]]
  554. own['spawn_rot'] = [[own.worldOrientation[0][0],own.worldOrientation[0][1],own.worldOrientation[0][2]], [own.worldOrientation[1][0],own.worldOrientation[1][1],own.worldOrientation[1][2]], own.worldOrientation[2][2]]
  555. own['spawn_cam_pos'] = [cam.worldPosition[0], cam.worldPosition[1], cam.worldPosition[2]]
  556. own['spawn_cam_rot'] = [[cam.worldOrientation[0][0],cam.worldOrientation[0][1],cam.worldOrientation[0][2]], [cam.worldOrientation[1][0],cam.worldOrientation[1][1],cam.worldOrientation[1][2]], cam.worldOrientation[2][2]]
  557. stance = own["stance"]
  558. own["spawn_stance"] = stance
  559. def falldeck():
  560. throw_deck_empty = scene.objects["throw_deck_empty"]
  561. deckact = deck.actuators["Visibility"]
  562. trucksact = trucks.actuators["Visibility"]
  563. wheel1act = wheel1.actuators["Visibility"]
  564. wheel2act = wheel2.actuators["Visibility"]
  565. wheel3act = wheel3.actuators["Visibility"]
  566. wheel4act = wheel4.actuators["Visibility"]
  567. if own['throw_deck'] == False:
  568. own['throw_deck'] = True
  569. deckact.visibility = False
  570. trucksact.visibility = False
  571. wheel1act.visibility = False
  572. wheel2act.visibility = False
  573. wheel3act.visibility = False
  574. wheel4act.visibility = False
  575. act = throw_deck_empty.actuators['throw_dec_act']
  576. if STANCE == True:
  577. act.linearVelocity = [0.0, 1.0, 1.0]
  578. if STANCE == False:
  579. act.linearVelocity = [0.0, 1.0, -1.0]
  580. cont.activate(act)
  581. else:
  582. own['throw_deck'] = False
  583. deckact.visibility = True
  584. trucksact.visibility = True
  585. wheel1act.visibility = True
  586. wheel2act.visibility = True
  587. wheel3act.visibility = True
  588. wheel4act.visibility = True
  589. throw_deck_empty['kill_deck'] = 1
  590. cont.activate(deck.actuators['Visibility'])
  591. cont.activate(trucks.actuators['Visibility'])
  592. cont.activate(wheel1.actuators['Visibility'])
  593. cont.activate(wheel2.actuators['Visibility'])
  594. cont.activate(wheel3.actuators['Visibility'])
  595. cont.activate(wheel4.actuators['Visibility'])
  596. def throwdeck(strength, ud):
  597. throw_deck_empty = scene.objects["throw_deck_empty"]
  598. deckact = deck.actuators["Visibility"]
  599. trucksact = trucks.actuators["Visibility"]
  600. wheel1act = wheel1.actuators["Visibility"]
  601. wheel2act = wheel2.actuators["Visibility"]
  602. wheel3act = wheel3.actuators["Visibility"]
  603. wheel4act = wheel4.actuators["Visibility"]
  604. if own['throw_deck'] == False:
  605. own['throw_deck'] = True
  606. deckact.visibility = False
  607. trucksact.visibility = False
  608. wheel1act.visibility = False
  609. wheel2act.visibility = False
  610. wheel3act.visibility = False
  611. wheel4act.visibility = False
  612. act = throw_deck_empty.actuators['throw_dec_act']
  613. hard = strength * .08
  614. if hard > 9:
  615. hard = 9
  616. if hard < 1:
  617. hard = 1
  618. ud = ud * 4
  619. own['bbut_timer'] = 0
  620. if STANCE == True:
  621. own['requestAction'] = 'fak_throw'
  622. act.linearVelocity = [0.0, ud, hard]
  623. if STANCE == False:
  624. own['requestAction'] = 'fak_throw'
  625. act.linearVelocity = [0.0, ud, -hard]
  626. cont.activate(act)
  627. else:
  628. own['throw_deck'] = False
  629. deckact.visibility = True
  630. trucksact.visibility = True
  631. wheel1act.visibility = True
  632. wheel2act.visibility = True
  633. wheel3act.visibility = True
  634. wheel4act.visibility = True
  635. throw_deck_empty['kill_deck'] = 1
  636. cont.activate(deck.actuators['Visibility'])
  637. cont.activate(trucks.actuators['Visibility'])
  638. cont.activate(wheel1.actuators['Visibility'])
  639. cont.activate(wheel2.actuators['Visibility'])
  640. cont.activate(wheel3.actuators['Visibility'])
  641. cont.activate(wheel4.actuators['Visibility'])
  642. def throwdeck_trigger():
  643. lastb = own['lastb']
  644. throw_deck_empty = scene.objects["throw_deck_empty"]
  645. if bBut == True:
  646. own['bbut_timer'] += 1
  647. ud = (rUD * 10) +1
  648. if bBut == False:
  649. throw_deck_empty['kill_deck'] = 0
  650. if bBut == False and own['lastb'] == True:
  651. strength = own['bbut_timer']
  652. ud = (rUD * 10) +1
  653. throwdeck(strength, ud)
  654. def focus_deck():
  655. since_air = own['framenum'] - own['lF_air_frame']
  656. if cb_td.positive and since_air < 10:
  657. object = 'focus_deckA'
  658. object2 = 'focus_deckB'
  659. other = throw_deck_empty
  660. throw_deck = scene.objects["throw_deck"]
  661. throw_deck.endObject()
  662. scene.addObject(object, other, 0)
  663. scene.addObject(object2, other, 0)
  664. if own['throw_deck'] == True:
  665. if dict['ldPad'] == False and dict['last_ldPad'] == True:
  666. object = 'focus_deckA'
  667. object2 = 'focus_deckB'
  668. other = throw_deck_empty
  669. scene.addObject(object, other, 0)
  670. scene.addObject(object2, other, 0)
  671. def fall():
  672. if own['fall'] == True:
  673. falldeck()
  674. if STANCE == 1:
  675. own['requestAction'] = 'fak_air-walk_air'
  676. own.setLinearVelocity([3,2,0], True)
  677. else:
  678. own['requestAction'] = 'reg_air-walk_air'
  679. own.setLinearVelocity([-3,-2,0], True)
  680. own['fall'] = False
  681. def sit():
  682. #turn off sit
  683. if lup == 1 or ldown == 1 or lUD > sens or lUD < -sens:
  684. if own['sit'] == 1:
  685. killact(300)
  686. killact(299)
  687. own['sit'] = 0
  688. if aBut == False and lasta == True:
  689. try:
  690. if 'sit' in r_ground.hitObject:
  691. print("sit")
  692. own['sit'] = 1
  693. killact(3)
  694. if STANCE == 0:
  695. own['requestAction'] = 'reg_sit'
  696. elif STANCE == 1:
  697. own['requestAction'] = 'fak_sit'
  698. except:
  699. pass
  700. if own['sit'] == 1:
  701. try:
  702. killact(3)
  703. sit_vect = r_ground.hitObject.getAxisVect( [0, 1, 0])
  704. if STANCE == 0:
  705. own.alignAxisToVect(-sit_vect, 0, .2)
  706. own['requestAction'] = 'reg_sit'
  707. elif STANCE == 1:
  708. own['requestAction'] = 'fak_sit'
  709. own.alignAxisToVect(sit_vect, 0, .2)
  710. except:
  711. pass
  712. def switchcam():
  713. if ltsBut == False and own['lastlts'] == True and rtsBut == False:
  714. if own['camera'] == 1:
  715. own['camera'] = 0
  716. else:
  717. own['camera'] = 1
  718. if rtsBut == False and own['lastrts'] == True and ltsBut == False:
  719. if own['camera'] == 2:
  720. own['camera'] = 0
  721. else:
  722. own['camera'] = 2
  723. #followcam
  724. def move_followcam():
  725. if own['camera'] == 2:
  726. if own['lastbkBut'] == True and bkBut == False:
  727. print("activate move followcam")
  728. if own['move_followcam'] == False:
  729. own['move_followcam'] = True
  730. else:
  731. own['move_followcam'] = False
  732. if own['move_followcam'] == True:
  733. camspeed1 = .015
  734. camspeed2 = .055
  735. camrot1 = .005
  736. camrot2 = .02
  737. #up
  738. if lUD < -0.080:
  739. followcam.actuators["up"].dLoc = [ 0, 0, -camspeed2]
  740. cont.activate(followcam.actuators["up"])
  741. print("fastup")
  742. else:
  743. cont.deactivate(followcam.actuators["up"])
  744. # #down
  745. if lUD > .080:
  746. followcam.actuators["down"].dLoc = [ 0, 0, camspeed2]
  747. cont.activate(followcam.actuators["down"])
  748. else:
  749. cont.deactivate(followcam.actuators["down"])
  750. # #left
  751. if lLR < -0.080:
  752. followcam.actuators["left"].dLoc = [-camspeed2, 0, 0]
  753. cont.activate(followcam.actuators["left"])
  754. else:
  755. cont.deactivate(followcam.actuators["left"])
  756. # #right
  757. if lLR > 0.080:
  758. followcam.actuators["right"].dLoc = [camspeed2, 0, 0]
  759. cont.activate(followcam.actuators["right"])
  760. else:
  761. cont.deactivate(followcam.actuators["right"])
  762. #up
  763. if rUD < -0.080:
  764. followcam.actuators["rotup"].dLoc = [0, 0, camrot2]
  765. cont.activate(followcam.actuators["rotup"])
  766. else:
  767. cont.deactivate(followcam.actuators["rotup"])
  768. # #down
  769. if rUD > .080:
  770. followcam.actuators["rotdown"].dLoc = [0, 0, -camrot2]
  771. cont.activate(followcam.actuators["rotdown"])
  772. else:
  773. cont.deactivate(followcam.actuators["rotdown"])
  774. # #left
  775. if rLR < -0.080:
  776. followcam.actuators["rotleft"].dRot = [0, 0, camrot2]
  777. cont.activate(followcam.actuators["rotleft"])
  778. else:
  779. cont.deactivate(followcam.actuators["rotleft"])
  780. # #right
  781. if rLR > 0.080:
  782. followcam.actuators["rotright"].dRot = [0, 0, -camrot2]
  783. cont.activate(followcam.actuators["rotright"])
  784. else:
  785. cont.deactivate(followcam.actuators["rotright"])
  786. #*********************************************
  787. if lUD > -0.080 and lUD < -0.030:
  788. followcam.actuators["up"].dLoc = [ 0, 0, -camspeed1]
  789. cont.activate(followcam.actuators["up"])
  790. else:
  791. cont.deactivate(followcam.actuators["up"])
  792. # #down
  793. if lUD < .080 and lUD > .03:
  794. followcam.actuators["down"].dLoc = [ 0, 0, camspeed1]
  795. cont.activate(followcam.actuators["down"])
  796. else:
  797. cont.deactivate(followcam.actuators["down"])
  798. # #left
  799. if lLR > -0.080 and lLR < -0.030:
  800. followcam.actuators["left"].dLoc = [-camspeed1, 0, 0]
  801. cont.activate(followcam.actuators["left"])
  802. else:
  803. cont.deactivate(followcam.actuators["left"])
  804. # #right
  805. if lLR < .080 and lLR > .03:
  806. followcam.actuators["right"].dLoc = [camspeed1, 0, 0]
  807. cont.activate(followcam.actuators["right"])
  808. else:
  809. cont.deactivate(followcam.actuators["right"])
  810. #up
  811. if rUD > -0.080 and rUD < -0.030:
  812. followcam.actuators["rotup"].dRot = [camrot1, 0, 0]
  813. cont.activate(followcam.actuators["rotup"])
  814. else:
  815. cont.deactivate(followcam.actuators["rotup"])
  816. # #down
  817. if rUD < .080 and rUD > .03:
  818. followcam.actuators["rotdown"].dRot = [-camrot1, 0, 0]
  819. cont.activate(followcam.actuators["rotdown"])
  820. else:
  821. cont.deactivate(followcam.actuators["rotdown"])
  822. # #left
  823. if rLR > -0.080 and rLR < -0.030:
  824. followcam.actuators["rotleft"].dRot = [0, 0, camrot1]
  825. cont.activate(followcam.actuators["rotleft"])
  826. else:
  827. cont.deactivate(followcam.actuators["rotleft"])
  828. # #right
  829. if rLR < .080 and rLR > .03:
  830. followcam.actuators["rotright"].dRot = [0, 0, -camrot1]
  831. cont.activate(followcam.actuators["rotright"])
  832. else:
  833. cont.deactivate(followcam.actuators["rotright"])
  834. def move_flycam():
  835. if own['camera'] == 1:
  836. if own['lastbkBut'] == True and bkBut == False:
  837. if own['move_freecam'] == False:
  838. own['move_freecam'] = True
  839. else:
  840. own['move_freecam'] = False
  841. if own['move_freecam'] == True:
  842. camspeed1 = .015
  843. camspeed2 = .055
  844. camrot1 = .005
  845. camrot2 = .02
  846. #up
  847. if lUD < -0.080:
  848. freecam.actuators["up"].dLoc = [ 0, 0, -camspeed2]
  849. cont.activate(freecam.actuators["up"])
  850. else:
  851. cont.deactivate(freecam.actuators["up"])
  852. # #down
  853. if lUD > .080:
  854. freecam.actuators["down"].dLoc = [ 0, 0, camspeed2]
  855. cont.activate(freecam.actuators["down"])
  856. else:
  857. cont.deactivate(freecam.actuators["down"])
  858. # #left
  859. if lLR < -0.080:
  860. freecam.actuators["left"].dLoc = [-camspeed2, 0, 0]
  861. cont.activate(freecam.actuators["left"])
  862. else:
  863. cont.deactivate(freecam.actuators["left"])
  864. # #right
  865. if lLR > 0.080:
  866. freecam.actuators["right"].dLoc = [camspeed2, 0, 0]
  867. cont.activate(freecam.actuators["right"])
  868. else:
  869. cont.deactivate(freecam.actuators["right"])
  870. #up
  871. if rUD < -0.080:
  872. freecam.actuators["rotup"].dRot = [camrot2, 0, 0]
  873. cont.activate(freecam.actuators["rotup"])
  874. else:
  875. cont.deactivate(freecam.actuators["rotup"])
  876. # #down
  877. if rUD > .080:
  878. freecam.actuators["rotdown"].dRot = [-camrot2, 0, 0]
  879. cont.activate(freecam.actuators["rotdown"])
  880. else:
  881. cont.deactivate(freecam.actuators["rotdown"])
  882. # #left
  883. if rLR < -0.080:
  884. freecam.actuators["rotleft"].dRot = [0, 0, camrot2]
  885. cont.activate(freecam.actuators["rotleft"])
  886. else:
  887. cont.deactivate(freecam.actuators["rotleft"])
  888. # #right
  889. if rLR > 0.080:
  890. freecam.actuators["rotright"].dRot = [0, 0, -camrot2]
  891. cont.activate(freecam.actuators["rotright"])
  892. else:
  893. cont.deactivate(freecam.actuators["rotright"])
  894. #*********************************************
  895. if lUD > -0.080 and lUD < -0.030:
  896. freecam.actuators["up"].dLoc = [ 0, 0, -camspeed1]
  897. cont.activate(freecam.actuators["up"])
  898. #print(lUD)
  899. else:
  900. cont.deactivate(freecam.actuators["up"])
  901. # #down
  902. if lUD < .080 and lUD > .03:
  903. freecam.actuators["down"].dLoc = [ 0, 0, camspeed1]
  904. cont.activate(freecam.actuators["down"])
  905. else:
  906. cont.deactivate(freecam.actuators["down"])
  907. # #left
  908. if lLR > -0.080 and lLR < -0.030:
  909. freecam.actuators["left"].dLoc = [-camspeed1, 0, 0]
  910. cont.activate(freecam.actuators["left"])
  911. else:
  912. cont.deactivate(freecam.actuators["left"])
  913. # #right
  914. if lLR < .080 and lLR > .03:
  915. freecam.actuators["right"].dLoc = [camspeed1, 0, 0]
  916. cont.activate(freecam.actuators["right"])
  917. else:
  918. cont.deactivate(freecam.actuators["right"])
  919. #up
  920. if rUD > -0.080 and rUD < -0.030:
  921. freecam.actuators["rotup"].dRot = [camrot1, 0, 0]
  922. cont.activate(freecam.actuators["rotup"])
  923. else:
  924. cont.deactivate(freecam.actuators["rotup"])
  925. # #down
  926. if rUD < .080 and rUD > .03:
  927. freecam.actuators["rotdown"].dRot = [-camrot1, 0, 0]
  928. cont.activate(freecam.actuators["rotdown"])
  929. else:
  930. cont.deactivate(freecam.actuators["rotdown"])
  931. # #left
  932. if rLR > -0.080 and rLR < -0.030:
  933. freecam.actuators["rotleft"].dRot = [0, 0, camrot1]
  934. cont.activate(freecam.actuators["rotleft"])
  935. else:
  936. cont.deactivate(freecam.actuators["rotleft"])
  937. # #right
  938. if rLR < .080 and rLR > .03:
  939. freecam.actuators["rotright"].dRot = [0, 0, -camrot1]
  940. cont.activate(freecam.actuators["rotright"])
  941. else:
  942. cont.deactivate(freecam.actuators["rotright"])
  943. if r_ground.triggered == False:
  944. cont.deactivate(own.actuators["walk_align"])
  945. else:
  946. cont.activate(own.actuators["walk_align"])
  947. #walking on stairs
  948. if r_ground.triggered:
  949. try:
  950. if 'stair' in r_ground.hitObject:
  951. own['stair_counter'] = 20
  952. except:
  953. pass
  954. if own['stair_counter'] > 0:
  955. own['stair_counter'] -= 1
  956. if yBut == True:
  957. own['walk_idling'] = 0
  958. own["walk_idle_frame"] = 0
  959. if own['stair_counter'] > 5 and r_ground.triggered == False:
  960. own.applyForce([0,0,-200], True)
  961. if deck.visible:
  962. own['deckvis'] = 1
  963. else:
  964. own['deckvis'] = 0
  965. if own['requestAction'] == 'empty' or own['requestAction'] == None:
  966. if STANCE == 0:
  967. own['requestAction'] = 'reg_idle1'
  968. if STANCE == 1:
  969. own['requestAction'] = 'fak_idle1'
  970. def onground():
  971. if r_ground.positive:
  972. own['lF_ground_frame'] = own['framenum']
  973. if 'grind' in r_ground.hitObject:
  974. if own['framenum'] - own['last_fall_frame'] < 90:
  975. own.applyForce([0,100,0], True)
  976. #print('moving away from rail')
  977. else:
  978. #print('in air')
  979. if own['framenum'] - own['lF_ground_frame'] > 10:
  980. if STANCE == 0:
  981. own['requestAction'] = 'reg_walk_air'
  982. else:
  983. own['requestAction'] = 'fak_walk_air'
  984. #if control bottom is touching ground object, turn ground on
  985. if cb.positive:
  986. if own['framenum'] - own['last_fall_frame'] < 90:
  987. own['lF_ground_frame'] = own['framenum']
  988. def get_in_car():
  989. carNear = cont.sensors["carNear"]
  990. if carNear.positive:
  991. obj = carNear.hitObject
  992. if yBut == True:
  993. obj['driving'] = True
  994. own['driving'] = True
  995. scene = bge.logic.getCurrentScene()
  996. cam = scene.active_camera
  997. #cam.target = obj
  998. #cam.state = 2
  999. cont.actuators['Camera'].object = obj
  1000. cont.actuators['Camera'].height = 3
  1001. cont.actuators['Camera'].min = 6
  1002. cont.actuators['Camera'].max = 10
  1003. own.state = 2
  1004. print('near car')
  1005. def get_on_bike():
  1006. bikeCol = cont.sensors['bikeCol']
  1007. if bikeCol.positive and yBut == True:
  1008. print('bike')
  1009. onboard()
  1010. jump()
  1011. dropin()
  1012. throwdeck_trigger()
  1013. nextframe()
  1014. checkidle()
  1015. getonboard()
  1016. reset_pos()
  1017. switchcam()
  1018. move_flycam()
  1019. move_followcam()
  1020. fall()
  1021. idle_anim()
  1022. sit()
  1023. onground()
  1024. focus_deck()
  1025. get_in_car()
  1026. #printplaying()
  1027. own.alignAxisToVect([0.0,0.0,1.0], 2, .03)
  1028. own.actuators["sroll"].stopSound()
  1029. wheel1 = scene.objects["rollen.000"]
  1030. wheel2 = scene.objects["rollen.001"]
  1031. wheel3 = scene.objects["rollen.002"]
  1032. wheel4 = scene.objects["rollen.003"]
  1033. wheel1.stopAction(2)
  1034. wheel2.stopAction(2)
  1035. wheel3.stopAction(2)
  1036. wheel4.stopAction(2)
  1037. own['lasty'] = yBut
  1038. own['lastb'] = bBut
  1039. own['lasta'] = aBut
  1040. own['lastx'] = xBut
  1041. own['lastlts'] = ltsBut
  1042. own['lastrts'] = rtsBut
  1043. own['lastbkBut'] = bkBut
  1044. own['dropinCol'] = dropinCol
  1045. own['walk'] = 1