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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. state_b = ['reg_jump',
  142. 'reg_walk_air',
  143. 'reg_walk_air_out',
  144. 'reg_onboard',
  145. 'reg_offboard',
  146. 'reg_brfoot',
  147. 'reg_frfoot',
  148. 'reg_blfoot',
  149. 'reg_flfoot',
  150. 'reg_land',
  151. 'reg_landL',
  152. 'reg_landLb',
  153. 'reg_landR',
  154. 'reg_landRb',
  155. 'revert1',
  156. 'revert2',
  157. 'fak_revert1',
  158. 'fak_revert2',
  159. 'revert3',
  160. 'revert4',
  161. 'fak_jump',
  162. 'fak_walk_air',
  163. 'fak_walk_air_out',
  164. 'fak_onboard',
  165. 'fak_offboard',
  166. 'fak_brfoot',
  167. 'fak_frfoot',
  168. 'fak_blfoot',
  169. 'fak_flfoot',
  170. 'fak_land',
  171. 'fak_landL',
  172. 'fak_landLb',
  173. 'fak_landR',
  174. 'fak_landRb']
  175. def actionPlayer(ac):
  176. scene = bge.logic.getCurrentScene()
  177. cont = bge.logic.getCurrentController()
  178. own = cont.owner
  179. skater = dict['p1']
  180. deck = dict['p1d']
  181. a = getattr(actionsFSMlist.reg_walk, 'name')
  182. name = getattr(ac, 'name')
  183. dname = getattr(ac, 'dname')
  184. start = getattr(ac, 'start')
  185. end = getattr(ac, 'end')
  186. dstart = getattr(ac, 'dstart')
  187. dend = getattr(ac, 'dend')
  188. layer = getattr(ac, 'layer')
  189. mode = getattr(ac, 'mode')
  190. speed = getattr(ac, 'speed')
  191. blendin = getattr(ac, 'blendin')
  192. #--------------------------------
  193. #if zero_blend:
  194. # if own['l_actionState'] != None and own['l_actionState'] in 'revert1':
  195. # blendin = 0
  196. # print('zeroing blend')
  197. skater.playAction(name, start,end, layer=layer, play_mode=mode, speed=speed, blendin=blendin)
  198. deck.playAction(dname, dstart,dend, layer=layer, play_mode=mode, speed=speed, blendin=blendin)
  199. #print('playing', name, get_frame(ac))
  200. #if skater.isPlayingAction(3):
  201. #print(skater.getActionFrame(3))
  202. def get_frame(ac):
  203. skater = dict['p1']
  204. layer = getattr(ac, 'layer')
  205. #print('getting frame', skater.getActionFrame(layer))
  206. return skater.getActionFrame(layer)
  207. def set_frame(ac, frame):
  208. skater = dict['p1']
  209. deck = dict['p1d']
  210. layer = getattr(ac, 'layer')
  211. skater.setActionFrame(frame, layer)
  212. deck.setActionFrame(frame, layer)
  213. #print('setting frame', frame)
  214. def check_exit(aState, rA, timer, ac):
  215. exits = getattr(ac, 'exits')
  216. force = getattr(ac, 'force_exit')
  217. fe = getattr(ac, 'fef')
  218. rv = ''
  219. #print('rA, aState', rA, aState, force, fe, timer)
  220. if rA in exits:
  221. rv = rA
  222. #
  223. elif ('fak' in rA and 'reg' in aState) or ('reg' in rA and 'fak' in aState):
  224. #print('change stance')
  225. if getattr(ac, 'opposite') != None:
  226. rv = getattr(ac, 'opposite')
  227. else:
  228. rv = aState
  229. if force != None and fe >= timer:
  230. print('doing exit timer')
  231. rv = force
  232. return rv
  233. def state_timer(own):
  234. if own['aState'] == own['l_aState']:
  235. own['stateTimer'] += 1
  236. else:
  237. own['stateTimer'] = 0
  238. def check_land(rA, aState, own):
  239. #check if manualling
  240. if rA in actionsFSMlist.reg_manuallist or rA in actionsFSMlist.reg_grindlist or rA in actionsFSMlist.fak_grindlist:
  241. #if rA in actionsFSMlist.reg_manuallist or rA in actionsFSMlist.fak_grindlist:
  242. aState = rA
  243. #own['stateTimer'] = 0
  244. own['aState'] = rA
  245. #otherwise, force land, offboard or fliptrick
  246. 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:
  247. #print('landing________________________', rA)
  248. aState = rA
  249. own['stateTimer'] = 0
  250. own['aState'] = rA
  251. #print(own['stance'], '-----stance', rA)
  252. return aState
  253. def main(cont):
  254. own = cont.owner
  255. dict = bge.logic.globalDict
  256. #initial state
  257. if 'aState' not in own:
  258. own['aState'] = 'reg_idle'
  259. own['l_aState'] = None
  260. own['stateTimer'] = 0
  261. aState = own['aState']
  262. rA = own['requestAction']
  263. timer = own['stateTimer']
  264. newState = own['aState']
  265. aState = check_land(rA, aState, own)
  266. newState = aState
  267. og_state = own['aState']
  268. if aState in state_a:
  269. action = getattr(actionsFSMlist, aState)
  270. if own['stateTimer'] < getattr(action, 'intro_frames'):
  271. intro = getattr(action, 'intro')
  272. actionPlayer(getattr(actionsFSMlist, intro))
  273. else:
  274. actionPlayer(action)
  275. newState = check_exit(aState, rA, timer, action)
  276. elif aState in state_b:
  277. action = getattr(actionsFSMlist, aState)
  278. actionPlayer(action)
  279. if own['stateTimer'] > getattr(action, 'fef'):
  280. newState = check_exit(aState, rA, timer, action)
  281. ###################################
  282. check_state = 'reg_sit'
  283. if aState == check_state:
  284. action = getattr(actionsFSMlist, check_state)
  285. #if own['stateTimer'] < 19:
  286. if own['stateTimer'] < getattr(action, 'intro_frames'):
  287. actionPlayer(getattr(actionsFSMlist, 'intro'))
  288. else:
  289. actionPlayer(action)
  290. newState = check_exit(aState, rA, timer, actionsFSMlist.reg_sit)
  291. #-----------------------
  292. check_state = 'reg_walk'
  293. if aState == check_state:
  294. action = getattr(actionsFSMlist, check_state)
  295. if own['l_aState'] == 'reg_walkFast':
  296. frame = get_frame(actionsFSMlist.reg_walkFast)
  297. actionPlayer(action)
  298. set_frame(actionsFSMlist.reg_walk, frame)
  299. else:
  300. frame = actionPlayer(action)
  301. newState = check_exit(aState, rA, timer, action)
  302. #-----------------------
  303. check_state = 'reg_walkFast'
  304. if aState == check_state:
  305. action = getattr(actionsFSMlist, check_state)
  306. newState = check_exit(aState, rA, timer, actionsFSMlist.reg_walkFast)
  307. if own['l_aState'] == 'reg_walk':
  308. frame = get_frame(actionsFSMlist.reg_walk)
  309. actionPlayer(action)
  310. set_frame(actionsFSMlist.reg_walkFast, frame)
  311. else:
  312. actionPlayer(action)
  313. check_state = 'reg_push'
  314. if aState == check_state:
  315. action = getattr(actionsFSMlist, check_state)
  316. actionPlayer(action)
  317. if own['stateTimer'] > 70:
  318. newState = 'reg_roll'
  319. check_state = 'reg_push_goof'
  320. if aState == check_state:
  321. action = getattr(actionsFSMlist, check_state)
  322. actionPlayer(action)
  323. if own['stateTimer'] > 70:
  324. newState = 'reg_roll'
  325. check_state = 'reg_powerslide'
  326. if aState == check_state:
  327. action = getattr(actionsFSMlist, check_state)
  328. # if own['stateTimer'] < 20:
  329. # actionPlayer(actionsFSMlist.reg_powerslide_in)
  330. if own['stateTimer'] < getattr(action, 'intro_frames'):
  331. intro = getattr(action, 'intro')
  332. actionPlayer(getattr(actionsFSMlist, intro))
  333. else:
  334. actionPlayer(action)
  335. newState = check_exit(aState, rA, timer, actionsFSMlist.reg_powerslide)
  336. check_state = 'reg_fs_powerslide'
  337. if aState == check_state:
  338. action = getattr(actionsFSMlist, check_state)
  339. # if own['stateTimer'] < 20:
  340. # actionPlayer(actionsFSMlist.reg_fs_powerslide_in)
  341. if own['stateTimer'] < getattr(action, 'intro_frames'):
  342. intro = getattr(action, 'intro')
  343. actionPlayer(getattr(actionsFSMlist, intro))
  344. else:
  345. actionPlayer(action)
  346. newState = check_exit(aState, rA, timer, actionsFSMlist.reg_fs_powerslide)
  347. check_state = 'fak_sit'
  348. if aState == check_state:
  349. action = getattr(actionsFSMlist, check_state)
  350. #if own['stateTimer'] < 19:
  351. if own['stateTimer'] < getattr(action, 'intro_frames'):
  352. actionPlayer(getattr(actionsFSMlist, 'intro'))
  353. else:
  354. actionPlayer(action)
  355. newState = check_exit(aState, rA, timer, actionsFSMlist.fak_sit)
  356. #-----------------------
  357. check_state = 'fak_walk'
  358. if aState == check_state:
  359. action = getattr(actionsFSMlist, check_state)
  360. if own['l_aState'] == 'fak_walkFast':
  361. frame = get_frame(actionsFSMlist.fak_walkFast)
  362. actionPlayer(action)
  363. set_frame(actionsFSMlist.fak_walk, frame)
  364. else:
  365. frame = actionPlayer(action)
  366. newState = check_exit(aState, rA, timer, action)
  367. #-----------------------
  368. check_state = 'fak_walkFast'
  369. if aState == check_state:
  370. action = getattr(actionsFSMlist, check_state)
  371. newState = check_exit(aState, rA, timer, actionsFSMlist.fak_walkFast)
  372. if own['l_aState'] == 'fak_walk':
  373. frame = get_frame(actionsFSMlist.fak_walk)
  374. actionPlayer(action)
  375. set_frame(actionsFSMlist.fak_walkFast, frame)
  376. else:
  377. actionPlayer(action)
  378. check_state = 'fak_push'
  379. if aState == check_state:
  380. action = getattr(actionsFSMlist, check_state)
  381. actionPlayer(action)
  382. if own['stateTimer'] > 70:
  383. newState = 'fak_roll'
  384. check_state = 'fak_push_goof'
  385. if aState == check_state:
  386. action = getattr(actionsFSMlist, check_state)
  387. actionPlayer(action)
  388. if own['stateTimer'] > 70:
  389. newState = 'fak_roll'
  390. check_state = 'fak_powerslide'
  391. if aState == check_state:
  392. action = getattr(actionsFSMlist, check_state)
  393. # if own['stateTimer'] < 20:
  394. # actionPlayer(actionsFSMlist.fak_powerslide_in)
  395. if own['stateTimer'] < getattr(action, 'intro_frames'):
  396. intro = getattr(action, 'intro')
  397. actionPlayer(getattr(actionsFSMlist, intro))
  398. else:
  399. actionPlayer(action)
  400. newState = check_exit(aState, rA, timer, actionsFSMlist.fak_powerslide)
  401. check_state = 'fak_fs_powerslide'
  402. if aState == check_state:
  403. action = getattr(actionsFSMlist, check_state)
  404. # if own['stateTimer'] < 20:
  405. # actionPlayer(actionsFSMlist.fak_fs_powerslide_in)
  406. if own['stateTimer'] < getattr(action, 'intro_frames'):
  407. intro = getattr(action, 'intro')
  408. actionPlayer(getattr(actionsFSMlist, intro))
  409. else:
  410. actionPlayer(action)
  411. newState = check_exit(aState, rA, timer, actionsFSMlist.fak_fs_powerslide)
  412. #-----------------------
  413. #print(own['aState'], newState, rA)
  414. if newState != '':
  415. own['aState'] = newState
  416. own['l_aState'] = og_state
  417. own['l_actionState'] = og_state
  418. state_timer(own)
  419. skater = dict['p1']
  420. if own['requestAction'] == 'reg_roll' and own['rotz'] < .985:
  421. frame = int(own['rotz'] * 70)
  422. else:
  423. skater.stopAction(5)