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.

Settings.py 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import bge
  2. import GameLogic
  3. import configobj
  4. from configobj import ConfigObj
  5. mainDir = GameLogic.expandPath("//")
  6. fileName = mainDir + "config.ini"
  7. config = ConfigObj(fileName, interpolation=True)
  8. dict = bge.logic.globalDict
  9. print('###############start game##########')
  10. dict['music_player'] = 1
  11. def to_dict(section, key):
  12. dict = bge.logic.globalDict
  13. value = config[key]
  14. if isinstance(value, str):
  15. if value.isdigit():
  16. value = int(value)
  17. else:
  18. try:
  19. value = float(value)
  20. except:
  21. pass
  22. dict[key] = value
  23. def readSettings():
  24. config.walk(to_dict)
  25. def from_dict(section, key):
  26. dict = bge.logic.globalDict
  27. config[key] = dict[key]
  28. def writeSettings():
  29. config.walk(from_dict)
  30. config.write()
  31. def setres():
  32. import GameLogic
  33. import bge
  34. scenes = bge.logic.getSceneList()
  35. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  36. own = main_scene.objects['Empty']
  37. cont = GameLogic.getCurrentController()
  38. own2 = cont.owner
  39. dict = bge.logic.globalDict
  40. resx = int(dict["resx"])
  41. resy = int(dict["resy"])
  42. fullscreen = bge.render.getFullScreen()
  43. print("fullscreen = ", fullscreen)
  44. if fullscreen != True:
  45. if dict['fullscreen_on'] == 1:
  46. bge.render.setFullScreen(True)
  47. if fullscreen == True:
  48. if dict['fullscreen_on'] == 0:
  49. bge.render.setFullScreen(False)
  50. bge.render.setWindowSize(resx, resy)
  51. print("resolution = ", resx, resy)
  52. def loadlevel():
  53. import GameLogic
  54. import bge
  55. scenes = bge.logic.getSceneList()
  56. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  57. own = main_scene.objects['Empty']
  58. cont = GameLogic.getCurrentController()
  59. own2 = cont.owner
  60. dict = bge.logic.globalDict #Get the global dictionary
  61. if own["framerate"] == 1:
  62. bge.render.showFramerate(1)
  63. if own["profile"] ==1:
  64. bge.render.showProfile(1)
  65. act = own2.actuators["level"]
  66. dict = bge.logic.globalDict
  67. level = dict['level']
  68. print('loading level', level)
  69. act.scene = level
  70. cont.activate(own2.actuators["level"])
  71. dict['npause'] = False
  72. def timer():
  73. import GameLogic
  74. import bge
  75. dict = bge.logic.globalDict
  76. if dict['reload_timer'] == 1:
  77. scene = bge.logic.getCurrentScene()
  78. if dict['reload_timer'] > 0:
  79. dict['reload_timer'] -= 1