def run(self): """The mainloop """ #self.paint() running = True self.sounds = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: running = True if event.key == pygame.K_DOWN or event.key == pygame.K_KP2: if self.sounds == True: self.sound1.play() if self.sounds == False: try: self.sound5.play() except: print("sound is off!") if event.key == pygame.K_DOWN or event.key == pygame.K_KP2: #print(m.active_itemnumber) m.nextitem() print(m.active_itemnumber) #self.sound2.play() if event.key == pygame.K_UP or event.key == pygame.K_KP8: if self.sounds == True: self.sound1.play() if self.sounds == False: try: self.sound5.play() except: print("sound is off!") if event.key == pygame.K_UP or event.key == pygame.K_KP8: m.previousitem() #self.sound1.play() if event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER: if self.sounds == True: self.sound2.play() if self.sounds == False: try: self.sound5.play() except: print("sound is off!") if event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER: result = m.get_text() #print(m.get_text()) print(result) if result is None: #print("Bildwechsel") #print(self.backgrounds) self.background = random.choice(self.backgrounds) break if "x" in result: # change screen resolution, menu text is something like "800x600" left = result.split("x")[0] right = result.split("x")[1] if str(int(left)) == left and str( int(right)) == right: self.width = int(left) self.height = int(right) self.set_resolution() # important: no elif here, instead if, because every menupoint could contain an 'x' if result == "Campaign" or "Practice" in result: print("starting game...") elif result == "Soundeffects": text = "Sonar sound by Argitoth\n URL:\nhttp://freesound.org/people/Argitoth/sounds/38701/" textscroller_vertical.PygView( text, self.width, self.height).run() elif result == "Turn music off": # music off Settings.menu["Options"][0] = "Turn music on" elif result == "Turn music on": # music on Settings.menu["Options"][0] = "Turn music off" elif result == "Turn sound off": self.sounds = False Settings.menu["Options"][1] = "Turn sound on" elif result == "Turn sound on": self.sounds = True Settings.menu["Options"][1] = "Turn sound off" elif result == "How to play": text = "play this game\n as you like\n and win!" textscroller_vertical.PygView( text, self.width, self.height).run() elif result == "How to win": text = "to win the game:\n shoot down enemies\n avoid catching bullets" textscroller_vertical.PygView( text, self.width, self.height).run() elif result == "Simon Heppner": text = "-----SIMON HEPPNER-----\nWurde geboren 2006 am 3.5.\n(Also noch nicht gestorben)" textscroller_vertical.PygView( text, self.width, self.height, textcolor=(200, 0, 200), bg_filename=os.path.join("data", "map.png")).run() elif result == "Horst Jens": text = "-----Horst Jens-----\nIsst gerne Joghurt! :)" textscroller_vertical.PygView( text, self.width, self.height, textcolor=(200, 0, 0), bg_filename=os.path.join( "data", "Ubootdead.png")).run() elif result == "Paolo Perfahl": text = "-----Paolo Perfahl-----\n Geboren 2003 1.7.\n (Also noch nicht gestorben)\nEr kann sehr gut am Computer\n und \n auch sonst malen und deshalb\nsind die meisten\nBilder von ihm\ngemalt worden." textscroller_vertical.PygView( text, self.width, self.height, textcolor=(0, 200, 0), bg_filename=os.path.join("data", "reef.png")).run() elif result == "Quit": print("Bye") pygame.quit() sys.exit() milliseconds = self.clock.tick(self.fps) #self.playtime += milliseconds / 1000.0 self.draw_text("FPS: {:6.3}".format(self.clock.get_fps())) #, self.playtime), color=(30, 120 ,18)) pygame.draw.line(self.screen, (random.randint( 0, 255), random.randint(0, 255), random.randint(0, 255)), (50, self.height - 80), (self.width - 50, self.height - 80), 3) self.paint() pygame.display.flip() self.screen.blit(self.background, (0, 0)) pygame.quit()
def run(self): """The mainloop """ #self.paint() running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: running = False if event.key == pygame.K_DOWN or event.key == pygame.K_KP2: m.nextitem() print(m.active_itemnumber) if event.key == pygame.K_UP or event.key == pygame.K_KP8: m.previousitem() if event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER: result = m.get_text() print(result) if result is None: break elif "x" in result: # change screen resolution, menu text is something like "800x600" left = result.split("x")[0] right = result.split("x")[1] if str(int(left)) == left and str( int(right)) == right: PygView.width = int(left) PygView.height = int(right) self.set_resolution() # important: no elif here, instead if, because every menupoint could contain an 'x' elif result == "Play": print("activating external program") pygame.quit() # START GAME print("bye") self.__init__() elif result == "Help": text = "You need to\ncontrol a ship\nand make graphics\nwhile the other, automated\nplayer flies around!" textscroller_vertical.PygView( text, self.width, self.height).run() elif result == "Turn music off": #TURN MUSIC OFF Settings.menu["Options"][0] = "Turn music on" elif result == "Turn music on": #TURN MUSIC ON Settings.menu["Options"][0] = "Turn music off" elif result == "Turn sound off": #TURN MUSIC OFF Settings.menu["Options"][1] = "Turn sound on" elif result == "Turn sound on": #TURN MUSIC ON Settings.menu["Options"][1] = "Turn sound off" elif result == "Simon HEPPNER": text = "Programmer of this\ngame. Likes Yoghurt!\n:D" textscroller_vertical.PygView( text, self.width, self.height).run() elif result == "Horst JENS": text = "Programming-Teacher of\nSimon HEPPNER.\nIs pleased to contribute!" textscroller_vertical.PygView( text, self.width, self.height).run() elif result == "Quit": print("Bye") pygame.quit() sys.exit() milliseconds = self.clock.tick(self.fps) self.playtime += milliseconds / 1000.0 self.draw_text("FPS: {:6.3}{}PLAYTIME: {:6.3} SECONDS".format( self.clock.get_fps(), " " * 5, self.playtime), color=(30, 120, 18)) pygame.draw.line(self.screen, (random.randint( 0, 255), random.randint(0, 255), random.randint(0, 255)), (50, self.height - 80), (self.width - 50, self.height - 80), 3) self.paint() pygame.display.flip() self.screen.blit(self.background, (0, 0)) pygame.quit()
def run(self): """The mainloop """ #self.paint() running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: running = False if event.key == pygame.K_DOWN or event.key == pygame.K_KP2: #print(m.active_itemnumber) m.nextitem() print(m.active_itemnumber) #self.sound2.play() if event.key == pygame.K_UP or event.key == pygame.K_KP8: m.previousitem() #self.sound1.play() if event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER: #self.sound3.play() result = m.get_text() #print(m.get_text()) print(result) if result is None: break elif "x" in result: # change screen resolution, menu text is something like "800x600" left = result.split("x")[0] right = result.split("x")[1] if str(int(left)) == left and str( int(right)) == right: PygView.width = int(left) PygView.height = int(right) self.set_resolution() # important: no elif here, instead if, because every menupoint could contain an 'x' elif result == "Play": # simpledefense.PygView().run() print("activating external program") #externalProgram.PygView(self.width, self.height) pygame.quit() template004_sprites_collision_detection.PygView( 900, 900).run() #sys.exit() print("bye") self.__init__() elif result == "buy blue defender": self.cash.play() if Settings.gold >= Settings.price_blue: Settings.gold -= Settings.price_blue Settings.blue_defenders += 1 else: print("earn some money first") elif result == "buy red defender": self.cash.play() if Settings.gold >= Settings.price_red: Settings.gold -= Settings.price_red Settings.red_defenders += 1 else: print("earn some money first") elif result == "buy blue attacker": self.cash.play() if Settings.gold >= Settings.price_blue: Settings.gold -= Settings.price_blue Settings.blue_attackers += 1 else: print("earn some money first") elif result == "buy red attacker": self.cash.play() if Settings.gold >= Settings.price_red: Settings.gold -= Settings.price_red Settings.red_attackers += 1 else: print("earn some money first") #------ sell ------ elif result == "sell blue defender": self.cash.play() if Settings.blue_defenders > 0: Settings.gold += Settings.price_blue / 2 Settings.blue_defenders -= 1 else: print("you have no blue defenders") elif result == "sell red defender": self.cash.play() if Settings.red_defenders > 0: Settings.gold += Settings.price_red / 2 Settings.red_defenders -= 1 else: print("you have no red defenders") elif result == "sell blue attacker": self.cash.play() if Settings.blue_attackers > 0: Settings.gold += Settings.price_blue / 2 Settings.blue_attackers -= 1 else: print("you have no blue attackers") elif result == "sell red attacker": self.cash.play() if Settings.red_attackers > 0: Settings.gold += Settings.price_red / 2 Settings.red_attackers -= 1 else: print("you have no red attackers") elif result == "how to play": text = "play this game\n as you like\n and win!" textscroller_vertical.PygView( text, self.width, self.height).run() elif result == "nix": text = "nix\n gar nix\n wirklich nix!" textscroller_vertical.PygView( text, self.width, self.height).run() elif result == "how to win": text = "to win the game:\n shoot down enemies\n avoid catching bullets" textscroller_vertical.PygView( text, self.width, self.height, bg_filename=os.path.join( "data", "800px-La_naissance_de_Venus.jpg")).run() elif result == "False": Settings.menu["Credits"][2] = "True" # toggle elif result == "True": Settings.menu["Credits"][2] = "False" # toggle elif result == "Quit": print("Bye") pygame.quit() sys.exit() milliseconds = self.clock.tick(self.fps) self.playtime += milliseconds / 1000.0 self.draw_text("FPS: {:6.3}{}PLAYTIME: {:6.3} SECONDS".format( self.clock.get_fps(), " " * 5, self.playtime), color=(30, 120, 18)) pygame.draw.line(self.screen, (random.randint( 0, 255), random.randint(0, 255), random.randint(0, 255)), (50, self.height - 80), (self.width - 50, self.height - 80), 3) self.paint() pygame.display.flip() self.screen.blit(self.background, (0, 0)) pygame.quit()
def run(self): """The mainloop """ #self.paint() running = True while running: self.screen.blit(self.background, (0, 0)) milliseconds = self.clock.tick(self.fps) seconds = milliseconds / 1000 self.playtime += milliseconds / 1000.0 self.allgroup.draw(self.screen) self.allgroup.update(seconds) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: if self.sounds is True: self.sound2.play() result = m.get_text() print(result) if result is None: break elif "x" in result: # change screen resolution, menu text is something like "800x600" left = result.split("x")[0] right = result.split("x")[1] if str(int(left))==left and str(int(right))== right: PygView.width = int(left) PygView.height = int(right) self.set_resolution() # important: no elif here, instead if, because every menupoint could contain an 'x' elif result == "Play": print("activating external program") # start imported game print("bye") self.__init__() elif result == "How to play": text = "play this game\n as you like\n and win!" textscroller_vertical.PygView(text, self.width, self.height).run() pygame.display.set_caption("Press ESC to quit") elif result == "How to win": text = "to win the game:\n shoot down enemies\n avoid catching bullets" textscroller_vertical.PygView(text, self.width, self.height).run() pygame.display.set_caption("Press ESC to quit") elif result == "Simon HEPPNER": text = "Programmer of this game!\n:D" textscroller_vertical.PygView(text, self.width, self.height).run() pygame.display.set_caption("Press ESC to quit") elif result == "Sounds off": Settings.menu["Options"][1] = "Sounds on" self.sounds = False elif result == "Sounds on": Settings.menu["Options"][1] = "Sounds off" self.sounds = True elif result == "Quit": print("Bye") pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: running = False #if event.key == pygame.K_DOWN or event.key == pygame.K_KP2: # #print(m.active_itemnumber) # m.nextitem() # print(m.active_itemnumber) # #self.sound2.play() #if event.key == pygame.K_UP or event.key == pygame.K_KP8: # m.previousitem() # print(m.active_itemnumber) # #self.sound1.play() #if event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER: # #self.sound3.play() # result = m.get_text() # #print(m.get_text()) # print(result) # if result is None: # break # elif "x" in result: # # change screen resolution, menu text is something like "800x600" # left = result.split("x")[0] # right = result.split("x")[1] # if str(int(left))==left and str(int(right))== right: # PygView.width = int(left) # PygView.height = int(right) # self.set_resolution() ## # # # important: no elif here, instead if, because every menupoint could contain an 'x' # elif result == "Play": # print("activating external program") # # start imported game # print("bye") # self.__init__() # elif result == "How to play": # text = "play this game\n as you like\n and win!" # textscroller_vertical.PygView(text, self.width, self.height).run() # elif result == "How to win": # text = "to win the game:\n shoot down enemies\n avoid catching bullets" # textscroller_vertical.PygView(text, self.width, self.height).run() # elif result == "Simon HEPPNER": # text = "Programmer of this game!\n:D" # textscroller_vertical.PygView(text, self.width, self.height).run() # elif result == "Quit": # print("Bye") # pygame.quit() # sys.exit() if self.clock.get_fps() > 30: self.draw_text("{} FPS: {:6.3}".format(" "*12, self.clock.get_fps()), color=(30, 180, 90)) elif self.clock.get_fps() > 20 and self.clock.get_fps() < 30: self.draw_text("{} FPS: {:6.3}".format(" "*12, self.clock.get_fps()), color=(200, 210, 0)) elif self.clock.get_fps() > 0 and self.clock.get_fps() < 20: self.draw_text("{} FPS: {:6.3}".format(" "*12, self.clock.get_fps()), color=(240, 70, 60)) pygame.draw.line(self.screen,(random.randint(0,255),random.randint(0,255), random.randint(0,255)),(50,self.height - 80),(self.width -50,self.height - 80) ,3) self.paint() pygame.display.flip() pygame.quit()
def run(self): """The mainloop """ #self.paint() running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: running = False if event.key==pygame.K_DOWN or event.key == pygame.K_KP2: #print(m.active_itemnumber) m.nextitem() print(m.active_itemnumber) #self.sound2.play() if event.key==pygame.K_UP or event.key == pygame.K_KP8: m.previousitem() #self.sound1.play() if event.key==pygame.K_RETURN or event.key == pygame.K_KP_ENTER: #self.sound3.play() result = m.get_text() #print(m.get_text()) print(result) if result is None: break elif "x" in result: # change screen resolution, menu text is something like "800x600" left = result.split("x")[0] right = result.split("x")[1] if str(int(left))==left and str(int(right))== right: PygView.width = int(left) PygView.height = int(right) self.set_resolution() # important: no elif here, instead if, because every menupoint could contain an 'x' elif result=="Play": print("activating external program") ballwars.PygView(PygView.width, PygView.height,bouncefactor = Settings.bounce, maxgoal=Settings.maxgoal,playermass = Settings.mass, playerspeed = Settings.speed, ai = Settings.ai, difficulty = Settings.difficulty).run() print("bye") self.__init__() elif result == "*1": Settings.bounce = 1 elif result == "*2": Settings.bounce = 2 elif result == "*3": Settings.bounce = 3 elif result == "EXTREME difficulty": Settings.difficulty = 10 elif result == "normal difficulty": Settings.difficulty = 1 elif result == "1 player": Settings.ai = True elif result == "2 player": Settings.ai = False elif result == "normalspeed": Settings.speed = 10 elif result == "halfspeed": Settings.speed = 5 elif result == "doublespeed": Settings.speed = 20 elif result == "normalmass": Settings.mass = 1000 elif result == "light": Settings.mass = 500 elif result == "fat": Settings.mass = 2500 elif result == "as heavy as the earth": Settings.mass = 100000 elif result == "1": Settings.maxgoal = 1 elif result == "2": Settings.maxgoal = 2 elif result == "3": Settings.maxgoal = 3 elif result == "4": Settings.maxgoal = 4 elif result == "5": Settings.maxgoal = 5 elif result == "6": Settings.maxgoal = 6 elif result == "7": Settings.maxgoal = 7 elif result == "8": Settings.maxgoal = 8 elif result == "9": Settings.maxgoal = 9 elif result == "10": Settings.maxgoal = 10 elif result == "100": Settings.maxgoal = 100 elif result == "9999": Settings.maxgoal = 9999 elif result == "how to play": text="play this game\n as you like\n and win!" textscroller_vertical.PygView(text, self.width, self.height).run() elif result == "nix": text="nix\n gar nix\n wirklich nix!" textscroller_vertical.PygView(text, self.width, self.height).run() elif result == "how to win": text="to win the game:\n shoot down enemies\n avoid catching bullets" textscroller_vertical.PygView(text, self.width, self.height, bg_filename=os.path.join("data", "800px-La_naissance_de_Venus.jpg")).run() elif result == "False": Settings.menu["Credits"][2] = "True" # toggle elif result == "True": Settings.menu["Credits"][2] = "False" # toggle elif result=="Quit": print("Bye") pygame.quit() sys.exit() milliseconds = self.clock.tick(self.fps) self.playtime += milliseconds / 1000.0 self.draw_text("FPS: {:6.3}{}PLAYTIME: {:6.3} SECONDS".format( self.clock.get_fps(), " "*5, self.playtime), color=(30, 120 ,18)) pygame.draw.line(self.screen,(random.randint(0,255),random.randint(0,255), random.randint(0,255)),(50,self.height - 80),(self.width -50,self.height - 80) ,3) self.paint() pygame.display.flip() self.screen.blit(self.background, (0, 0)) pygame.quit()