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

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