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

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