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 dict['kb_lsh'] == 2 and dict['kb_w'] == 2:
  162. print('wtf')
  163. if ((lup == 1 and aBut == 0) or (dict['kb_w'] == 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:
  164. own['walking'] = "regular"
  165. walking = "regular"
  166. elif ((lup == 1 and aBut == 1) or (dict['kb_lsh'] == 2 and dict['kb_w'] == 2)) and yBut == False and (r_ground.positive or own['stair_counter'] > 0) and xBut == 0 and wf == 0 and dict['kb_space'] != 2:
  167. own['walking'] = "fast"
  168. walking = "fast"
  169. else:
  170. own['walking'] = None
  171. walking = None
  172. #print(own['walk_timer'])
  173. if walking == "regular":
  174. cont.deactivate(own.actuators['forward2'])
  175. cont.deactivate(own.actuators['backward2'])
  176. if stance == 0:
  177. cont.activate(own.actuators['forward'])
  178. else:
  179. cont.activate(own.actuators['backward'])
  180. if walking == "fast":
  181. cont.deactivate(own.actuators['forward'])
  182. cont.deactivate(own.actuators['backward'])
  183. if stance == 0:
  184. cont.activate(own.actuators['forward2'])
  185. else:
  186. cont.activate(own.actuators['backward2'])
  187. if walking == None:
  188. cont.deactivate(own.actuators['forward2'])
  189. cont.deactivate(own.actuators['backward2'])
  190. cont.deactivate(own.actuators['forward'])
  191. cont.deactivate(own.actuators['backward'])
  192. if own['walk_timer'] < 50:
  193. velx = vel.x * .95
  194. own.setLinearVelocity([velx, 0, vel.z], True)
  195. else:
  196. own.setLinearVelocity([0, 0, vel.z], True)
  197. #print("set 0 vel")
  198. #old walking
  199. if (lup == 1 and aBut == 0) or (dict['kb_w'] == 2 and dict['kb_lsh'] == 0) and yBut == False and (r_ground.positive or own['stair_counter'] > 0) and xBut == 0:
  200. own.actuators["walkondirt"].volume = .2
  201. own.actuators["walkondirt"].pitch = 1
  202. cont.activate(own.actuators["walkondirt"])
  203. if stance == 0 and skater.isPlayingAction(fliplay) == False:
  204. #without deck
  205. if own['throw_deck'] == True:
  206. own['requestAction'] = 'reg_walk_nb'
  207. else:
  208. own['requestAction'] = 'reg_walk'
  209. if stance == 1 and skater.isPlayingAction(fliplay) == False:
  210. #without deck
  211. if own['throw_deck'] == True:
  212. own['requestAction'] = 'fak_walk_nb'
  213. else:
  214. own['requestAction'] = 'fak_walk'
  215. elif ((lup == 1 and aBut == 1) or (dict['kb_lsh'] == 2 and dict['kb_w'] == 2)) and yBut == False and (r_ground.positive or own['stair_counter'] > 0) and xBut == 0:
  216. own.actuators["walkondirt"].volume = .2
  217. own.actuators["walkondirt"].pitch = 1.3
  218. cont.activate(own.actuators["walkondirt"])
  219. if stance == 0 and skater.isPlayingAction(fliplay) == False:
  220. if own['throw_deck'] == True:
  221. own['requestAction'] = 'reg_walkFast_nb'
  222. skater.playAction("reg_nwalk_nb.001", 0,35, layer=25, play_mode=1, speed=1)
  223. else:
  224. own['requestAction'] = 'reg_walkFast'
  225. else:
  226. killact(25)
  227. killact(305)
  228. killact(306)
  229. if stance == 1 and skater.isPlayingAction(fliplay) == False:
  230. if own['throw_deck'] == True:
  231. own['requestAction'] = 'fak_walkFast_nb'
  232. skater.playAction("fak_nwalk_nb.001", 0,35, layer=24, play_mode=1, speed=1)
  233. else:
  234. own['requestAction'] = 'fak_walkFast'
  235. else:
  236. vel = own.getLinearVelocity(True)
  237. cont.deactivate(own.actuators["walkondirt"])
  238. #turning
  239. if lRight == 1 or dict['kb_d'] == 2:
  240. cont.activate(own.actuators['right'])
  241. else:
  242. cont.deactivate(own.actuators['right'])
  243. if lLeft == 1 or dict['kb_a'] == 2:
  244. cont.activate(own.actuators['left'])
  245. else:
  246. cont.deactivate(own.actuators['left'])
  247. #in air
  248. if (lup == 1 or dict['kb_w'] != 0) and r_ground.positive == False:
  249. if stance == 0:
  250. cont.deactivate(own.actuators['forward'])
  251. cont.deactivate(own.actuators['forward2'])
  252. killact(4)
  253. killact(5)
  254. killact(6)
  255. killact(7)
  256. velx = linvel.x - 1
  257. own.setLinearVelocity([-1.5, linvel.y, linvel.z], 1)
  258. if stance == 1:
  259. cont.deactivate(own.actuators['backward'])
  260. cont.deactivate(own.actuators['backward2'])
  261. killact(4)
  262. killact(5)
  263. killact(6)
  264. killact(7)
  265. velx = linvel.x + 1
  266. own.setLinearVelocity([1.5, linvel.y, linvel.z], 1)
  267. own['lF_air_frame'] = own['framenum']
  268. #---------------
  269. if rLR > .05:
  270. cont.activate(camobj.actuators['camRight'])
  271. else:
  272. cont.deactivate(camobj.actuators['camRight'])
  273. if rLR < -.05:
  274. cont.activate(camobj.actuators['camLeft'])
  275. else:
  276. cont.deactivate(camobj.actuators['camLeft'])
  277. if rUD > .05:
  278. cont.activate(camobj.actuators['camDown'])
  279. else:
  280. cont.deactivate(camobj.actuators['camDown'])
  281. if rUD < -.05:
  282. cont.activate(camobj.actuators['camUp'])
  283. else:
  284. cont.deactivate(camobj.actuators['camUp'])
  285. #----------------
  286. camera.height = .9 #-.4
  287. camera.min = 1.5
  288. camera.max = 2
  289. lasty = own['lasty']
  290. def onboard():
  291. if own['walk'] == 0:
  292. print("start walking")
  293. if own['framenum'] > 100 and own['fall'] == False:
  294. #pass
  295. cont.activate(own.actuators['pop'])
  296. own['getoffboard'] = False
  297. fliplay = 301
  298. fliplay2 = 302
  299. fliplay3 = 303
  300. own['grindcement_vol'] = 0
  301. own['grindcement_pitch'] = 0
  302. own['grindrail_vol'] = 0
  303. own['grindrail_pitch'] = 0
  304. own['sroll_vol'] = 0
  305. own['sroll_pitch'] = 0
  306. try:
  307. vel = own['offboard_vel']
  308. vel = [velx, vel.y, vel.z]
  309. except:
  310. pass
  311. if STANCE == 0:
  312. skater.stopAction(fliplay)
  313. deck.stopAction(deckon)
  314. trucks.stopAction(truckon)
  315. own['requestAction'] = 'reg_offboard'
  316. if STANCE == 1:
  317. skater.stopAction(fliplay)
  318. deck.stopAction(deckon)
  319. trucks.stopAction(truckon)
  320. own['requestAction'] = 'fak_offboard'
  321. def jump():
  322. if xBut == True or dict['kb_space'] == 1:
  323. #if xBut == True:
  324. if own['lastx'] == 0:
  325. killact(3)
  326. killact(4)
  327. killact(5)
  328. killact(6)
  329. killact(7)
  330. if STANCE == 0:
  331. own['requestAction'] ='reg_jump'
  332. print('jump')
  333. if STANCE == 1:
  334. own['requestAction'] ='fak_jump'
  335. print('jump')
  336. JUMPHEIGHT = 1100
  337. force = [ 0.0, 0.0, JUMPHEIGHT]
  338. # use local axis
  339. local = False
  340. # apply force
  341. own.applyForce(force, local)
  342. own['lastx'] = 1
  343. else:
  344. own['lastx'] = 0
  345. def dropin():
  346. if dropinCol.positive == True:
  347. pass
  348. def getonboard():
  349. getonboard = own['getonboard']
  350. fliplay2 = 50#8560
  351. if yBut == True:
  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. if (yBut == False and lasty == True) or yBut == True and dropinCol.positive:
  406. deckact = deck.actuators["Visibility"]
  407. trucksact = trucks.actuators["Visibility"]
  408. wheel1act = wheel1.actuators["Visibility"]
  409. wheel2act = wheel2.actuators["Visibility"]
  410. wheel3act = wheel3.actuators["Visibility"]
  411. wheel4act = wheel4.actuators["Visibility"]
  412. deckact.visibility = True
  413. trucksact.visibility = True
  414. wheel1act.visibility = True
  415. wheel2act.visibility = True
  416. wheel3act.visibility = True
  417. wheel4act.visibility = True
  418. cont.activate(deck.actuators['Visibility'])
  419. cont.activate(trucks.actuators['Visibility'])
  420. cont.activate(wheel1.actuators['Visibility'])
  421. cont.activate(wheel2.actuators['Visibility'])
  422. cont.activate(wheel3.actuators['Visibility'])
  423. cont.activate(wheel4.actuators['Visibility'])
  424. own['throw_deck'] = False
  425. throw_deck_empty = scene.objects["throw_deck_empty"]
  426. throw_deck_empty['kill_deck'] = 1
  427. if (yBut == False and lasty == True):
  428. own['getonboard'] = 1
  429. def nextframe():
  430. framenumber = own["framenum"]
  431. framenumber = framenumber + 1
  432. if framenumber == 900000:
  433. framenumber = 0
  434. own["framenum"] = framenumber
  435. own['last_walk_frame'] = framenumber
  436. def checkidle():
  437. idle = cont.sensors["idle"]
  438. #print(idle.positive)
  439. idle_frame = own["walk_idle_frame"]
  440. if idle.positive:
  441. own["walk_idle_frame"] = 0
  442. cont.deactivate(camobj.actuators['idle_camRight'])
  443. camera.height = .5
  444. else:
  445. if idle_frame == 0:
  446. own["walk_idle_frame"] = own["framenum"]
  447. diff = own["framenum"] - idle_frame
  448. if (diff > 700 and idle_frame != 0 and dropinCol.positive == False and own['walk'] != 0) or own['sit'] == 1:
  449. cont.activate(camobj.actuators['idle_camRight'])
  450. camera.height = .9
  451. camera.min = 2
  452. camera.max = 2.50
  453. own['walk_idling'] = 1
  454. else:
  455. own['walk_idling'] = 0
  456. def idle_anim():
  457. if own['walk_idling'] == 1 and own['sit'] == 0:
  458. walk_idle_frame = own['walk_idle_frame']
  459. mod_num = (own["framenum"] - walk_idle_frame) % 240
  460. idle_lay = 300
  461. if mod_num == 0:
  462. if own['idle_skipper'] > 0:
  463. own['idle_skipper'] -= 1
  464. ran_num = random.randint(1, 8)
  465. if own['last_idle_num'] == ran_num:
  466. ran_num = 1
  467. if own['idle_skipper'] == 0:
  468. own['last_idle_num'] = ran_num
  469. if ran_num == 1 or ran_num > 7:
  470. killact(3)
  471. if STANCE == 0 and own['throw_deck'] == 0:
  472. own['requestAction'] = 'reg_idle1'
  473. elif STANCE == 0 and own['throw_deck'] == 1:
  474. own['requestAction'] = 'reg_idle1'
  475. elif STANCE == 1 and own['throw_deck'] == 0:
  476. own['requestAction'] = 'fak_idle1'
  477. elif STANCE == 1 and own['throw_deck'] == 1:
  478. own['requestAction'] = 'fak_idle1'
  479. elif ran_num == 2:
  480. killact(3)
  481. if STANCE == 0 and own['throw_deck'] == 0:
  482. own['requestAction'] = 'reg_idle2'
  483. elif STANCE == 0 and own['throw_deck'] == 1:
  484. own['requestAction'] = 'reg_idle2_nb'
  485. elif STANCE == 1 and own['throw_deck'] == 0:
  486. own['requestAction'] = 'fak_idle1'
  487. elif STANCE == 1 and own['throw_deck'] == 1:
  488. own['requestAction'] = 'fak_idle1'
  489. elif ran_num == 3:
  490. killact(3)
  491. if STANCE == 0 and own['throw_deck'] == 0:
  492. own['requestAction'] = 'reg_idle3'
  493. elif STANCE == 0 and own['throw_deck'] == 1:
  494. own['requestAction'] = 'reg_idle3'
  495. elif STANCE == 1 and own['throw_deck'] == 0:
  496. own['requestAction'] = 'fak_idle1'
  497. elif STANCE == 1 and own['throw_deck'] == 1:
  498. own['requestAction'] = 'fak_idle1'
  499. own['idle_skipper'] = 2
  500. elif ran_num == 4:
  501. killact(3)
  502. if STANCE == 0 and own['throw_deck'] == 0:
  503. own['requestAction'] = 'reg_idle4'
  504. elif STANCE == 0 and own['throw_deck'] == 1:
  505. own['requestAction'] = 'reg_idle4'
  506. elif STANCE == 1 and own['throw_deck'] == 0:
  507. own['requestAction'] = 'fak_idle4'
  508. elif STANCE == 1 and own['throw_deck'] == 1:
  509. own['requestAction'] = 'fak_idle4'
  510. elif ran_num == 5:
  511. killact(3)
  512. if STANCE == 0 and own['throw_deck'] == 0:
  513. own['requestAction'] = 'reg_idle5'
  514. elif STANCE == 0 and own['throw_deck'] == 1:
  515. own['requestAction'] = 'reg_idle5'
  516. elif STANCE == 1 and own['throw_deck'] == 0:
  517. own['requestAction'] = 'fak_idle5'
  518. elif STANCE == 1 and own['throw_deck'] == 1:
  519. own['requestAction'] = 'fak_idle5'
  520. elif ran_num == 6:
  521. killact(3)
  522. if STANCE == 0 and own['throw_deck'] == 0:
  523. own['requestAction'] = 'reg_idle6'
  524. elif STANCE == 0 and own['throw_deck'] == 1:
  525. own['requestAction'] = 'reg_idle6'
  526. elif STANCE == 1 and own['throw_deck'] == 0:
  527. own['requestAction'] = 'fak_idle6'
  528. elif STANCE == 1 and own['throw_deck'] == 1:
  529. own['requestAction'] = 'fak_idle6'
  530. elif ran_num == 7:
  531. killact(3)
  532. if STANCE == 0 and own['throw_deck'] == 0:
  533. own['requestAction'] = 'reg_idle7'
  534. elif STANCE == 0 and own['throw_deck'] == 1:
  535. own['requestAction'] = 'reg_idle7'
  536. elif STANCE == 1 and own['throw_deck'] == 0:
  537. own['requestAction'] = 'fak_idle6'
  538. elif STANCE == 1 and own['throw_deck'] == 1:
  539. own['requestAction'] = 'fak_idle6'
  540. def reset_pos():
  541. #reset
  542. if ddPad == 1:
  543. spawn_pos = own['spawn_pos']
  544. spawn_rot = own['spawn_rot']
  545. spawn_cam_pos = own['spawn_cam_pos']
  546. spawn_cam_rot = own['spawn_cam_rot']
  547. try:
  548. own.worldPosition = (spawn_pos[0], spawn_pos[1], (spawn_pos[2] + .1))
  549. 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]]
  550. cam.worldPosition = (spawn_cam_pos[0], spawn_cam_pos[1], (spawn_cam_pos[2]))
  551. 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]]
  552. except:
  553. own.worldPosition = (0, 0, .1)
  554. own.worldOrientation = [[1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
  555. own['stance'] = own['spawn_stance']
  556. if own["spawn_stance"] == 1:
  557. own.setLinearVelocity([.1,0,0], 1)
  558. else:
  559. own.setLinearVelocity([-.1,0,0], 1)
  560. if udPad == 1:
  561. own['spawn_pos'] = [own.worldPosition[0], own.worldPosition[1], own.worldPosition[2]]
  562. 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]]
  563. own['spawn_cam_pos'] = [cam.worldPosition[0], cam.worldPosition[1], cam.worldPosition[2]]
  564. 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]]
  565. stance = own["stance"]
  566. own["spawn_stance"] = stance
  567. def falldeck():
  568. throw_deck_empty = scene.objects["throw_deck_empty"]
  569. deckact = deck.actuators["Visibility"]
  570. trucksact = trucks.actuators["Visibility"]
  571. wheel1act = wheel1.actuators["Visibility"]
  572. wheel2act = wheel2.actuators["Visibility"]
  573. wheel3act = wheel3.actuators["Visibility"]
  574. wheel4act = wheel4.actuators["Visibility"]
  575. if own['throw_deck'] == False:
  576. own['throw_deck'] = True
  577. deckact.visibility = False
  578. trucksact.visibility = False
  579. wheel1act.visibility = False
  580. wheel2act.visibility = False
  581. wheel3act.visibility = False
  582. wheel4act.visibility = False
  583. act = throw_deck_empty.actuators['throw_dec_act']
  584. if STANCE == True:
  585. act.linearVelocity = [0.0, 1.0, 1.0]
  586. if STANCE == False:
  587. act.linearVelocity = [0.0, 1.0, -1.0]
  588. cont.activate(act)
  589. else:
  590. own['throw_deck'] = False
  591. deckact.visibility = True
  592. trucksact.visibility = True
  593. wheel1act.visibility = True
  594. wheel2act.visibility = True
  595. wheel3act.visibility = True
  596. wheel4act.visibility = True
  597. throw_deck_empty['kill_deck'] = 1
  598. cont.activate(deck.actuators['Visibility'])
  599. cont.activate(trucks.actuators['Visibility'])
  600. cont.activate(wheel1.actuators['Visibility'])
  601. cont.activate(wheel2.actuators['Visibility'])
  602. cont.activate(wheel3.actuators['Visibility'])
  603. cont.activate(wheel4.actuators['Visibility'])
  604. def throwdeck(strength, ud):
  605. throw_deck_empty = scene.objects["throw_deck_empty"]
  606. deckact = deck.actuators["Visibility"]
  607. trucksact = trucks.actuators["Visibility"]
  608. wheel1act = wheel1.actuators["Visibility"]
  609. wheel2act = wheel2.actuators["Visibility"]
  610. wheel3act = wheel3.actuators["Visibility"]
  611. wheel4act = wheel4.actuators["Visibility"]
  612. if own['throw_deck'] == False:
  613. own['throw_deck'] = True
  614. deckact.visibility = False
  615. trucksact.visibility = False
  616. wheel1act.visibility = False
  617. wheel2act.visibility = False
  618. wheel3act.visibility = False
  619. wheel4act.visibility = False
  620. act = throw_deck_empty.actuators['throw_dec_act']
  621. hard = strength * .08
  622. if hard > 9:
  623. hard = 9
  624. if hard < 1:
  625. hard = 1
  626. ud = ud * 4
  627. own['bbut_timer'] = 0
  628. if STANCE == True:
  629. own['requestAction'] = 'fak_throw'
  630. act.linearVelocity = [0.0, ud, hard]
  631. if STANCE == False:
  632. own['requestAction'] = 'fak_throw'
  633. act.linearVelocity = [0.0, ud, -hard]
  634. cont.activate(act)
  635. else:
  636. own['throw_deck'] = False
  637. deckact.visibility = True
  638. trucksact.visibility = True
  639. wheel1act.visibility = True
  640. wheel2act.visibility = True
  641. wheel3act.visibility = True
  642. wheel4act.visibility = True
  643. throw_deck_empty['kill_deck'] = 1
  644. cont.activate(deck.actuators['Visibility'])
  645. cont.activate(trucks.actuators['Visibility'])
  646. cont.activate(wheel1.actuators['Visibility'])
  647. cont.activate(wheel2.actuators['Visibility'])
  648. cont.activate(wheel3.actuators['Visibility'])
  649. cont.activate(wheel4.actuators['Visibility'])
  650. def throwdeck_trigger():
  651. lastb = own['lastb']
  652. throw_deck_empty = scene.objects["throw_deck_empty"]
  653. if bBut == True:
  654. own['bbut_timer'] += 1
  655. ud = (rUD * 10) +1
  656. if bBut == False:
  657. throw_deck_empty['kill_deck'] = 0
  658. if bBut == False and own['lastb'] == True:
  659. strength = own['bbut_timer']
  660. ud = (rUD * 10) +1
  661. throwdeck(strength, ud)
  662. def focus_deck():
  663. since_air = own['framenum'] - own['lF_air_frame']
  664. if cb_td.positive and since_air < 10:
  665. print('focus!!!!!')
  666. object = 'focus_deckA'
  667. object2 = 'focus_deckB'
  668. other = throw_deck_empty
  669. throw_deck = scene.objects["throw_deck"]
  670. throw_deck.endObject()
  671. scene.addObject(object, other, 0)
  672. scene.addObject(object2, other, 0)
  673. if own['throw_deck'] == True:
  674. if dict['ldPad'] == False and dict['last_ldPad'] == True:
  675. #focus
  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. own['lF_ground_frame'] = own['framenum']
  999. onboard()
  1000. jump()
  1001. dropin()
  1002. throwdeck_trigger()
  1003. nextframe()
  1004. checkidle()
  1005. getonboard()
  1006. reset_pos()
  1007. switchcam()
  1008. move_flycam()
  1009. move_followcam()
  1010. fall()
  1011. idle_anim()
  1012. sit()
  1013. onground()
  1014. focus_deck()
  1015. #printplaying()
  1016. own.alignAxisToVect([0.0,0.0,1.0], 2, .03)
  1017. own.actuators["sroll"].stopSound()
  1018. wheel1 = scene.objects["rollen.000"]
  1019. wheel2 = scene.objects["rollen.001"]
  1020. wheel3 = scene.objects["rollen.002"]
  1021. wheel4 = scene.objects["rollen.003"]
  1022. wheel1.stopAction(2)
  1023. wheel2.stopAction(2)
  1024. wheel3.stopAction(2)
  1025. wheel4.stopAction(2)
  1026. own['lasty'] = yBut
  1027. own['lastb'] = bBut
  1028. own['lasta'] = aBut
  1029. own['lastx'] = xBut
  1030. own['lastlts'] = ltsBut
  1031. own['lastrts'] = rtsBut
  1032. own['lastbkBut'] = bkBut
  1033. own['dropinCol'] = dropinCol
  1034. own['walk'] = 1