def main(self): while not self.done: self.events() self.draw() self.update() saves.save_data(self.profile_selected, self.profile) pygame.mixer.music.fadeout(1000)
def main(self): background = self.display.copy() self.draw() fade_in(self.display, 3, background) while not self.done: self.events() self.draw() self.update() saves.save_data(self.profile_selected, self.profile) pygame.mixer.music.fadeout(1000)
def confirmExit(display, profile, num): button_selected = 0 buttons = ["Save + Exit", "Exit", "Cancel"] rect = pygame.Rect(0, 0, 150, 50) points = [(150, 400), (400, 400), (650, 400)] rect1, rect2, rect3 = rect.copy(), rect.copy(), rect.copy() rect1.midleft = points[0] rect2.center = points[1] rect3.midright = points[2] rects = [rect1, rect2, rect3] old_display = display.copy() surf2 = old_display.copy() surf2.fill((30, 30, 30)) surf2.set_alpha(150) old_display.blit(surf2, (0, 0)) while True: click = False for event in pygame.event.get(): mpos = pygame.mouse.get_pos() joystick.Update(event) if not hasattr(event, 'key'): event.key = None if event.type == pygame.KEYDOWN or joystick.WasEvent(): if event.key == pygame.K_F2 or joystick.JustPressedLB(): screenshot.capture(num, display) if event.type == pygame.MOUSEMOTION: for rect in rects: if rect.collidepoint(mpos): button_selected = rects.index(rect) break if event.type == pygame.MOUSEBUTTONDOWN: for rect in rects: if rect.collidepoint(mpos): click = True if event.type == pygame.KEYUP or joystick.WasEvent(): if event.key == pygame.K_ESCAPE or joystick.BackEvent(): return if event.key == pygame.K_LEFT or joystick.JustWentLeft(): button_selected -= 1 if event.key == pygame.K_RIGHT or joystick.JustWentRight(): button_selected += 1 if button_selected < 0: button_selected = 0 if button_selected > 2: button_selected = 2 if event.key == pygame.K_RETURN or joystick.JustPressedA(): click = True display.blit(old_display, (0, 0)) retro_text((400, 302), display, 30, "Exit?", anchor="midbottom", bold=True, color=(0, 0, 0)) retro_text((400, 300), display, 30, "Exit?", anchor="midbottom", bold=True) for n, rect in enumerate(rects): color = (75, 75, 75) tcolor = (255, 255, 255) if n == button_selected: color = (50, 50, 50) tcolor = (255, 255, 255) pygame.draw.rect(display, (0, 0, 0), rect.move(2, 2)) pygame.draw.rect(display, color, rect) retro_text(rect.move(0, 2).center, display, 12, buttons[n], color = (0, 0, 0), anchor="center") retro_text(rect.center, display, 12, buttons[n], color = tcolor, anchor="center") pygame.display.update() clock.tick(10) if click: name = buttons[button_selected] if name == "Cancel": return if name == "Save + Exit": saves.save_data(num, profile) pygame.quit() sys.exit() if name == "Exit": transition(display, 5) pygame.quit() sys.exit()
def main(self): point = None retry = False mission = None while True: if not retry: Map = maps.Map(self.images, self.Display, self.profile, self.profile_selected, point) mission, point = Map.main() old_mission = mission if Map.toMenu: background = self.Display.copy() self.menu() point = None continue play = game.Game(self.display, self.Display, self.images, mission, self.profile, self.profile_selected, retry) score, mode, acc, maxcombo, im_back = play.main() if play.toMenu: self.menu() point = None continue try: self.acc_per = acc.count(True) / len(acc) except ZeroDivisionError: self.acc_per = 0 for p in self.profile["map"][self.profile["planet"].name]: if p.mission == mission: if mode == "lost": p.lost += 1 break lw = lose_win.LoseWin( self.Display, self.images, (self.profile["money"], self.profile["money"] + score, mission().bonus / (p.lost + 1), mission().bonus, acc, p.lost + 1, maxcombo), mode=mode) self.keepGoing(lw) not_finished = False ach = [] if im_back: ach.append("im_back") # I'm Back Achievement if mode == "won": play.victory() self.profile["addNewStore"] -= 1 self.profile["money"] += round(mission().bonus * self.acc_per) self.profile["money"] += round(mission().bonus / (p.lost + 1)) if acc.count(True) >= ((len(acc) / 4) * 3) and acc: ach.append("archer") if maxcombo > 4: ach.append("combo5") if maxcombo > 9: ach.append("combo10") if maxcombo > 14: ach.append("combo15") if maxcombo > 19: ach.append("combo20") for name in mission().unlocks_planets: for p in planetsmoons: if p.name == name: self.profile["unlocked_planets"].append(name) congrats(self.Display, self.images, "planet", p) for a in ach: if ACHIEVEMENTS[a][0] in self.profile["achievements"]: continue congrats(self.Display, self.images, "ach", ACHIEVEMENTS[a], self.profile) r = False while not r: r = stores.confirmStores(self.profile, self.Display, self.images) self.profile = r saves.save_data(self.profile_selected, self.profile) del play retry = lw.retry if lw.exit: black_out(self.Display, 2) pygame.quit() sys.exit()
def events(self): for event in pygame.event.get(): joystick.Update(event) if event.type == pygame.QUIT: self.exit() if event.type == pygame.MOUSEBUTTONDOWN: if not self.finished and not self.options_lock: self.finished = True print(colorize(self.text, 'bold')) self.text = "" if event.type == pygame.KEYDOWN or joystick.WasEvent(): if not hasattr(event, "key"): event.key = None if event.key == pygame.K_F2 or joystick.JustPressedLB(): screenshot.capture("M", self.display) if not self.finished and not self.options_lock: self.finished = True print(colorize(self.text, 'bold')) self.text = "" else: item = self.item_selected items = self.items if self.options_mode: item = self.option_selected items = self.options if self.play_mode: item = self.profile_selected items = self.profiles if event.key == pygame.K_ESCAPE or joystick.BackEvent(): if self.play_mode: self.play_mode = False elif self.options_mode: self.options_mode = False self.options_dict = saves.load_options() else: self.exit() if event.key == pygame.K_UP or joystick.JustWentUp(): item -= 1 if (event.key == pygame.K_DOWN) or joystick.JustWentDown(): item += 1 if item < 0: item = 0 if item >= len(items): item = len(items) - 1 if self.options_mode: self.option_selected = item if self.play_mode: self.profile_selected = item elif self.play_mode: pass else: self.item_selected = item if self.options_mode: op = self.options[self.option_selected] if op == "Volume": vol = self.options_dict["volume"] if event.key == pygame.K_LEFT or joystick.JustWentLeft(): vol -= .1 if event.key == pygame.K_RIGHT or joystick.JustWentRight(): vol += .1 if vol < 0: vol = 0 if vol > 1: vol = 1 self.options_dict["volume"] = vol if op == "Cache Screenshots": if event.key == pygame.K_RETURN or joystick.JustPressedA(): self.options_dict["cache_screen_shots"] = not self.options_dict["cache_screen_shots"] if op == "Stretch to Fullscreen": if event.key == pygame.K_RETURN or joystick.JustPressedA(): self.options_dict["fullscreen"] = not self.options_dict["fullscreen"] if op == self.DEL: if event.key == pygame.K_RETURN or joystick.JustPressedA(): try: DID_SOMETHING = False for e, x in enumerate(os.listdir(fix_path(get_file("data/screenshots")))): os.remove(fix_path(get_file("data/screenshots/")) + x) DID_SOMETHING = True if DID_SOMETHING: print(colorize(f"Deleted screenshots: {e+1}", "green")) self.options[self.options.index(self.DEL)] = "Deleted screenshots" self.DEL = "Deleted screenshots" except FileNotFoundError: print(colorize("Failed to delete screenshots!", "fail")) print(colorize("File not found error.", "fail")) if event.key == pygame.K_x or joystick.JustPressedX(): if self.play_mode: if self.profile_selected < 5 and not self.profiles[self.profile_selected].startswith("New"): self.confirm_delete() if event.key == pygame.K_RETURN or joystick.JustPressedA() or joystick.JustPressedStart(): if self.options_mode: sel = self.option_selected if self.options[sel] == "Cancel": self.option_selected = 2 self.options_mode = False self.options_dict = saves.load_options() if self.options[sel] == "Save": self.options_mode = False saves.save_data("options", self.options_dict) elif self.play_mode: if self.profiles[self.profile_selected] == "Back": self.play_mode = False else: profile = saves.load_profile(self.profile_selected) if profile["version"] != __version__: if profile["new"]: profile["version"] = __version__ else: print(colorize("Warning: this profile is from a different version \ of Interplanetary Invaders; \nerrors may occur", "warning")) profile["new"] = False saves.save_data(self.profile_selected, profile) self.done = True else: sel = self.item_selected if self.items[sel] == "Play": self.play_mode = True if self.items[sel] == "Options": self.options_mode = True if self.items[sel] == "Quit": self.exit() if self.items[sel] == "Credits": run_credits(self.display, self.images) pygame.mixer.music.load(fix_path(get_file("audio/music/MainMenu.mp3"))) pygame.mixer.music.play(-1) if not self.options_mode and self.options_lock: self.done = True
def pause_menu(display, images, data, index, exit_lock=False): from interplanetary_invaders.scripts.menu import Menu from interplanetary_invaders.scripts.saves import save_data from interplanetary_invaders.scripts.retro_text import retro_text joystick.Reset() background = display.copy() done = False sel = 0 items = ["Resume", "Options", "Exit to Main Menu", f"Exit to {platform}"] old_items = items[:] stuff_rect = pygame.Rect(0, 0, 300, 400) stuff_rect.center = display.get_rect().center toMainMenu = False confirm = False while not done: for event in pygame.event.get(): joystick.Update(event) if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN or joystick.WasEvent(): if not hasattr(event, "key"): event.key = None if event.key == pygame.K_ESCAPE or joystick.BackEvent(): done = True if event.key in (pygame.K_w, pygame.K_UP) or joystick.JustWentUp(): sel -= 1 if event.key in (pygame.K_s, pygame.K_DOWN) or joystick.JustWentDown(): sel += 1 if sel < 0: sel = 0 if sel >= len(items): sel = len(items) - 1 if event.key == pygame.K_RETURN or joystick.JustPressedA(): i = items[sel] if confirm: if i == "Save": save_data(index, data) if "Save" in i: if not toMainMenu: pygame.quit() sys.exit() done = True return toMainMenu if i == "Cancel": confirm = False toMainMenu = False items = old_items if i == "Resume": done = True if i == "Options": m = Menu(display, images, True) m.main() if i == f"Exit to {platform}" and not exit_lock: items = ["Cancel", "Save", "Don't Save"] sel = 0 confirm = True if i == "Exit to Main Menu" and not exit_lock: toMainMenu = True items = ["Cancel", "Save", "Don't Save"] sel = 0 confirm = True display.blit(background, (0, 0)) pygame.draw.rect(display, (0, 0, 0), stuff_rect) pygame.draw.rect(display, (255, 255, 0), stuff_rect, 1) for e, i in enumerate(items): color = (255, 255, 255) if e == sel: color = (255, 255, 175) display.blit( images["bullet"], (stuff_rect.left + 5, stuff_rect.top + 50 + e * 30)) retro_text((stuff_rect.left + 10, stuff_rect.top + 50 + e * 30), display, 15, " " + i, color=color) pygame.display.update() return toMainMenu