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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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('toLand')
  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. # if self.FSM.owner['stance']:
  53. # self.FSM.owner.applyRotation([0,0,3], True)
  54. # self.FSM.owner['stance'] = False
  55. # o['requestAction'] = 'fak_offboard'
  56. # print('request fak offboard')
  57. # else:
  58. # o['requestAction'] = 'reg_offboard'
  59. # print('request reg offboard')
  60. #o['requestAction'] = 'fak_offboard'
  61. super(Walk, self).Enter()
  62. def Execute(self):
  63. self.FSM.stateLife += 1
  64. o = self.FSM.owner
  65. #print('walking')
  66. if self.FSM.stateLife == 2:
  67. if self.FSM.owner['stance']:
  68. self.FSM.owner.applyRotation([0,0,3], True)
  69. self.FSM.owner['stance'] = False
  70. o['requestAction'] = 'fak_offboard'
  71. print('request fak offboard')
  72. else:
  73. o['requestAction'] = 'reg_offboard'
  74. print('request reg offboard')
  75. if self.FSM.stateLife > 5:
  76. o['requestAction'] = 'reg_idle'
  77. self.check_onboard()
  78. self.check_jump()
  79. #self.FSM.ToTransition('toLand')
  80. def check_onboard(self):
  81. if dict['walk'] == 0:
  82. self.FSM.ToTransition('toRoll')
  83. if dict['yBut'] == 1 and dict['last_yBut'] == 0:
  84. print('do the onboard')
  85. def check_jump(self):
  86. o = self.FSM.owner
  87. #limit fall speed
  88. if o.linearVelocity.z < -10:
  89. o.linearVelocity.z = -10
  90. if dict['xBut'] == True or dict['kb_space'] == 1:
  91. if dict['last_xBut'] == 0:
  92. #killact(3)
  93. #killact(4)
  94. #killact(5)
  95. #killact(6)
  96. #killact(7)
  97. #if STANCE == 0:
  98. o['requestAction'] ='reg_jump'
  99. #print('jump')
  100. #if STANCE == 1:
  101. #own['requestAction'] ='fak_jump'
  102. #print('jump')
  103. JUMPHEIGHT = 1100
  104. force = [ 0.0, 0.0, JUMPHEIGHT]
  105. # use local axis
  106. local = False
  107. # apply force -- limit jump speed
  108. if o.linearVelocity.z < 10:
  109. o.applyForce(force, local)
  110. o.linearVelocity.z += 5
  111. #o.linearVelocity.x = linvel.x
  112. #o.linearVelocity.y = linvel.y
  113. #own['walk_jump_timer'] = 6
  114. def Exit(self):
  115. pass
  116. #====================================
  117. class Roll(State):
  118. def __init__(self,FSM):
  119. super(Roll, self).__init__(FSM)
  120. def Enter(self):
  121. self.FSM.stateLife = 1
  122. super(Roll, self).Enter()
  123. def Execute(self):
  124. self.FSM.stateLife += 1
  125. if dict['walk'] == 1:
  126. self.FSM.ToTransition('toWalk')
  127. print('rolling')
  128. #self.FSM.ToTransition('toLand')
  129. def Exit(self):
  130. pass
  131. #====================================