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

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