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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #from bge import logic
  2. import GameLogic
  3. #from os.path import dirname, realpath, join
  4. #BASE_DIR = os.path.join( os.path.dirname( __file__ ), '..' )
  5. mainDir = GameLogic.expandPath("//")
  6. fileName = mainDir + "Settings.dat"
  7. resx = 1280
  8. resy = 720
  9. def readSettings():
  10. import GameLogic
  11. import bge
  12. cont = GameLogic.getCurrentController()
  13. own = cont.owner
  14. scenes = bge.logic.getSceneList()
  15. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  16. own = main_scene.objects['Empty']
  17. with open(fileName) as reading:
  18. #data = [line.split()[0] for line in reading]
  19. data = reading.readlines()
  20. #print lines[25]
  21. #print lines[29]
  22. reading.close()
  23. own["val"] = int(data[1])
  24. own["bright"] = int(data[1])
  25. own["playerName"] = data[4]
  26. #own["audio"] = int(data[3])
  27. own["level"] = data[5]
  28. #data6 = data[6]
  29. #data6.split(None, 1)[0]
  30. #data5 = data5.strip('\n')
  31. #print(data6)
  32. own["resx"] = int(data[7])
  33. own["resy"] = int(data[8])
  34. own["framerate"] = int(data[10])
  35. own["profile"] = int(data[12])
  36. dict = bge.logic.globalDict #Get the global dictionary
  37. dict['resx'] = resx
  38. dict['resy'] = resy
  39. level = data[5]
  40. level = level.split(None, 1)[0]
  41. level = str(level)
  42. own["level"] = level
  43. dict["level"] = level
  44. print("reading. settings")
  45. print("Level: ", level)
  46. recorder_on = int(data[14])
  47. print("Game play recorder on: ", recorder_on)
  48. #dict = bge.logic.globalDict
  49. dict['recorder_on'] = recorder_on
  50. own['recorder_on'] = recorder_on
  51. def writeSettings():
  52. import GameLogic
  53. import bge
  54. cont = GameLogic.getCurrentController()
  55. own = cont.owner
  56. scenes = bge.logic.getSceneList()
  57. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  58. own = main_scene.objects['Empty']
  59. print("writing called")
  60. with open(fileName, 'w') as writing:
  61. writing.write(str("//settings.dat")+"\n")
  62. writing.write(str(own["val"])+"\n")
  63. writing.write(str(own["bright"])+"\n")
  64. writing.write(str("-\n"))
  65. writing.write(str("//level (e.g. spine, city, city2)")+"\n")
  66. writing.write(str(own["level"])+"\n")
  67. writing.write(str("//resolution")+"\n")
  68. writing.write(str(own["resx"])+"\n")
  69. writing.write(str(own["resy"])+"\n")
  70. writing.write(str("//show framerate")+"\n")
  71. writing.write(str(own["framerate"])+"\n")
  72. writing.write(str("//show profile")+"\n")
  73. writing.write(str(own["profile"])+"\n")
  74. writing.write(str("//Game play recorder off/on (0,1)")+"\n")
  75. writing.write(str(own["recorder_on"])+"\n")
  76. #writing.write(str(own["framerate"])+"\n")
  77. print("writing settings")
  78. writing.close()
  79. def loadlevel():
  80. import GameLogic
  81. import bge
  82. scenes = bge.logic.getSceneList()
  83. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  84. own = main_scene.objects['Empty']
  85. cont = GameLogic.getCurrentController()
  86. own2 = cont.owner
  87. #readSettings()
  88. resx = own["resx"]
  89. resy = own["resy"]
  90. #dict = bge.logic.globalDict #Get the global dictionary
  91. #dict['resx'] = resx
  92. #dict['resy'] = resy
  93. #bge.render.setWindowSize(resx, resy)
  94. #fullscreen = bge.render.getFullScreen()
  95. #print("fullscreen = ", fullscreen)
  96. #if fullscreen != True:
  97. #bge.render.setFullScreen(True)
  98. print("resolution = ", resx, resy)
  99. #objList = scene.objects
  100. if own["framerate"] == 1:
  101. bge.render.showFramerate(1)
  102. if own["profile"] ==1:
  103. bge.render.showProfile(1)
  104. #cont = GameLogic.getCurrentController()
  105. #own = cont.owner
  106. #cont = own2.controllers['loadLevel']
  107. act = own2.actuators["level"]
  108. #cont.activate(own.actuators["loading"])
  109. #level = own["level"]
  110. dict = bge.logic.globalDict
  111. level = dict['level']
  112. #dict['level'] = level
  113. act.scene = level
  114. cont.activate(own2.actuators["level"])
  115. #cont.activate(own2.actuators["stance"])
  116. dict['npause'] = False
  117. def timer():
  118. import GameLogic
  119. import bge
  120. dict = bge.logic.globalDict
  121. if dict['reload_timer'] == 1:
  122. #restart
  123. # get current scene
  124. scene = bge.logic.getCurrentScene()
  125. # restart the current scene
  126. #scene.restart()
  127. if dict['reload_timer'] > 0:
  128. dict['reload_timer'] -= 1
  129. #print(dict['reload_timer'])
  130. #own['reload_timer'] = dict['reload_timer']