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.

StatesPlayer.py 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. import bge
  2. dict = bge.logic.globalDict
  3. import sound_man
  4. #====================================
  5. State = type("State", (object,), {})
  6. #====================================
  7. class State(object):
  8. def __init__(self, FSM):
  9. self.FSM = FSM
  10. self.timer = 0
  11. self.startTime = 0
  12. def Enter(self):
  13. self.timer = 0
  14. self.startTime = 0
  15. def Execute(self):
  16. print('Executing')
  17. def Exit(self):
  18. print('Exiting')
  19. #====================================
  20. class Example(State):
  21. def __init__(self,FSM):
  22. super(Example, self).__init__(FSM)
  23. def Enter(self):
  24. self.FSM.stateLife = 1
  25. super(Example, self).Enter()
  26. def Execute(self):
  27. self.FSM.stateLife += 1
  28. #self.FSM.ToTransition('toExample')
  29. def Exit(self):
  30. pass
  31. #====================================
  32. class Startup(State):
  33. def __init__(self,FSM):
  34. super(Startup, self).__init__(FSM)
  35. def Enter(self):
  36. self.FSM.stateLife = 1
  37. super(Startup, self).Enter()
  38. def Execute(self):
  39. self.FSM.stateLife += 1
  40. if self.FSM.stateLife == 5:
  41. self.FSM.ToTransition('toWalk')
  42. print('player FSM')
  43. def Exit(self):
  44. pass
  45. #====================================
  46. class Walk(State):
  47. def __init__(self,FSM):
  48. super(Walk, self).__init__(FSM)
  49. def Enter(self):
  50. self.FSM.stateLife = 1
  51. o = self.FSM.owner.obj
  52. c = self.FSM.owner
  53. o['getoffboard'] = False
  54. o['getonboard'] = False
  55. if c.arm == None:
  56. c.arm = o.childrenRecursive['Char4']
  57. c.deck_arm = o.childrenRecursive['deck_arm']
  58. self.walk_weight = 1
  59. self.run_weight = 1
  60. self.run_speed = 0.0
  61. self.turn_weight = 0
  62. self.FSM.owner.walking = True
  63. dict['walking'] = True
  64. dict['walk'] = 1
  65. print('fsm enter walk')
  66. super(Walk, self).Enter()
  67. def Execute(self):
  68. self.FSM.stateLife += 1
  69. o = self.FSM.owner.obj
  70. c = self.FSM.owner
  71. #print(o.worldPosition.z)
  72. #print(o['getonboard'], 'dict onboard')
  73. #print(dict['walk'], 'fsm walk walk')
  74. # if self.FSM.stateLife == 2:
  75. # if o['stance']:
  76. # o.applyRotation([0,0,3.14], True)
  77. # o['stance'] = False
  78. # o['requestAction'] = 'fak_offboard'
  79. # print('request fak offboard')
  80. # else:
  81. # o['requestAction'] = 'reg_offboard'
  82. # print('request reg offboard')
  83. # if self.FSM.stateLife > 5:
  84. # o['requestAction'] = 'reg_idle'
  85. c.align_walk_z()
  86. ground_rays = c.get_ground_ray()
  87. #77777777777777777777777777777777777777777777777777777777777777777777777777777777777
  88. c.get_hang_align_ray()
  89. c.move_walk_cam()
  90. c.check_reset_point()
  91. c.check_throw()
  92. if ground_rays[0][0] != None:
  93. dist = c.get_ground_dist(ground_rays)
  94. if dist > .7:
  95. self.FSM.ToTransition('toWalkAir')
  96. #print('---falling')
  97. else:
  98. c.set_walk_z(dist)
  99. #print(dist, 'setting height')
  100. if self.FSM.stateLife > 4:
  101. self.check_onboard()
  102. self.check_jump()
  103. moving = c.walk_movement()
  104. self.get_walk_weight()
  105. self.idle_blend()
  106. else:
  107. dict['walk'] = 1
  108. def check_onboard(self):
  109. o = self.FSM.owner.obj
  110. #print(o['getonboard'], 'getonboard')
  111. if dict['walk'] == 0:
  112. o['getonboard'] = True
  113. #self.FSM.ToTransition('toRoll')
  114. self.FSM.ToTransition('toWalkOnboard')
  115. #print('onboard', dict['walk'], o['getonboard'])
  116. if dict['yBut'] == 1 and dict['last_yBut'] == 0:
  117. dropin = self.check_dropin()
  118. print('-----dropin', dropin)
  119. if dropin == None:
  120. o['getonboard'] = True
  121. self.FSM.ToTransition('toWalkOnboard')
  122. else:
  123. self.FSM.owner.dropin_obj = dropin
  124. self.FSM.ToTransition('toDropin')
  125. def check_dropin(self):
  126. dr = None
  127. ground_rays = self.FSM.owner.get_dropin_rays()
  128. for x in ground_rays:
  129. if x[0] != None:
  130. #print(x[0], '---checked')
  131. if 'coping' in x[0]:
  132. print('dropin collided')
  133. dr = x
  134. return dr
  135. def check_jump(self):
  136. if dict['xBut'] == True or dict['kb_space'] == 1:
  137. if dict['last_xBut'] == 0:
  138. self.FSM.ToTransition('toWalkJump')
  139. def idle_blend(self):
  140. arm = self.FSM.owner.arm
  141. deck = self.FSM.owner.deck_arm
  142. arm.playAction('reg_idle1', 1,120, layer=1, play_mode=1, speed=1, blendin=10)
  143. deck.playAction('b_reg_idle1', 1,120, layer=1, play_mode=1, speed=1, blendin=10)
  144. if self.FSM.stateLife > 20:
  145. frame = arm.getActionFrame(2) + .5 * self.run_speed
  146. if frame > 30:
  147. frame = 0
  148. arm.stopAction(2)
  149. deck.stopAction(2)
  150. arm.playAction('reg_nwalk3', 0,30, layer=2, play_mode=1, speed=self.run_speed, blendin=0, layer_weight=self.walk_weight)
  151. deck.playAction('b_reg_walk', 0,30, layer=2, play_mode=1, speed=self.run_speed, blendin=0, layer_weight=self.walk_weight)
  152. #b_reg_walk
  153. arm.setActionFrame(frame, 2)
  154. deck.setActionFrame(frame, 2)
  155. #print(self.walk_weight, frame)
  156. frame = arm.getActionFrame(3) + .5 * self.run_speed
  157. if frame > 30:
  158. frame = 0
  159. arm.stopAction(3)
  160. deck.stopAction(3)
  161. arm.playAction('reg_run.003', 0,30, layer=3, play_mode=1, speed=self.run_speed, blendin=0, layer_weight=self.run_weight)
  162. deck.playAction('b_reg_run', 0,30, layer=3, play_mode=1, speed=self.run_speed, blendin=0, layer_weight=self.run_weight)
  163. arm.setActionFrame(frame, 3)
  164. deck.setActionFrame(frame, 3)
  165. #print(frame, 'frame')
  166. #print(self.run_weight, frame)
  167. # if self.turn_weight > 0:
  168. # tw = abs(self.turn_weight - 1)
  169. # #tw = self.turn_weight
  170. # arm.stopAction(4)
  171. # arm.playAction('bwalk_right', 1,60, layer=4, play_mode=1, speed=self.run_speed, blendin=0, layer_weight=tw)
  172. # elif self.turn_weight < 0:
  173. # tw = abs(abs(self.turn_weight) - 1)
  174. # #tw = self.turn_weight
  175. # arm.stopAction(4)
  176. # arm.playAction('bwalk_left', 1,60, layer=4, play_mode=1, speed=self.run_speed, blendin=0, layer_weight=tw)
  177. #print('walk_weight', self.walk_weight)
  178. if self.walk_weight < .8:
  179. if frame > 15:
  180. if self.FSM.owner.step == False:
  181. self.FSM.owner.step = True
  182. if frame < 23:
  183. print('step left')
  184. dict['camera']['sndmgr'].queue_sound(['s_l_1', self.FSM.owner.obj, dict['camera']])
  185. else:
  186. if self.FSM.owner.step == True:
  187. self.FSM.owner.step = False
  188. if frame < 8:
  189. dict['camera']['sndmgr'].queue_sound(['s_r_1', self.FSM.owner.obj, dict['camera']])
  190. print('step right')
  191. # if frame > 15 and self.FSM.owner.step:
  192. # self.FSM.owner.step = True
  193. # print('step left')
  194. # if frame < 15 and not self.FSM.owner.step:
  195. # self.FSM.owner.step = False
  196. # print('step right')
  197. #print('frame', frame)
  198. def get_walk_weight(self):
  199. #print(self.FSM.owner.linearVelocity.y)
  200. o = self.FSM.owner.obj
  201. w = abs(o.linearVelocity.x)
  202. #wt = 3.5
  203. #yt = 8
  204. wt = 1.7
  205. yt = 3
  206. out2 = 0
  207. if w < wt:
  208. out = w / wt
  209. else:
  210. out = 1
  211. #print('running', w)
  212. out2 = w / yt
  213. out = abs(1 - out)
  214. out2 = abs(1 - out2)
  215. tgww = round(out, 3)
  216. tgrw = round(out2, 3)
  217. incer = .05
  218. if self.walk_weight < tgww:
  219. self.walk_weight += incer
  220. if self.walk_weight > tgww:
  221. self.walk_weight -= incer
  222. if self.run_weight <= tgrw:
  223. self.run_weight += incer
  224. if self.run_weight > tgrw:
  225. self.run_weight -= incer
  226. if self.walk_weight <= 0:
  227. self.walk_weight = 0
  228. if self.walk_weight > .95:
  229. self.walk_weight = 1
  230. if self.run_weight <= 0:
  231. self.run_weight = 0
  232. if self.run_weight > .95:
  233. self.run_weight = 1
  234. if dict['kb_lsh'] == 2 or dict['aBut'] == 1:
  235. self.run_speed = 1.3
  236. else:
  237. self.run_speed = .8
  238. #print(self.run_speed, '---', self.walk_weight, 'walk weight', self.run_weight, 'run weight')
  239. def Exit(self):
  240. self.FSM.owner.arm.stopAction(0)
  241. self.FSM.owner.arm.stopAction(1)
  242. self.FSM.owner.arm.stopAction(2)
  243. self.FSM.owner.arm.stopAction(3)
  244. self.FSM.owner.deck_arm.stopAction(0)
  245. self.FSM.owner.deck_arm.stopAction(1)
  246. self.FSM.owner.deck_arm.stopAction(2)
  247. self.FSM.owner.deck_arm.stopAction(3)
  248. dict['walk'] = 0
  249. #====================================
  250. class WalkAir(State):
  251. def __init__(self,FSM):
  252. super(WalkAir, self).__init__(FSM)
  253. def Enter(self):
  254. self.FSM.stateLife = 1
  255. super(WalkAir, self).Enter()
  256. def Execute(self):
  257. self.FSM.stateLife += 1
  258. self.FSM.owner.check_reset_point()
  259. arm = self.FSM.owner.arm
  260. deck_arm = self.FSM.owner.deck_arm
  261. #arm.playAction('a_jump_t', 23, 23, layer=3, play_mode=1, speed=1, blendin=5)
  262. arm.playAction('c_jump_up', 23, 23, layer=3, play_mode=1, speed=1, blendin=15)
  263. deck_arm.playAction('b_walk_jump', 23, 23, layer=3, play_mode=1, speed=1, blendin=15)
  264. if self.FSM.owner.obj.linearVelocity.z < -10:
  265. self.FSM.owner.obj.linearVelocity.z = -10
  266. moving = self.FSM.owner.walk_movement()
  267. ground_rays = self.FSM.owner.get_ground_ray()
  268. self.FSM.owner.check_throw()
  269. self.check_onboard()
  270. self.FSM.owner.align_walk_z()
  271. if ground_rays[0][0] != None:
  272. dist = self.FSM.owner.get_ground_dist(ground_rays)
  273. if dist < .4:
  274. self.FSM.ToTransition('toWalkLand')
  275. if dist > .5 and self.FSM.owner.obj.worldPosition.z < self.FSM.owner.last_pos.z:
  276. hang_ray = self.FSM.owner.get_hang_ray()
  277. hang_align_ray = self.FSM.owner.get_hang_align_ray()
  278. if hang_ray[0] != None and hang_align_ray[0] != None and self.FSM.prevState != 'WalkHang' and dict['lUD'] < .04:
  279. hr_dist = self.FSM.owner.get_hang_dist(hang_ray)
  280. if hr_dist < .1:
  281. self.FSM.owner.obj.linearVelocity = [0,0,0]
  282. self.FSM.owner.obj.worldPosition.z = hang_ray[1].z - 1
  283. self.FSM.ToTransition('toWalkHang')
  284. def check_onboard(self):
  285. o = self.FSM.owner.obj
  286. # if dict['walk'] == 0:
  287. # o['getonboard'] = True
  288. # self.FSM.ToTransition('toWalkOnboard')
  289. if dict['yBut'] == 1 and dict['last_yBut'] == 0:
  290. o['getonboard'] = True
  291. #self.FSM.ToTransition('toWalkOnboard')
  292. self.FSM.ToTransition('toAirOnboard')
  293. def Exit(self):
  294. self.FSM.owner.arm.stopAction(0)
  295. self.FSM.owner.arm.stopAction(1)
  296. self.FSM.owner.arm.stopAction(2)
  297. self.FSM.owner.arm.stopAction(3)
  298. self.FSM.owner.deck_arm.stopAction(0)
  299. self.FSM.owner.deck_arm.stopAction(1)
  300. self.FSM.owner.deck_arm.stopAction(2)
  301. self.FSM.owner.deck_arm.stopAction(3)
  302. #====================================
  303. class WalkJump(State):
  304. def __init__(self,FSM):
  305. super(WalkJump, self).__init__(FSM)
  306. def Enter(self):
  307. self.FSM.stateLife = 1
  308. dict['camera']['sndmgr'].queue_sound(['walk_grunt', self.FSM.owner.obj, dict['camera']])
  309. arm = self.FSM.owner.arm
  310. deck = self.FSM.owner.deck_arm
  311. #arm.playAction('a_jump_t', 1, 23, layer=3, play_mode=0, speed=1, blendin=5)
  312. arm.playAction('c_jump_up', 1, 23, layer=3, play_mode=0, speed=1, blendin=5)
  313. deck.playAction('b_walk_jump', 1, 23, layer=3, play_mode=0, speed=1, blendin=5)
  314. super(WalkJump, self).Enter()
  315. def Execute(self):
  316. self.FSM.stateLife += 1
  317. arm = self.FSM.owner.arm
  318. o = self.FSM.owner.obj
  319. moving = self.FSM.owner.walk_movement()
  320. self.check_onboard()
  321. if self.FSM.stateLife == 10:
  322. force = [ 0.0, 0.0, dict['walk_jump_force']]
  323. if o.linearVelocity.z < 10:
  324. o.applyForce(force, True)
  325. if self.FSM.stateLife > 27:
  326. self.FSM.ToTransition('toWalkAir')
  327. def check_onboard(self):
  328. o = self.FSM.owner.obj
  329. # if dict['walk'] == 0:
  330. # o['getonboard'] = True
  331. # self.FSM.ToTransition('toWalkOnboard')
  332. if dict['yBut'] == 1 and dict['last_yBut'] == 0:
  333. o['getonboard'] = True
  334. self.FSM.ToTransition('toAirOnboard')
  335. def Exit(self):
  336. pass
  337. #====================================
  338. class WalkLand(State):
  339. def __init__(self,FSM):
  340. super(WalkLand, self).__init__(FSM)
  341. def Enter(self):
  342. self.FSM.stateLife = 1
  343. #self.FSM.owner.arm.playAction('a_jump_t', 23, 50, layer=5, play_mode=0, speed=1, blendin=5)
  344. self.FSM.owner.arm.playAction('c_land', 0, 50, layer=1, play_mode=0, speed=1, blendin=5)
  345. self.FSM.owner.deck_arm.playAction('b_walk_land', 0, 50, layer=1, play_mode=0, speed=1, blendin=5)
  346. dict['camera']['sndmgr'].queue_sound(['walk_land', self.FSM.owner.obj, dict['camera']])
  347. #c_land
  348. super(WalkLand, self).Enter()
  349. def Execute(self):
  350. self.FSM.stateLife += 1
  351. self.FSM.owner.obj.linearVelocity.x *= .8
  352. self.FSM.owner.obj.linearVelocity.y *= .8
  353. # arm = self.FSM.owner.arm
  354. # print('af', arm.getActionFrame(5))
  355. # if arm.getActionFrame(5) > 30:
  356. # print('stopping land')
  357. # arm.stopAction(5)
  358. # arm.playAction('reg_idle1', 1,120, layer=1, play_mode=1, speed=1, blendin=2)
  359. if self.FSM.stateLife > 30:
  360. self.FSM.ToTransition('toWalk')
  361. ground_rays = self.FSM.owner.get_ground_ray()
  362. if ground_rays[0][0] != None:
  363. dist = self.FSM.owner.get_ground_dist(ground_rays)
  364. self.FSM.owner.set_walk_z(dist)
  365. def Exit(self):
  366. pass
  367. #====================================
  368. class WalkHang(State):
  369. def __init__(self,FSM):
  370. super(WalkHang, self).__init__(FSM)
  371. def Enter(self):
  372. self.FSM.stateLife = 1
  373. self.FSM.owner.arm.playAction('c_braced_hang', 0, 36, layer=2, play_mode=0, speed=1, blendin=10)
  374. self.moveable = False
  375. dict['camera']['sndmgr'].queue_sound(['walk_hang', self.FSM.owner.obj, dict['camera']])
  376. self.FSM.owner.drop_deck()
  377. #self.FSM.owner.arm.playAction('c_braced_hang', 36, 50, layer=1, play_mode=1, speed=1, blendin=10)
  378. super(WalkHang, self).Enter()
  379. def Execute(self):
  380. self.FSM.stateLife += 1
  381. self.FSM.owner.obj.linearVelocity = [0,0,0]
  382. #self.FSM.owner.arm.playAction('c_braced_hang', 0, 36, layer=2, play_mode=0, speed=1, blendin=10)
  383. self.FSM.owner.arm.playAction('c_braced_hang', 36, 50, layer=1, play_mode=1, speed=1, blendin=10)
  384. if dict['lUD'] > .04:
  385. self.FSM.ToTransition('toWalkAir')
  386. self.FSM.owner.move_walk_cam()
  387. if self.FSM.stateLife > 25:
  388. self.moveable = True
  389. if self.moveable:
  390. if dict['lUD'] < -.04:
  391. self.FSM.ToTransition('toWalkClimb')
  392. self.FSM.owner.hang_move()
  393. ground_rays = self.FSM.owner.get_ground_ray()
  394. if ground_rays[0][0] != None:
  395. dist = self.FSM.owner.get_ground_dist(ground_rays)
  396. if dist < .4:
  397. self.FSM.ToTransition('toWalkLand')
  398. hang_ray = self.FSM.owner.get_hang_ray()
  399. hang_align_ray = self.FSM.owner.get_hang_align_ray()
  400. #print(hang_align_ray, 'hang_align_ray')
  401. #self.FSM.owner.hang_move()
  402. if hang_ray[0] != None:
  403. hr_dist = self.FSM.owner.get_hang_dist(hang_ray)
  404. #print(hr_dist, 'hang dist')
  405. if hr_dist < .5:
  406. self.FSM.owner.obj.linearVelocity = [0,0,0]
  407. self.FSM.owner.obj.worldPosition.z = hang_ray[1].z - 1
  408. if hang_align_ray[0] != None:
  409. #print(hang_align_ray[0])
  410. v = hang_align_ray[2]
  411. self.FSM.owner.obj.alignAxisToVect(v, 0, .5)
  412. else:
  413. self.FSM.ToTransition('toWalkAir')
  414. if hang_align_ray[0] == None:
  415. self.FSM.ToTransition('toWalkAir')
  416. self.FSM.owner.align_walk_z()
  417. def Exit(self):
  418. pass
  419. #====================================
  420. class WalkClimb(State):
  421. def __init__(self,FSM):
  422. super(WalkClimb, self).__init__(FSM)
  423. def Enter(self):
  424. self.FSM.stateLife = 1
  425. self.FSM.owner.arm.playAction('c_wallclimb', 1, 50, layer=3, play_mode=0, speed=1, blendin=10)
  426. dict['camera']['sndmgr'].queue_sound(['walk_climb', self.FSM.owner.obj, dict['camera']])
  427. super(WalkClimb, self).Enter()
  428. def Execute(self):
  429. self.FSM.stateLife += 1
  430. #self.FSM.ToTransition('toLand')
  431. if self.FSM.stateLife > 25:
  432. self.FSM.owner.obj.applyForce([-300, 0, 80], True)
  433. else:
  434. self.FSM.owner.obj.applyForce([-20, 0, 80], True)
  435. if self.FSM.stateLife > 35:
  436. self.FSM.ToTransition('toWalkLand')
  437. def Exit(self):
  438. pass
  439. #====================================
  440. class WalkHurdle(State):
  441. def __init__(self,FSM):
  442. super(WalkHurdle, self).__init__(FSM)
  443. def Enter(self):
  444. self.FSM.stateLife = 1
  445. super(WalkHurdle, self).Enter()
  446. def Execute(self):
  447. self.FSM.stateLife += 1
  448. #self.FSM.ToTransition('toLand')
  449. def Exit(self):
  450. pass
  451. #====================================
  452. class WalkOnboard(State):
  453. def __init__(self,FSM):
  454. super(WalkOnboard, self).__init__(FSM)
  455. def Enter(self):
  456. self.FSM.stateLife = 1
  457. self.FSM.owner.walking = False
  458. self.FSM.owner.obj['getonboard'] = False
  459. if self.FSM.owner.throw_deck != None:
  460. self.FSM.owner.throw_deck.endObject()
  461. self.FSM.owner.throw_deck = None
  462. self.FSM.owner.show_deck()
  463. dict['walking'] = False
  464. self.FSM.owner.obj['walking'] = False
  465. self.FSM.owner.obj['requestAction'] = 'reg_onboard'
  466. self.FSM.owner.obj['getoffboard'] == False
  467. self.FSM.owner.obj.applyForce([-300, 0, 0], True)
  468. print('walkonboard entered')
  469. super(WalkOnboard, self).Enter()
  470. def Execute(self):
  471. self.FSM.stateLife += 1
  472. self.FSM.ToTransition('toRoll')
  473. def Exit(self):
  474. pass
  475. #====================================
  476. class AirOnboard(State):
  477. def __init__(self,FSM):
  478. super(AirOnboard, self).__init__(FSM)
  479. def Enter(self):
  480. self.FSM.stateLife = 1
  481. self.FSM.owner.walking = False
  482. self.FSM.owner.obj['getonboard'] = False
  483. if self.FSM.owner.throw_deck != None:
  484. self.FSM.owner.throw_deck.endObject()
  485. self.FSM.owner.throw_deck = None
  486. self.FSM.owner.show_deck()
  487. dict['walking'] = False
  488. self.FSM.owner.obj['walking'] = False
  489. #self.FSM.owner.obj['requestAction'] = 'reg_onboard'
  490. self.FSM.owner.arm.playAction('c_land', 0, 50, layer=1, play_mode=0, speed=1, blendin=5)
  491. self.FSM.owner.deck_arm.playAction('b_walk_land', 0, 50, layer=1, play_mode=0, speed=1, blendin=5)
  492. self.FSM.owner.obj['getoffboard'] == False
  493. self.FSM.owner.obj.applyForce([-300, 0, 0], True)
  494. print('air entered')
  495. super(AirOnboard, self).Enter()
  496. def Execute(self):
  497. self.FSM.stateLife += 1
  498. print('@@@@@@@@@@@@@@@@@@@@@@@@@@@air ob')
  499. self.FSM.ToTransition('toRoll')
  500. def Exit(self):
  501. pass
  502. #====================================
  503. class Roll(State):
  504. def __init__(self,FSM):
  505. super(Roll, self).__init__(FSM)
  506. def Enter(self):
  507. self.FSM.stateLife = 1
  508. # self.FSM.owner.obj['getoffboard'] == False
  509. # dict['walk'] = 0
  510. print('roll entered')
  511. super(Roll, self).Enter()
  512. def Execute(self):
  513. self.FSM.stateLife += 1
  514. if dict['walk'] == 1 or self.FSM.owner.obj['getoffboard'] == True:
  515. dict['walk'] = 1
  516. self.FSM.owner.obj['getoffboard'] = True
  517. #self.FSM.ToTransition('toWalk')
  518. self.FSM.ToTransition('toOffboard')
  519. print('fsm to walk', dict['walk'], self.FSM.owner.obj['getoffboard'])
  520. if self.FSM.owner.obj['fall'] == True:
  521. self.FSM.ToTransition('toRagdoll')
  522. #print('rolling')
  523. #self.FSM.ToTransition('toLand')
  524. def Exit(self):
  525. pass
  526. #====================================
  527. class Offboard(State):
  528. def __init__(self,FSM):
  529. super(Offboard, self).__init__(FSM)
  530. def Enter(self):
  531. self.FSM.stateLife = 1
  532. o = self.FSM.owner.obj
  533. if o['stance']:
  534. o.applyRotation([0,0,3.14], True)
  535. o['stance'] = False
  536. self.FSM.owner.arm.playAction('fak_noffboard', 0,24, layer=2, play_mode=0, speed=1, blendin=0)
  537. self.FSM.owner.deck_arm.playAction('b_reg_offboard', 0,30, layer=2, play_mode=0, speed=1, blendin=0)
  538. else:
  539. self.FSM.owner.arm.playAction('reg_noffboard', 0,40, layer=2, play_mode=0, speed=1, blendin=0)
  540. self.FSM.owner.deck_arm.playAction('b_reg_offboard', 0,40, layer=2, play_mode=0, speed=1, blendin=0)
  541. print('fsm getting off board')
  542. super(Offboard, self).Enter()
  543. def Execute(self):
  544. self.FSM.stateLife += 1
  545. self.FSM.ToTransition('toWalk')
  546. def Exit(self):
  547. pass
  548. #====================================
  549. class Ragdoll(State):
  550. def __init__(self,FSM):
  551. super(Ragdoll, self).__init__(FSM)
  552. def Enter(self):
  553. self.FSM.stateLife = 1
  554. self.FSM.owner.obj['ragdoll_active'] = True
  555. self.FSM.owner.drop_deck()
  556. print('ragdoll_player_fsm entered')
  557. super(Ragdoll, self).Enter()
  558. def Execute(self):
  559. self.FSM.stateLife += 1
  560. print('ragdolling')
  561. if dict['yBut'] == 1:
  562. self.FSM.owner.obj['fall'] = False
  563. self.FSM.owner.cont.activate(self.FSM.owner.cont.actuators['walk'])
  564. #self.FSM.ToTransition('toWalk')
  565. self.FSM.ToTransition('toOffboard')
  566. self.FSM.owner.move_walk_cam()
  567. def Exit(self):
  568. print('ragdoll_player_fsm exited')
  569. self.FSM.owner.obj['ragdoll_active'] = False
  570. #pass
  571. #====================================
  572. class Dropin(State):
  573. def __init__(self,FSM):
  574. super(Dropin, self).__init__(FSM)
  575. def Enter(self):
  576. self.FSM.stateLife = 1
  577. if self.FSM.owner.throw_deck != None:
  578. self.FSM.owner.throw_deck.endObject()
  579. self.FSM.owner.throw_deck = None
  580. self.FSM.owner.show_deck()
  581. self.FSM.owner.arm.playAction('reg_dropin3', 30, 50, layer=2, play_mode=0, speed=1, blendin=5)
  582. self.FSM.owner.deck_arm.playAction('b_reg_dropin', 30, 50, layer=2, play_mode=0, speed=1, blendin=5)
  583. self.out_triggered = False
  584. # #player armature action name, start, end frames
  585. # 'reg_dropin3', 30, 50,
  586. # #deck action name, start, end frames
  587. # 'b_reg_dropin', 30, 50,
  588. # #layer, speed, mode (0 = play, 1 = loop), blendin
  589. # 1, .5, 0, 15,
  590. # #intro, length
  591. super(Dropin, self).Enter()
  592. def Execute(self):
  593. self.FSM.stateLife += 1
  594. print('dropin')
  595. eu = self.FSM.owner.get_vert_rot(self.FSM.owner.obj, self.FSM.owner.dropin_obj[0])
  596. #print(eu, 'eu')
  597. self.FSM.owner.arm.playAction('reg_dropin3', 50, 50, layer=1, play_mode=1, speed=1, blendin=5)
  598. self.FSM.owner.deck_arm.playAction('b_reg_dropin', 50, 50, layer=1, play_mode=1, speed=1, blendin=5)
  599. if dict['last_yBut'] == True and dict['yBut'] == False:
  600. self.out_triggered = True
  601. if self.out_triggered:
  602. self.FSM.owner.arm.playAction('reg_dropin3', 60, 80, layer=2, play_mode=0, speed=1, blendin=5)
  603. self.FSM.owner.deck_arm.playAction('b_reg_dropin', 60, 80, layer=2, play_mode=0, speed=1, blendin=5)
  604. self.FSM.owner.obj.applyForce([-15, 0, 0], True)
  605. self.FSM.owner.obj.applyRotation([0, -.01, 0], True)
  606. else:
  607. self.FSM.owner.move_to_te()
  608. if self.FSM.owner.arm.getActionFrame(2)> 78:
  609. self.FSM.ToTransition('toRoll')
  610. self.FSM.owner.move_walk_cam()
  611. def Exit(self):
  612. self.FSM.owner.obj['getonboard'] = True
  613. self.FSM.owner.walking = False
  614. #self.FSM.owner.obj['getonboard'] = False
  615. dict['walking'] = False
  616. self.FSM.owner.obj['walking'] = False
  617. self.FSM.owner.obj['requestAction'] = 'reg_air'
  618. self.FSM.owner.obj['getoffboard'] == False
  619. #====================================