def events(self):
     for event in pygame.event.get():
         joystick.Update(event)
         if not hasattr(event, "key"):
             event.key = None
         if event.type == pygame.KEYUP or joystick.WasEvent():
             if event.key == pygame.K_F2 or joystick.JustPressedLB():
                 screenshot.capture("WL", self.display)
             if event.key == pygame.K_ESCAPE or joystick.BackEvent():
                 self.money_old = self.money_new
             if event.key == pygame.K_TAB:
                 self.top_selected = not self.top_selected
             if event.key == pygame.K_UP or joystick.JustWentUp():
                 self.top_selected = True
             if event.key == pygame.K_DOWN or joystick.JustWentDown():
                 self.top_selected = False
             if event.key == pygame.K_y or joystick.JustPressedY():
                 self.info()
             if event.key == pygame.K_RETURN or joystick.JustPressedA():
                 self.stopped = True
                 if self.mode == "won":
                     self.register_sound.play()
                 self.money_sound.stop()
                 if self.top_selected:
                     self.done = True
                 else:
                     self.done = True
                     self.exit = True
 def events(self):
     for event in pygame.event.get():
         joystick.Update(event)
         if not hasattr(event, "key"):
             event.key = None
         if event.type == pygame.KEYUP or joystick.WasEvent():
             if event.key == pygame.K_F2 or joystick.JustPressedLB():
                 screenshot.capture("WL", self.display)
             if event.key == pygame.K_ESCAPE or joystick.BackEvent():
                 self.money_old = self.money_new
             if event.key == pygame.K_TAB:
                 self.selected_option += 1
                 if self.selected_option > self.options_range[1]:
                     self.selected_option = self.options_range[0]
             if event.key == pygame.K_UP or joystick.JustWentUp():
                 self.selected_option = clamp(self.selected_option - 1,
                                              *self.options_range)
             if event.key == pygame.K_DOWN or joystick.JustWentDown():
                 self.selected_option = clamp(self.selected_option + 1,
                                              *self.options_range)
             if event.key == pygame.K_y or joystick.JustPressedY():
                 self.info()
             if event.key == pygame.K_RETURN or joystick.JustPressedA():
                 self.stopped = True
                 self.done = True
                 if self.mode == "won":
                     self.register_sound.play()
                 self.money_sound.stop()
                 text = self.text[self.selected_option]
                 if text == "Retry":
                     self.retry = True
                 if text == "Exit Game":
                     self.exit = True
    def info(self):
        display = self.display.copy()
        done = False
        rect = pygame.Rect(0, 0, 600, 400)
        rect.center = self.display.get_rect().center
        data = f"""
Shots fired: {len(self.acc)}
Shots hit: {self.acc.count(True)}
Shots missed: {self.acc.count(False)}
Accuracy: {self.acc_per2}%

Total attempts to beat this level:{self.lost}

Max Combo: {self.maxcombo}"""
        while not done:
            for event in pygame.event.get():
                joystick.Update(event)
                if not hasattr(event, "key"):
                    event.key = None
                if event.type == pygame.QUIT:
                    done = True
                if event.type == pygame.KEYUP or joystick.WasEvent():
                    if event.key == pygame.K_F2 or joystick.JustPressedLB():
                        screenshot.capture("WL_info", self.display)
                    if event.key in (pygame.K_q, pygame.K_ESCAPE,
                                     pygame.K_RETURN, pygame.K_SPACE,
                                     pygame.K_y) or joystick.BackEvent(
                                     ) or joystick.GoEvent():
                        done = True
            self.display.blit(display, (0, 0))
            pygame.draw.rect(self.display, (40, 40, 40), rect)
            pygame.draw.rect(self.display, (255, 255, 0), rect, 1)
            for index, line in enumerate(data.split("\n")):
                retro_text((121, 142 + index * 14),
                           self.display,
                           14,
                           line,
                           color=(0, 0, 0))
                retro_text((120, 140 + index * 14), self.display, 14, line)
            pygame.display.update()
        joystick.Reset()
Пример #4
0
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()
Пример #5
0
def congrats(display, images, mode, data, profile=None):
    """Display a screen for awarding achievements / unlocking planets"""
    done = False
    pf = 1
    pt = 0
    pfr = 1 / 25
    time_passed = 0
    total_time_passed = 0
    clock = pygame.time.Clock()
    if profile and mode == "ach":
        Sound(fix_path("audio/cashRegister.wav")).play()
        profile["money"] += data[2]
        profile["achievements"].append(data[0])
    while not done:
        for event in pygame.event.get():
            joystick.Update(event)
            if not hasattr(event, "key"):
                event.key = None
            if event.type == pygame.KEYDOWN or joystick.WasEvent():
                if event.key in (pygame.K_RETURN,
                                 pygame.K_ESCAPE) or joystick.GoEvent(
                                 ) or joystick.BackEvent():
                    done = True
                if event.key == pygame.K_F2 or joystick.JustPressedLB():
                    screenshot.capture("_congrats", display)
        display.blit(images["background"], (0, 0))
        if not mode == "store":
            retro_text((400, 100),
                       display,
                       24,
                       "Congratulations!",
                       font="impact",
                       anchor="center")
        stuff_rect = pygame.Rect(0, 0, 450, 350)
        if mode == "ach":
            stuff_rect.w *= 1.5
        stuff_rect.midtop = (400, 90)
        stuff_surf = pygame.Surface(stuff_rect.size)
        stuff_surf.fill((255, 0, 255))
        stuff_surf.set_alpha(50)
        display.blit(stuff_surf, stuff_rect)
        if mode == "planet" or mode == "store":
            rgba = ""
            if data.rgba:
                rgba = "RGBA"
            name = f"spinning{data.name}{rgba}{pf}"
            if not name in images:
                name = f"still_{data.name.lower()}"
            image = images[name]
            rect = pygame.Rect(0, 0, 100, 100)
            rect.center = (400, 200)
            display.blit(pygame.transform.scale(image, (100, 100)), rect)
            text = ""
            if not mode == "store":
                retro_text((400, 300),
                           display,
                           14,
                           f"You have unlocked Planet {data.name}",
                           anchor="center")
            else:
                retro_text((400, 300),
                           display,
                           14,
                           f"Restocked Store on {data.name}",
                           anchor="center")
            pt += time_passed
            if pt >= pfr:
                pf += 1
                pt = 0
            if pf > 25:
                pf = 1
        if mode == "ach":  # Short for achievement
            retro_text((400, 250),
                       display,
                       17,
                       f"{data[0]} Achievement Unlocked!",
                       anchor="center",
                       font="Sans")
            retro_text((400, 280),
                       display,
                       15,
                       data[1],
                       anchor="center",
                       bold=True,
                       font="Sans")
            retro_text((400, 300),
                       display,
                       15,
                       f"Money Earned: {data[2]}",
                       bold=True,
                       font="Sans",
                       anchor="center")
        if total_time_passed >= 15:
            done = True
        pygame.display.update()
        time_passed = clock.tick(60) / 1000
        total_time_passed += time_passed
Пример #6
0
    def events(self):
        for event in pygame.event.get():
            joystick.Update(event)
            click = False
            if event.type == pygame.QUIT:
                confirmExit(self.display, self.profile, self.profile_number)
                self.pause_time = True
            if event.type == pygame.MOUSEBUTTONDOWN:
                sel = self.selected_point
                rect = pygame.Rect((0, 0), (220, 50))
                rect.midtop = self.map[sel].pos[0], self.map[sel].pos[1] + 35
                backrect = pygame.Rect(0, 0, 32, 32)
                if rect.collidepoint(pygame.mouse.get_pos()):
                    click = True
                elif backrect.collidepoint(pygame.mouse.get_pos()):
                    self.toMenu = True
                    self.done = True
                self.click = True
            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(self.profile_number, self.display)
                    self.pause_time = True
                if event.key == pygame.K_RETURN or event.key == pygame.K_SPACE or joystick.GoEvent():
                    click = True
                if event.key == pygame.K_ESCAPE or joystick.BackEvent():
                    tmm = pause_menu(self.display, self.images, self.profile, self.profile_number)
                    self.pause_time = True
                    if tmm:
                        self.toMenu = True
                        self.done = True
            if event.type == pygame.KEYUP or joystick.WasEvent():
                tabbed = False
                sel = self.selected_point
                if (event.key == pygame.K_TAB) and not self.map[self.selected_point].alien_flag:
                    sel += 1
                    tabbed = True
                FB = self.GoForwardOrBack(event)
                if (FB):
                    sel += 1
                if (FB == False):
                    sel -= 1
#                if (event.key == pygame.K_LEFT or joystick.JustWentLeft()):
#                    sel -= 1
#                if (event.key == pygame.K_RIGHT or joystick.JustWentRight()) and not self.map[self.selected_point].alien_flag:
#                    sel += 1
                if (event.key == pygame.K_END or joystick.JustPressedRT()):
                    self.waypoints = []
                    x = 0
                    for x in range(self.selected_point, len(self.map)):
                        self.waypoints.append(x)
                        if self.map[x].alien_flag:
                            break
                    sel = x
                    if self.waypoints:
                        self.target_pos = self.get_point(self.waypoints[0])
                        self.changed = True
                if (event.key == pygame.K_HOME or joystick.JustPressedLT()):
                    self.waypoints = []
                    x = 0
                    for x in reversed(range(self.selected_point)):
                        self.waypoints.append(x)
                        if self.map[x].alien_flag:
                            break
                    sel = x
                    if self.waypoints:
                        self.target_pos = self.get_point(self.waypoints[0])
                        self.changed = True
                self.selected_point = sel
                if self.target_pos != self.avatar_pos:
                    self.waypoints.append(sel)
                if self.selected_point < 0:
                    self.selected_point = 0
                yes = False
                if self.waypoints:
                    if self.waypoints[-1] >= len(self.map):
                        yes = True
                if self.selected_point >= len(self.map) or yes:
                    if yes:
                        self.waypoints[-1] = len(self.map) - 1
                    if tabbed and not yes:
                        self.selected_point = 0
                        self.waypoints += list(reversed(range(len(self.map))))
                        for x in reversed(range(len(self.map))):
                            if x > 0:
                                if self.map[x - 1].alien_flag:
                                    break
                            self.waypoints.append(x)
                    else:
                        self.selected_point = len(self.map) - 1
            if self.target_pos == self.avatar_pos and click:
                t = self.map[self.selected_point].type
                if t == "spaceport":
                    spacemap = SpaceMap(self.images, self.display, self.profile, self.profile_number, focus = self.planet.name)
                    transition(self.display, 5)
                    self.profile = spacemap.main()
                    self.__init__(self.images, self.display, self.profile, self.profile_number)
                if t == "mission":
                    self.done = True
                if t == "store":
                    sel1 = self.selected_point
                    store = StoreUI(self.display, self.images, self.profile, self.profile_number, self.map[self.selected_point])
                    if store.main():
                        self.waypoints = []
                        self.target_pos = self.get_point(0)
                        self.changed = True
                        self.avatar_pos = self.get_point(0)
                        self.set_velocity()
                        self.selected_point = 0
Пример #7
0
 def events(self):
     for event in pygame.event.get():
         joystick.Update(event)
         click = False
         if event.type == pygame.QUIT:
             confirmExit(self.Display, self.profile, self.profile_number)
         if event.type == pygame.MOUSEBUTTONDOWN and not self.focused in ("theSun", None):
             planet = self.planets[self.focused]
             rect = pygame.Rect((0, 0), (205, 50))
             rect.midtop = planet.center[1][0], planet.center[1][1] + 35
             if rect.collidepoint(pygame.mouse.get_pos()):
                 click = True
         if event.type == pygame.MOUSEBUTTONDOWN:
             self.start_click = pygame.math.Vector2(pygame.mouse.get_pos())
             self.last_sample = copy.copy(self.start_click)
             if pygame.Rect(0, 0, 32, 32).collidepoint(pygame.mouse.get_pos()):
                 self.done = True
             rect = pygame.Rect(0, 0, 32, 32)
             rect.midright = self.Display.get_rect().midright
             if rect.collidepoint(pygame.mouse.get_pos()):
                 for e, p in enumerate(self.planets):
                     if p.name == "Earth":
                         self.focused = e
         if event.type == pygame.MOUSEBUTTONUP:
             self.start_click = None
         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():
                 self.done = True
             if event.key == pygame.K_RETURN or event.key == pygame.K_SPACE or joystick.GoEvent():
                 click = True
             if event.key == pygame.K_LEFT or joystick.JustWentLeft():
                 self.speed -= .1
                 if self.speed <= 0.2:
                     self.speed = 0.2
             if event.key == pygame.K_RIGHT or joystick.JustWentRight():
                 self.speed += .1
                 if self.speed > 2:
                     self.speed = 2
             if event.key == pygame.K_F2 or joystick.JustPressedLB():
                 screenshot.capture(self.profile_number, self.Display)
             if event.key == pygame.K_COMMA or joystick.JustPressedLT():
                 if self.focused == None:
                     self.focused = 0
                 self.focused = (self.focused + 1) % len(self.planets)
                 self.target_zoom = 1.5
             if event.key == pygame.K_PERIOD or joystick.JustPressedRT():
                 if self.focused == None:
                     self.focused = 0
                 self.focused = (self.focused - 1) % len(self.planets)
                 self.target_zoom = 1.5
         if event.type == pygame.MOUSEMOTION:
             self.mouse_on = True
         if event.type == pygame.MOUSEBUTTONUP:
             pos = pygame.mouse.get_pos()
             nto = self.target_offset[:]
             if event.button == 5:
                 self.target_zoom -= self.zoom_amount
                 nto[0] -= (pos[0] - self.Display.get_width() / 2) / 10
                 nto[1] -= (pos[1] - self.Display.get_height() / 2) / 10
             if event.button == 4:
                 self.target_zoom += self.zoom_amount
                 nto[0] += (pos[0] - self.Display.get_width() / 2) / 10
                 nto[1] += (pos[1] - self.Display.get_height() / 2) / 10
             if self.target_zoom < .5:
                self.target_zoom = .5
             elif self.target_zoom > 2:
                 self.target_zoom = 2
             else:
                 self.target_offset = nto
         if not self.focused in ("theSun", None) and self.zoom >= 1.25 and click and self.planets[self.focused] in self.unlocked_planets:
             self.profile["planet"] = self.planets[self.focused]
             self.done = True
    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