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.

actionPlayer.py 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. import bge
  2. import actionsFSMlist
  3. import mathutils
  4. dict = bge.logic.globalDict
  5. zero_blend = False
  6. state_a = ['reg_idle',
  7. 'reg_idle2',
  8. 'reg_idle3',
  9. 'reg_idle4',
  10. 'reg_idle5',
  11. 'reg_idle6',
  12. 'reg_idle7',
  13. 'reg_roll',
  14. 'reg_turnLeft',
  15. 'reg_turnRight',
  16. 'reg_manual_left',
  17. 'reg_manual_right',
  18. 'reg_nmanual_left',
  19. 'reg_nmanual_right',
  20. 'reg_opos',
  21. 'reg_nopos',
  22. 'reg_pump',
  23. 'reg_pump_left',
  24. 'reg_pump_right',
  25. 'reg_manual',
  26. 'reg_nmanual',
  27. 'reg_air',
  28. 'reg_air_nb',
  29. 'reg_air_nose',
  30. 'reg_air_tail',
  31. 'reg_5050',
  32. 'reg_bsboard',
  33. 'reg_fsboard',
  34. 'reg_tailg',
  35. 'reg_tailgr',
  36. 'reg_tailgl',
  37. 'reg_noseg',
  38. 'reg_nosegr',
  39. 'reg_nosegl',
  40. 'reg_tailslide',
  41. 'reg_noseslide',
  42. 'fak_idle',
  43. 'fak_idle2',
  44. 'fak_idle3',
  45. 'fak_idle4',
  46. 'fak_idle5',
  47. 'fak_idle6',
  48. 'fak_idle7',
  49. 'fak_roll',
  50. 'fak_turnLeft',
  51. 'fak_turnRight',
  52. 'fak_manual_left',
  53. 'fak_manual_right',
  54. 'fak_nmanual_left',
  55. 'fak_nmanual_right',
  56. 'fak_opos',
  57. 'fak_nopos',
  58. 'fak_pump',
  59. 'fak_pump_left',
  60. 'fak_pump_right',
  61. 'fak_manual',
  62. 'fak_nmanual',
  63. 'fak_air',
  64. 'fak_air_nb',
  65. 'fak_air_nose',
  66. 'fak_air_tail',
  67. 'fak_5050',
  68. 'fak_bsboard',
  69. 'fak_fsboard',
  70. 'fak_tailg',
  71. 'fak_tailgr',
  72. 'fak_tailgl',
  73. 'fak_noseg',
  74. 'fak_nosegr',
  75. 'fak_nosegl',
  76. 'fak_tailslide',
  77. 'fak_noseslide',
  78. 'reg_ollie',
  79. 'reg_kickflip',
  80. 'reg_heelflip',
  81. 'reg_shuvit',
  82. 'reg_shuvit360',
  83. 'reg_fsshuvit',
  84. 'reg_fsshuvit360',
  85. 'reg_nollie',
  86. 'reg_nollie_kickflip',
  87. 'reg_nollie_heelflip',
  88. 'reg_nollie_shuvit',
  89. 'reg_nollie_fsshuvit',
  90. 'reg_nollie_shuvit360',
  91. 'reg_nollie_fsshuvit_360',
  92. 'reg_hardflip',
  93. 'reg_inward_heelflip',
  94. 'reg_varial_kickflip',
  95. 'reg_varial_heelflip',
  96. 'fak_ollie',
  97. 'fak_kickflip',
  98. 'fak_heelflip',
  99. 'fak_shuvit',
  100. 'fak_shuvit360',
  101. 'fak_fsshuvit',
  102. 'fak_fsshuvit360',
  103. 'fak_nollie',
  104. 'fak_nollie_kickflip',
  105. 'fak_nollie_heelflip',
  106. 'fak_nollie_shuvit',
  107. 'fak_nollie_fsshuvit',
  108. 'fak_nollie_shuvit360',
  109. 'fak_nollie_fsshuvit_360',
  110. 'fak_hardflip',
  111. 'fak_inward_heelflip',
  112. 'fak_varial_kickflip',
  113. 'fak_varial_heelflip',
  114. 'frontside_grab',
  115. 'backside_grab',
  116. 'frontside_nose_grab',
  117. 'backside_nose_grab',
  118. 'frontside_tail_grab',
  119. 'backside_tail_grab',
  120. 'reg_ollie_north',
  121. 'reg_ollie_south',
  122. 'reg_judo',
  123. 'reg_frigid',
  124. 'reg_fsonefoot',
  125. 'reg_onefoot',
  126. 'reg_airwalk',
  127. 'reg_wall_r',
  128. 'reg_wall_l',
  129. 'fak_frontside_grab',
  130. 'fak_backside_grab',
  131. 'fak_frontside_nose_grab',
  132. 'fak_backside_nose_grab',
  133. 'fak_frontside_tail_grab',
  134. 'fak_backside_tail_grab',
  135. 'fak_ollie_north',
  136. 'fak_ollie_south',
  137. 'fak_judo',
  138. 'fak_frigid',
  139. 'fak_fsonefoot',
  140. 'fak_onefoot',
  141. 'reg_back_invert']
  142. state_b = ['reg_jump',
  143. 'reg_walk_air',
  144. 'reg_walk_air_out',
  145. 'reg_onboard',
  146. 'reg_offboard',
  147. 'reg_brfoot',
  148. 'reg_frfoot',
  149. 'reg_blfoot',
  150. 'reg_flfoot',
  151. 'reg_land',
  152. 'reg_landL',
  153. 'reg_landLb',
  154. 'reg_landR',
  155. 'reg_landRb',
  156. 'revert1',
  157. 'revert2',
  158. 'fak_revert1',
  159. 'fak_revert2',
  160. 'revert3',
  161. 'revert4',
  162. 'fak_jump',
  163. 'fak_walk_air',
  164. 'fak_walk_air_out',
  165. 'fak_onboard',
  166. 'fak_offboard',
  167. 'fak_brfoot',
  168. 'fak_frfoot',
  169. 'fak_blfoot',
  170. 'fak_flfoot',
  171. 'fak_land',
  172. 'fak_landL',
  173. 'fak_landLb',
  174. 'fak_landR',
  175. 'fak_landRb']
  176. def actionPlayer(ac):
  177. scene = bge.logic.getCurrentScene()
  178. cont = bge.logic.getCurrentController()
  179. own = cont.owner
  180. skater = dict['p1']
  181. deck = dict['p1d']
  182. a = getattr(actionsFSMlist.reg_walk, 'name')
  183. name = getattr(ac, 'name')
  184. dname = getattr(ac, 'dname')
  185. start = getattr(ac, 'start')
  186. end = getattr(ac, 'end')
  187. dstart = getattr(ac, 'dstart')
  188. dend = getattr(ac, 'dend')
  189. layer = getattr(ac, 'layer')
  190. mode = getattr(ac, 'mode')
  191. speed = getattr(ac, 'speed')
  192. blendin = getattr(ac, 'blendin')
  193. #--------------------------------
  194. #if zero_blend:
  195. # if own['l_actionState'] != None and own['l_actionState'] in 'revert1':
  196. # blendin = 0
  197. # print('zeroing blend')
  198. skater.playAction(name, start,end, layer=layer, play_mode=mode, speed=speed, blendin=blendin)
  199. deck.playAction(dname, dstart,dend, layer=layer, play_mode=mode, speed=speed, blendin=blendin)
  200. #print('playing', name, get_frame(ac))
  201. #if skater.isPlayingAction(3):
  202. #print(skater.getActionFrame(3))
  203. def get_frame(ac):
  204. skater = dict['p1']
  205. layer = getattr(ac, 'layer')
  206. #print('getting frame', skater.getActionFrame(layer))
  207. return skater.getActionFrame(layer)
  208. def set_frame(ac, frame):
  209. skater = dict['p1']
  210. deck = dict['p1d']
  211. layer = getattr(ac, 'layer')
  212. skater.setActionFrame(frame, layer)
  213. deck.setActionFrame(frame, layer)
  214. #print('setting frame', frame)
  215. def check_exit(aState, rA, timer, ac):
  216. exits = getattr(ac, 'exits')
  217. force = getattr(ac, 'force_exit')
  218. fe = getattr(ac, 'fef')
  219. rv = ''
  220. #print('rA, aState', rA, aState, force, fe, timer)
  221. if rA in exits:
  222. rv = rA
  223. #
  224. elif ('fak' in rA and 'reg' in aState) or ('reg' in rA and 'fak' in aState):
  225. #print('change stance')
  226. if getattr(ac, 'opposite') != None:
  227. rv = getattr(ac, 'opposite')
  228. else:
  229. rv = aState
  230. if force != None and fe >= timer:
  231. print('doing exit timer')
  232. rv = force
  233. return rv
  234. def state_timer(own):
  235. if own['aState'] == own['l_aState']:
  236. own['stateTimer'] += 1
  237. else:
  238. own['stateTimer'] = 0
  239. def check_land(rA, aState, own):
  240. #check if manualling
  241. if rA in actionsFSMlist.reg_manuallist or rA in actionsFSMlist.reg_grindlist or rA in actionsFSMlist.fak_grindlist:
  242. #if rA in actionsFSMlist.reg_manuallist or rA in actionsFSMlist.fak_grindlist:
  243. aState = rA
  244. #own['stateTimer'] = 0
  245. own['aState'] = rA
  246. #otherwise, force land, offboard or fliptrick
  247. elif 'land' in rA or 'onboard' in rA or 'offboard' in rA or rA in actionsFSMlist.reg_fliplist or rA in actionsFSMlist.fak_fliplist or rA in actionsFSMlist.revertlist:
  248. #print('landing________________________', rA)
  249. aState = rA
  250. own['stateTimer'] = 0
  251. own['aState'] = rA
  252. #print(own['stance'], '-----stance', rA)
  253. return aState
  254. def main(cont):
  255. own = cont.owner
  256. dict = bge.logic.globalDict
  257. #initial state
  258. if 'aState' not in own:
  259. own['aState'] = 'reg_idle'
  260. own['l_aState'] = None
  261. own['stateTimer'] = 0
  262. aState = own['aState']
  263. rA = own['requestAction']
  264. timer = own['stateTimer']
  265. newState = own['aState']
  266. aState = check_land(rA, aState, own)
  267. newState = aState
  268. og_state = own['aState']
  269. #print(aState)
  270. if aState in state_a:
  271. action = getattr(actionsFSMlist, aState)
  272. if own['stateTimer'] < getattr(action, 'intro_frames'):
  273. intro = getattr(action, 'intro')
  274. actionPlayer(getattr(actionsFSMlist, intro))
  275. else:
  276. actionPlayer(action)
  277. newState = check_exit(aState, rA, timer, action)
  278. if aState == 'reg_back_invert':
  279. print('fffffffffffffffffffffffffffffffff')
  280. elif aState in state_b:
  281. action = getattr(actionsFSMlist, aState)
  282. actionPlayer(action)
  283. if own['stateTimer'] > getattr(action, 'fef'):
  284. newState = check_exit(aState, rA, timer, action)
  285. ###################################
  286. check_state = 'reg_sit'
  287. if aState == check_state:
  288. action = getattr(actionsFSMlist, check_state)
  289. #if own['stateTimer'] < 19:
  290. if own['stateTimer'] < getattr(action, 'intro_frames'):
  291. actionPlayer(getattr(actionsFSMlist, 'intro'))
  292. else:
  293. actionPlayer(action)
  294. newState = check_exit(aState, rA, timer, actionsFSMlist.reg_sit)
  295. #-----------------------
  296. check_state = 'reg_walk'
  297. if aState == check_state:
  298. action = getattr(actionsFSMlist, check_state)
  299. if own['l_aState'] == 'reg_walkFast':
  300. frame = get_frame(actionsFSMlist.reg_walkFast)
  301. actionPlayer(action)
  302. set_frame(actionsFSMlist.reg_walk, frame)
  303. else:
  304. frame = actionPlayer(action)
  305. newState = check_exit(aState, rA, timer, action)
  306. #-----------------------
  307. check_state = 'reg_walkFast'
  308. if aState == check_state:
  309. action = getattr(actionsFSMlist, check_state)
  310. newState = check_exit(aState, rA, timer, actionsFSMlist.reg_walkFast)
  311. if own['l_aState'] == 'reg_walk':
  312. frame = get_frame(actionsFSMlist.reg_walk)
  313. actionPlayer(action)
  314. set_frame(actionsFSMlist.reg_walkFast, frame)
  315. else:
  316. actionPlayer(action)
  317. check_state = 'reg_push'
  318. if aState == check_state:
  319. action = getattr(actionsFSMlist, check_state)
  320. actionPlayer(action)
  321. if own['stateTimer'] > 70:
  322. newState = 'reg_roll'
  323. check_state = 'reg_push_goof'
  324. if aState == check_state:
  325. action = getattr(actionsFSMlist, check_state)
  326. actionPlayer(action)
  327. if own['stateTimer'] > 70:
  328. newState = 'reg_roll'
  329. check_state = 'reg_powerslide'
  330. if aState == check_state:
  331. action = getattr(actionsFSMlist, check_state)
  332. # if own['stateTimer'] < 20:
  333. # actionPlayer(actionsFSMlist.reg_powerslide_in)
  334. if own['stateTimer'] < getattr(action, 'intro_frames'):
  335. intro = getattr(action, 'intro')
  336. actionPlayer(getattr(actionsFSMlist, intro))
  337. else:
  338. actionPlayer(action)
  339. newState = check_exit(aState, rA, timer, actionsFSMlist.reg_powerslide)
  340. check_state = 'reg_fs_powerslide'
  341. if aState == check_state:
  342. action = getattr(actionsFSMlist, check_state)
  343. # if own['stateTimer'] < 20:
  344. # actionPlayer(actionsFSMlist.reg_fs_powerslide_in)
  345. if own['stateTimer'] < getattr(action, 'intro_frames'):
  346. intro = getattr(action, 'intro')
  347. actionPlayer(getattr(actionsFSMlist, intro))
  348. else:
  349. actionPlayer(action)
  350. newState = check_exit(aState, rA, timer, actionsFSMlist.reg_fs_powerslide)
  351. check_state = 'fak_sit'
  352. if aState == check_state:
  353. action = getattr(actionsFSMlist, check_state)
  354. #if own['stateTimer'] < 19:
  355. if own['stateTimer'] < getattr(action, 'intro_frames'):
  356. actionPlayer(getattr(actionsFSMlist, 'intro'))
  357. else:
  358. actionPlayer(action)
  359. newState = check_exit(aState, rA, timer, actionsFSMlist.fak_sit)
  360. #-----------------------
  361. check_state = 'fak_walk'
  362. if aState == check_state:
  363. action = getattr(actionsFSMlist, check_state)
  364. if own['l_aState'] == 'fak_walkFast':
  365. frame = get_frame(actionsFSMlist.fak_walkFast)
  366. actionPlayer(action)
  367. set_frame(actionsFSMlist.fak_walk, frame)
  368. else:
  369. frame = actionPlayer(action)
  370. newState = check_exit(aState, rA, timer, action)
  371. #-----------------------
  372. check_state = 'fak_walkFast'
  373. if aState == check_state:
  374. action = getattr(actionsFSMlist, check_state)
  375. newState = check_exit(aState, rA, timer, actionsFSMlist.fak_walkFast)
  376. if own['l_aState'] == 'fak_walk':
  377. frame = get_frame(actionsFSMlist.fak_walk)
  378. actionPlayer(action)
  379. set_frame(actionsFSMlist.fak_walkFast, frame)
  380. else:
  381. actionPlayer(action)
  382. check_state = 'fak_push'
  383. if aState == check_state:
  384. action = getattr(actionsFSMlist, check_state)
  385. actionPlayer(action)
  386. if own['stateTimer'] > 70:
  387. newState = 'fak_roll'
  388. check_state = 'fak_push_goof'
  389. if aState == check_state:
  390. action = getattr(actionsFSMlist, check_state)
  391. actionPlayer(action)
  392. if own['stateTimer'] > 70:
  393. newState = 'fak_roll'
  394. check_state = 'fak_powerslide'
  395. if aState == check_state:
  396. action = getattr(actionsFSMlist, check_state)
  397. # if own['stateTimer'] < 20:
  398. # actionPlayer(actionsFSMlist.fak_powerslide_in)
  399. if own['stateTimer'] < getattr(action, 'intro_frames'):
  400. intro = getattr(action, 'intro')
  401. actionPlayer(getattr(actionsFSMlist, intro))
  402. else:
  403. actionPlayer(action)
  404. newState = check_exit(aState, rA, timer, actionsFSMlist.fak_powerslide)
  405. check_state = 'fak_fs_powerslide'
  406. if aState == check_state:
  407. action = getattr(actionsFSMlist, check_state)
  408. # if own['stateTimer'] < 20:
  409. # actionPlayer(actionsFSMlist.fak_fs_powerslide_in)
  410. if own['stateTimer'] < getattr(action, 'intro_frames'):
  411. intro = getattr(action, 'intro')
  412. actionPlayer(getattr(actionsFSMlist, intro))
  413. else:
  414. actionPlayer(action)
  415. newState = check_exit(aState, rA, timer, actionsFSMlist.fak_fs_powerslide)
  416. #-----------------------
  417. #print(own['aState'], newState, rA)
  418. if newState != '':
  419. own['aState'] = newState
  420. own['l_aState'] = og_state
  421. own['l_actionState'] = og_state
  422. state_timer(own)
  423. skater = dict['p1']
  424. if own['requestAction'] == 'reg_roll' and own['rotz'] < .985:
  425. frame = int(own['rotz'] * 70)
  426. else:
  427. skater.stopAction(5)