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

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