Пример #1
0
 def main(self):
     self.had_text = bool(self.text)
     while not self.done:
         self.events()
         self.draw()
         self.update()
     if not self.options_lock:
         pygame.mixer.music.fadeout(1000)
         black_out(self.display, 5)
 def main(self):
     self.draw()
     fade_in(self.display, 3)
     while not self.done:
         self.events()
         self.draw()
         self.update()
     if not (self.retry or self.exit):
         black_out(self.display, 3)
     return self.retry, self.exit
 def main(self):
     self.fade_in()
     joystick.Reset()
     while not self.done:
         self.events()
         self.draw()
         self.update()
     black_out(self.display, 5)
     joystick.Reset()
     pygame.mixer.music.fadeout(500)
     return self.map[self.selected_point].mission, self.selected_point
 def main(self):
     pygame.event.set_grab(True)
     joystick.Reset()
     while not self.done:
         self.events()
         self.draw()
         self.update()
     pygame.mixer.music.fadeout(1000)
     black_out(self.Display, 5)
     joystick.Reset()
     pygame.event.set_grab(False)
     return self.profile
Пример #5
0
    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 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":
                black_out(display, 5)
                pygame.quit()
                sys.exit()
    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:
                if event.button in (1, 3):
                    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)
                    black_out(self.display, 5)
                    self.profile = spacemap.main()
                    self.__init__(self.images, self.display, self.profile,
                                  self.profile_number)
                    self.fade_in()
                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
                    background = self.display.copy()
                    self.draw()
                    fade_in(self.display, 2, background)