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

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