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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import bge
  2. dict = bge.logic.globalDict
  3. #====================================
  4. State = type("State", (object,), {})
  5. #====================================
  6. class State(object):
  7. def __init__(self, FSM):
  8. self.FSM = FSM
  9. self.timer = 0
  10. self.startTime = 0
  11. def Enter(self):
  12. self.timer = 0
  13. self.startTime = 0
  14. def Execute(self):
  15. print('Executing')
  16. def Exit(self):
  17. print('Exiting')
  18. #====================================
  19. class Example(State):
  20. def __init__(self,FSM):
  21. super(Example, self).__init__(FSM)
  22. def Enter(self):
  23. self.FSM.stateLife = 1
  24. super(Example, self).Enter()
  25. def Execute(self):
  26. self.FSM.stateLife += 1
  27. #self.FSM.ToTransition('toExample')
  28. def Exit(self):
  29. pass
  30. #====================================
  31. class Startup(State):
  32. def __init__(self,FSM):
  33. super(Startup, self).__init__(FSM)
  34. def Enter(self):
  35. self.FSM.stateLife = 1
  36. super(Startup, self).Enter()
  37. def Execute(self):
  38. self.FSM.stateLife += 1
  39. #if self.FSM.stateLife == 2:
  40. #Startup.main(self.FSM.owner['cont'])
  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
  52. super(Walk, self).Enter()
  53. def Execute(self):
  54. self.FSM.stateLife += 1
  55. o = self.FSM.owner
  56. #print('walking')
  57. if self.FSM.stateLife == 2:
  58. if self.FSM.owner['stance']:
  59. self.FSM.owner.applyRotation([0,0,3], True)
  60. self.FSM.owner['stance'] = False
  61. o['requestAction'] = 'fak_offboard'
  62. print('request fak offboard')
  63. else:
  64. o['requestAction'] = 'reg_offboard'
  65. print('request reg offboard')
  66. if self.FSM.stateLife > 5:
  67. o['requestAction'] = 'reg_idle'
  68. self.check_onboard()
  69. self.check_jump()
  70. #self.FSM.ToTransition('toLand')
  71. def check_onboard(self):
  72. if dict['walk'] == 0:
  73. self.FSM.ToTransition('toRoll')
  74. if dict['yBut'] == 1 and dict['last_yBut'] == 0:
  75. print('do the onboard')
  76. def check_jump(self):
  77. o = self.FSM.owner
  78. #limit fall speed
  79. if o.linearVelocity.z < -10:
  80. o.linearVelocity.z = -10
  81. if dict['xBut'] == True or dict['kb_space'] == 1:
  82. if dict['last_xBut'] == 0:
  83. o['requestAction'] ='reg_jump'
  84. JUMPHEIGHT = 1100
  85. force = [ 0.0, 0.0, JUMPHEIGHT]
  86. # use local axis
  87. local = False
  88. # apply force -- limit jump speed
  89. if o.linearVelocity.z < 10:
  90. o.applyForce(force, local)
  91. o.linearVelocity.z += 5
  92. def Exit(self):
  93. pass
  94. #====================================
  95. class WalkAir(State):
  96. def __init__(self,FSM):
  97. super(WalkAir, self).__init__(FSM)
  98. def Enter(self):
  99. self.FSM.stateLife = 1
  100. super(WalkAir, self).Enter()
  101. def Execute(self):
  102. self.FSM.stateLife += 1
  103. #self.FSM.ToTransition('toLand')
  104. def Exit(self):
  105. pass
  106. #====================================
  107. class WalkJump(State):
  108. def __init__(self,FSM):
  109. super(WalkJump, self).__init__(FSM)
  110. def Enter(self):
  111. self.FSM.stateLife = 1
  112. super(WalkJump, self).Enter()
  113. def Execute(self):
  114. self.FSM.stateLife += 1
  115. #self.FSM.ToTransition('toLand')
  116. def Exit(self):
  117. pass
  118. #====================================
  119. class WalkLand(State):
  120. def __init__(self,FSM):
  121. super(WalkLand, self).__init__(FSM)
  122. def Enter(self):
  123. self.FSM.stateLife = 1
  124. super(WalkLand, self).Enter()
  125. def Execute(self):
  126. self.FSM.stateLife += 1
  127. #self.FSM.ToTransition('toLand')
  128. def Exit(self):
  129. pass
  130. #====================================
  131. class WalkHang(State):
  132. def __init__(self,FSM):
  133. super(WalkHang, self).__init__(FSM)
  134. def Enter(self):
  135. self.FSM.stateLife = 1
  136. super(WalkHang, self).Enter()
  137. def Execute(self):
  138. self.FSM.stateLife += 1
  139. #self.FSM.ToTransition('toLand')
  140. def Exit(self):
  141. pass
  142. #====================================
  143. class WalkClimb(State):
  144. def __init__(self,FSM):
  145. super(WalkClimb, self).__init__(FSM)
  146. def Enter(self):
  147. self.FSM.stateLife = 1
  148. super(WalkClimb, self).Enter()
  149. def Execute(self):
  150. self.FSM.stateLife += 1
  151. #self.FSM.ToTransition('toLand')
  152. def Exit(self):
  153. pass
  154. #====================================
  155. class WalkHurdle(State):
  156. def __init__(self,FSM):
  157. super(WalkClimb, self).__init__(FSM)
  158. def Enter(self):
  159. self.FSM.stateLife = 1
  160. super(WalkClimb, self).Enter()
  161. def Execute(self):
  162. self.FSM.stateLife += 1
  163. #self.FSM.ToTransition('toLand')
  164. def Exit(self):
  165. pass
  166. #====================================
  167. class Roll(State):
  168. def __init__(self,FSM):
  169. super(Roll, self).__init__(FSM)
  170. def Enter(self):
  171. self.FSM.stateLife = 1
  172. super(Roll, self).Enter()
  173. def Execute(self):
  174. self.FSM.stateLife += 1
  175. if dict['walk'] == 1:
  176. self.FSM.ToTransition('toWalk')
  177. print('rolling')
  178. #self.FSM.ToTransition('toLand')
  179. def Exit(self):
  180. pass
  181. #====================================