Reputation: 1
I have created a game which has a pause feature. Once the player presses the escape key whilst a game is playing, the menu enables, once escaped is pressed again it disables the menu and resumes the game. But when i open my program and press escape without launching a game first the game crashes causes theirs no game to resume. How could i disable the escape key until at least one game has started.
I am using the Pygame-menu module by ppizarror to create my gui, iv'e tried looking up my question but no one has a clear answer. Below is the main parts of code from two different classes that handles the pause feature.
Class EntertheGauntlet: # a function used throughout the menus that disables the previous menu for the new one to be displayed def resume_feature(): # disables menu self.main_menu.disable() # resumes the game paused in the background by calling upon it from the main gameloop self.game.main()
Class GUI: # a function used throughout the game that initiates when the new game button is pressed def start_new():
# disable previous menu
self.main_menu.disable()
# Start new game by calling variable from EscapeTheGauntlet.py
self.game = EscapeTheGauntlet(self.window, clock, self.sfx)
# sets this new updated screen to the new main window
self.game.main()
The only solution i can see is disabling the escape key until the start new game feature is called upon at least once. Could you please show me how i would do that.
Upvotes: 0
Views: 329
Reputation: 3685
What you're suggesting sounds unnecessarily complex. You cannot mess with the system drivers of the keyboard, or with the key-to-character mapping, because the user might be working in a different window with a different program where the escape key is needed.
Can't you re-write your code that handles the pause function to check whether there is a paused game? Initialize some variable with False when the application starts, and set it to True when the function you expect to be called is called.
Upvotes: 2