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.

StatesEa.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import bge
  2. import random
  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. #print('doing example', self.FSM.owner['EaRequest'])
  28. if self.FSM.owner['EaRequest'] == 'land':
  29. self.FSM.ToTransition('toLand')
  30. def Exit(self):
  31. pass
  32. #====================================
  33. class Land(State):
  34. def __init__(self,FSM):
  35. super(Land, self).__init__(FSM)
  36. def Enter(self):
  37. self.FSM.stateLife = 1
  38. #self.strength = random.choice([.1, .2, .3, .4, .5, .6, .7, .8, .9, .9, .9, .9])
  39. self.strength = random.choice([.1, .2, .3, .4, .5, .6, .7, .8, .9])
  40. self.act = random.choice(['ea_land2', 'ea_land3'])
  41. #self.strength = random.choice([.1])
  42. super(Land, self).Enter()
  43. def Execute(self):
  44. self.FSM.stateLife += 1
  45. print('land')
  46. arm = bge.logic.globalDict['p1']
  47. if self.FSM.stateLife > 80:
  48. if self.strength < 1:
  49. self.strength += .05
  50. arm.stopAction(8)
  51. arm.playAction(self.act, 0,80, layer=8, play_mode=0, speed=1, blendin=10, layer_weight=self.strength)
  52. if self.FSM.stateLife > 100:
  53. self.FSM.owner['EaRequest'] = None
  54. self.FSM.ToTransition('toExample')
  55. def Exit(self):
  56. pass