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

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