From a4f94f586609269ad66dbd487c3043cc65a8901b Mon Sep 17 00:00:00 2001 From: Martin Otzen Date: Sun, 5 Dec 2021 02:41:36 +0100 Subject: [PATCH] Fixing multi init bug , adding pycharm project settings. There was a bug htat caused the process to hang, I narrowed it down to the pygame.init being called multiply tims. @Nuke Bloodaxe if you don't like the pyCharm ide just leave out the .idea folder in the pull request merge. removing format changes --- .idea/.gitignore | 3 ++ .idea/Ironseed-py.iml | 8 +++ .../inspectionProfiles/profiles_settings.xml | 6 +++ .idea/misc.xml | 4 ++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 6 +++ global_constants.py | 31 +++++++---- helper_functions.py | 7 ++- ironSeed.py | 54 ++++++++++--------- requirements.txt | 12 ++--- 10 files changed, 95 insertions(+), 44 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/Ironseed-py.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Ironseed-py.iml b/.idea/Ironseed-py.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/Ironseed-py.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..07f5952 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a0f0ebd --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/global_constants.py b/global_constants.py index 76a1a18..a3c6f91 100644 --- a/global_constants.py +++ b/global_constants.py @@ -7,6 +7,10 @@ """ import pygame, os + +# Simple objects is declared and initialized here, +# class object types is declared here and initialized in the init method. + size = width, height = 640, 480 # screen dimensions # Planet texture constants. planetHeight = 240 # 120 @@ -14,10 +18,6 @@ # It's certainly not a lively python... version = "IronPython 0.02 - Frigid Snake Alpha" -# Initialise music system and pygame -pygame.mixer.pre_init(44100, -16, 2, 2048) -pygame.init() - # Colours WHITE = (255, 255, 255) GREY = (127, 127, 127) @@ -36,9 +36,7 @@ TECH4 = (200, 200, 0) TECH5 = (250, 250, 0) -# Note: Font should resize according to resolution, but logic needed. -# Fonts: this is a temporary google font, get it from them. -font = pygame.font.Font(os.path.join('Fonts', 'Inconsolata-ExtraBold.ttf'), 14) +font: object offset = 15 # for this font. # Totals for items @@ -60,5 +58,20 @@ systemsVisited = [] -starDate = [2, 3, 3784, 8, 75] #M,D,Y,H,M, Default entry here is for new game. -gameDate = "Placeholder" # The game time needs to be accessible everywhere. \ No newline at end of file +starDate = [2, 3, 3784, 8, 75] # M,D,Y,H,M, Default entry here is for new game. +gameDate: object # The game time needs to be accessible everywhere. + + +# Class objects need a separate init function +def init(init_game_date): + # Initialise music system and pygame + pygame.mixer.pre_init(44100, -16, 2, 2048) + pygame.init() + global font + # Note: Font should resize according to resolution, but logic needed. + # Fonts: this is a temporary google font, get it from them. + font = pygame.font.Font(os.path.join('Fonts', 'Inconsolata-ExtraBold.ttf'), 14) + + # Initialise game objects + global gameDate + gameDate = init_game_date diff --git a/helper_functions.py b/helper_functions.py index eef4a18..e5078c2 100644 --- a/helper_functions.py +++ b/helper_functions.py @@ -72,8 +72,11 @@ def colourLine(length, colour): # Rounded indicates if the end of the bar needs to be drawn as # half a hemesphere with Height diameter. # Returns a pygame surface with the required elements added. -def createBar(tupleList=[], length=0, height=int((g.height/320)*2), rounded=False): - +def createBar(tupleList=None, length=0, height=None, rounded=False): + if height is None: + height = int((g.height / 320) * 2) + if tupleList is None: + tupleList = [] bar = pygame.Surface((length, height)) bar.set_colorkey(g.BLACK) barArray = pygame.PixelArray(bar) diff --git a/ironSeed.py b/ironSeed.py index 5301898..edab777 100644 --- a/ironSeed.py +++ b/ironSeed.py @@ -15,29 +15,27 @@ import helper_functions as h class IronSeed(object): - + def __init__(self): - - self.state = 3 # Initilise with intro set, normally 3. + + self.state = 3 # Initialise with intro set, normally 3. self.creditText = ["1994 Channel 7, Destiny: Virtual", - "Released Under GPL V3.0 in 2013 by Jeremy D Stanton of IronSeed.net", - "2013 y-salnikov - Converted IronSeed to FreePascal and GNU/Linux", - "2016 Nuke Bloodaxe - Pascal Code Tidying/Prep", - "2020 Nuke Bloodaxe - Complete Python Refactor/Rewrite", - "All rights reserved."] + "Released Under GPL V3.0 in 2013 by Jeremy D Stanton of IronSeed.net", + "2013 y-salnikov - Converted IronSeed to FreePascal and GNU/Linux", + "2016 Nuke Bloodaxe - Pascal Code Tidying/Prep", + "2020 Nuke Bloodaxe - Complete Python Refactor/Rewrite", + "All rights reserved."] self.versionText = ["Ironseed", g.version] - + # Set Window version and Display surface print("Initialise Screen.") self.displaySurface = pygame.display.set_mode(g.size) pygame.display.set_caption(self.versionText[0]+' '+self.versionText[1]) - - # Initialise game objects - print("Initilising IronSeed Game Time") - g.starDate = [2, 3, 3784, 8, 75] # M,D,Y,H,M. - g.gameDate = h.IronSeedTime() - + + # init globals + g.init(h.IronSeedTime()) + # Populate Item dictionaries print("Loading Items: ", end='') items.loadItemData() @@ -73,7 +71,7 @@ def __init__(self): print("Game Generator Objects: ", end='') self.generator = gen.Generator(self.ship, self.crew) # Settings at new-game state. print("complete.") - print("Commnications System Objects: ", end='') + print("Communications System Objects: ", end='') self.crewCom = crewC.crewComm(self.crew) # Needs to have crew data set. print("complete.") print("Planet Scanner Objects: ", end='') @@ -97,9 +95,9 @@ def __init__(self): print("Creating Main Menu: ", end='') self.mainMenu = mainMenu.MainMenu() print("complete.") - + # Note: While in Alpha, the below state list is not exhaustive. - + self.states = {1:self.generator.update, # The crew + ship selection system. 2:self.mainMenu.update, # Main menu. 3:self.intro.update, # Game Intro - quite useful for testing. @@ -118,7 +116,7 @@ def __init__(self): 16: "Creation", # really item assembly/disassembly. 17: "Sector Map" # Inter-Sector travel. } - + self.interactive = {1:self.generator.interact, 2:self.mainMenu.interact, 3:self.intro.interact, @@ -152,20 +150,26 @@ def main_loop(self): # enter main state and logic loop. while 1: - + for evt in pygame.event.get(): - + if evt.type == pygame.QUIT: - + pygame.quit() sys.exit() - + # Handle mouse input. elif evt.type == pygame.MOUSEBUTTONDOWN: - + self.state = self.interactive[self.state](evt.button) - + g.gameDate.update() # Update game time in "realtime" self.state = self.states[self.state](self.displaySurface) # self.state(self.displaySurface) pygame.display.update() + + +if __name__ == "__main__": + game = IronSeed() + game.main_loop() + diff --git a/requirements.txt b/requirements.txt index ce85a33..b90a795 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ -# ####### requirements.txt ####### -# + ###### Requirements without Version Specifiers ###### pygame #io @@ -10,23 +9,20 @@ pygame #sys #time numpy -# + ###### Requirements with Version Specifiers ###### # See https://www.python.org/dev/peps/pep-0440/#version-specifiers #docopt == 0.6.1 # Version Matching. Must be version 0.6.1 #keyring >= 4.1.1 # Minimum version 4.1.1 #coverage != 3.5 # Version Exclusion. Anything except version 3.5 #Mopidy-Dirble ~= 1.1 # Compatible release. Same as >= 1.1, == 1.* -# -python >= 3.0 + ###### Refer to other requirements files ###### #-r other-requirements.txt -# -# ###### A particular file ###### #./downloads/numpy-1.9.2-cp34-none-win32.whl #http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1820+49a8884-cp34-none-win_amd64.whl -# + ###### Additional Requirements without Version Specifiers ###### # Same as 1st section, just here to show that you can put things in any order. #rejected