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.

StatesGame.py 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import bge
  2. import random
  3. import Startup as S2
  4. import Settings
  5. import inputs
  6. import logo_fades
  7. dict = bge.logic.globalDict
  8. #====================================
  9. State = type("State", (object,), {})
  10. #====================================
  11. class State(object):
  12. def __init__(self, FSM):
  13. self.FSM = FSM
  14. self.timer = 0
  15. self.startTime = 0
  16. def Enter(self):
  17. self.timer = 0
  18. self.startTime = 0
  19. def Execute(self):
  20. print('Executing')
  21. def Exit(self):
  22. print('Exiting')
  23. #====================================
  24. class Example(State):
  25. def __init__(self,FSM):
  26. super(Example, self).__init__(FSM)
  27. def Enter(self):
  28. self.FSM.stateLife = 1
  29. super(Example, self).Enter()
  30. def Execute(self):
  31. self.FSM.stateLife += 1
  32. #self.FSM.ToTransition('toLand')
  33. def Exit(self):
  34. pass
  35. #====================================
  36. class Startup(State):
  37. def __init__(self,FSM):
  38. super(Startup, self).__init__(FSM)
  39. def Enter(self):
  40. self.FSM.stateLife = 1
  41. super(Startup, self).Enter()
  42. def Execute(self):
  43. self.FSM.stateLife += 1
  44. #if self.FSM.stateLife == 2:
  45. #Startup.main(self.FSM.owner['cont'])
  46. self.FSM.ToTransition('toIniter')
  47. def Exit(self):
  48. pass
  49. #====================================
  50. class Initer(State):
  51. def __init__(self,FSM):
  52. super(Initer, self).__init__(FSM)
  53. def Enter(self):
  54. self.FSM.stateLife = 1
  55. super(Initer, self).Enter()
  56. def Execute(self):
  57. self.FSM.stateLife += 1
  58. if self.FSM.stateLife == 2:
  59. print('--------- fsm running startup')
  60. S2.main(self.FSM.owner['cont'])
  61. #Settings.readSettings(self.FSM.owner['cont'])
  62. Settings.readSettings()
  63. Settings.setres()
  64. if self.FSM.stateLife == 120:
  65. self.FSM.ToTransition('toLoadLevel')
  66. def Exit(self):
  67. pass
  68. #====================================
  69. class LoadLevel(State):
  70. def __init__(self,FSM):
  71. super(LoadLevel, self).__init__(FSM)
  72. def Enter(self):
  73. self.FSM.stateLife = 1
  74. super(LoadLevel, self).Enter()
  75. def Execute(self):
  76. self.FSM.stateLife += 1
  77. print('fsm loading level')
  78. Settings.loadlevel()
  79. self.FSM.ToTransition('toGameOn')
  80. def Exit(self):
  81. pass
  82. #====================================
  83. class GameOn(State):
  84. def __init__(self,FSM):
  85. super(GameOn, self).__init__(FSM)
  86. def Enter(self):
  87. self.FSM.stateLife = 1
  88. super(GameOn, self).Enter()
  89. def Execute(self):
  90. self.FSM.stateLife += 1
  91. #self.FSM.ToTransition('toLand')
  92. #print('game on')
  93. inputs.main()
  94. logo_fades.main()
  95. def Exit(self):
  96. pass
  97. #====================================
  98. class Reload(State):
  99. def __init__(self,FSM):
  100. super(Reload, self).__init__(FSM)
  101. def Enter(self):
  102. self.FSM.stateLife = 1
  103. super(Reload, self).Enter()
  104. def Execute(self):
  105. self.FSM.stateLife += 1
  106. dict.clear()
  107. self.FSM.owner['cont'].activate(self.FSM.owner['cont'].actuators['restart'])
  108. #cont.activate(own.actuators['add_fade'])
  109. #own['cont'] = cont
  110. def Exit(self):
  111. pass
  112. #====================================