file - python menu Game menu game... etc -
i'm making game in python using pygame , other libraries. have main menu 1 python file, , when player selected, starts game file. if choose go menu while playing game, starts menu again. new menu can't start/open game file anymore doesn't @ all. (after each time open file close previous one)
eg:
menu-->playerselect-->gamestartup-->menu-->playerselect-->break/crash.
so actual code first file menu name "flappybirdmain, "happybrid" name of second game file.
if startgui == 2: screen.blit(background, [0, 0]) import happybird done=true pygame.quit()
for second file "happybird" have open menu connected pressing down "m" key:
if event.key == k_m: pygame.mixer.fadeout(1) import flappybirdmain done=true
so import flappybirdmain done=true closes "happybird" file
i have figured out making copies of same files("flappybirdmain", , "happybird") making them import each other in series can have menu come go down again(more once) when link origonal file crash/breaks eg:
ex1:
flappybirdmain-->happybird-->flappybirdmain2-->happybird2-->flappybirdmain3-->happybird3
ex2:
flappybirdmain-->happybird-->flappybirdmain2-->happybird2-->flappybirdmain3-->happybird3-->flappybirdmain
the problem using import command. exec(open("happybird.py").read())
using import cuases python think open, smart import system. (or along lines of that).
repeating import module - python / pygame
^the link how figured out.
thanks.
using import
start menu not solution.
if have menu.py
print("hello world")
it works when import first time in game.py
import menu
but can put in function
def run_it(): print("hello world")
and can use many times
import menu menu.run_it() # , again menu.run_it() # , again menu.run_it()
if use class
class menu(): def update(): pass def draw(): pass def event_handler(): pass def mainloop(): print("hello world")
then can run many times too
menu = menu() menu.mainloop() # , again menu.mainloop() # , again menu.mainloop()
Comments
Post a Comment