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

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