コード例 #1
0
 def marathon_result(self, time):
     if type(time) == int:
         Data.increase_day()
         back = pygame.Surface((self.width, self.height))
         back.set_alpha(215)
         back.fill((0, 0, 0))
         self.screen.blit(back, (0, 0))
         self.write(text=f"Fim da Maratona", size=72, where=(self.width / 2, 150))
         position = self.get_position(time)
         if position > 0:
             color = {1: (0, 255, 0), 2: (255, 255, 0), 3: (255, 128, 0)}
             self.write(text=f"{position}º Posição", size=48, where=(self.width / 2, 300), color=color[position])
             self.write(text=f"Você subiu no ranking!", size=38, where=(self.width / 2, 400))
             self.write(text=f"Sua próxima maratona será mais desafiadora!", size=38, where=(self.width / 2, 450))
         else:
             self.write(text=f"Você não alcançou o pódio.", size=48, where=(self.width / 2, 350), color=(255, 0, 0))
         self.write(text="Pressione <Enter> para voltar a treinar", size=32,
                    where=(self.width / 2, self.height / 2 + 200))
         while True:
             for event in pygame.event.get():
                 if event.type == QUIT:
                     pygame.quit()
                     exit()
                 elif event.type == KEYUP and event.key == K_RETURN:
                     return
             pygame.display.update()
     self.on = False
     pygame.mixer.quit()
コード例 #2
0
    def minigame_end(self, result, kind):
        if type(result) == int:
            Data.increase_day()
            back = pygame.Surface((self.width, self.height))
            back.set_alpha(215)
            back.fill((0, 0, 0))
            self.screen.blit(back, (0, 0))
            self.write(text=f"Fim do {Data.get_day()}º dia",
                       size=48,
                       where=(self.width / 2, 300))
            self.write(text="Pressione <Enter> para continuar",
                       size=32,
                       where=(self.width / 2, self.height / 2 + 200))

            if result > 0:
                if kind != '':
                    Data.increase_status(result, kind)
                self.show_win_screen(result, kind)
            else:
                self.show_loss_screen()

            pygame.display.update()
            while True:
                for event in pygame.event.get():
                    if event.type == QUIT:
                        pygame.quit()
                        exit()
                    elif event.type == KEYUP and event.key == K_RETURN:
                        return
        elif not result:
            self.on = False
コード例 #3
0
    def show(self):
        self.on = True
        while self.on:
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    exit()
                if event.type == MOUSEBUTTONDOWN:
                    pass
                elif event.type == MOUSEBUTTONUP:
                    pass

            ex = Data.get_next_exercise()
            if ex == "marathon":
                result, time, level = Marathon(self.screen).marathon(
                    Data.get_character()[1], Data.get_status(),
                    self.sound_status)
                self.marathon_result(time)
            elif ex == "resistance":
                biking_result = Biking(self.screen).biking_minigame(
                    Data.get_character()[1],
                    Data.get_status()["resistance"], self.sound_status)
                self.minigame_end(biking_result, "resistance")
            elif ex == "strength":
                weight_result = WeightLifting(self.screen).weightlifting(
                    Data.get_character()[1],
                    Data.get_status()["strength"], self.sound_status)
                self.minigame_end(weight_result, "strength")
            else:
                corrida_result = CorridaDeObstaculos(
                    self.screen).corrida_obstaculo(Data.get_character()[1],
                                                   Data.get_status()["speed"],
                                                   self.sound_status)
                self.minigame_end(corrida_result, "speed")
コード例 #4
0
 def process_mouseup(self, pos):
     self.reset_imgs()
     if self.input_field["content"] != "":
         if in_bounds(pos, self.usaim_bounds):
             if Data.create_new_person("U", self.input_field["content"]):
                 return "created"
             else:
                 self.input_field["content"] = ""
         elif in_bounds(pos, self.radcliffe_bounds):
             if Data.create_new_person("R", self.input_field["content"]):
                 return "created"
             else:
                 self.input_field["content"] = ""
     if in_bounds(pos, self.backbutton_bounds):
         return "back"
コード例 #5
0
 def show_win_screen(self, result, kind):
     translation = {
         "resistance": "resistência",
         "speed": "velocidade",
         "strength": "força"
     }
     # title
     self.write(text="Você venceu!",
                size=72,
                color=(0, 255, 0),
                where=(self.width / 2, 100))
     # description
     if kind != "":
         if Data.get_status()[kind] <= 90:
             self.write(
                 text=
                 f"+{result} pontos de {translation[kind]} lhe foram atribuidos",
                 size=32,
                 where=(self.width / 2, self.height / 2))
         else:
             self.write(
                 text=
                 f"Você alcançou o limite da {translation[kind]} humana",
                 size=32,
                 where=(self.width / 2, self.height / 2 + 100))
コード例 #6
0
    def drop_new(self):
        """Changes 'Novo jogo' image to its unpressed version. And go to person creation."""
        result = self.new_game.show()
        self.has_save = Data.has_save()

        if result == "created":
            self.controller.show()
コード例 #7
0
    def __init__(self, screen):
        self.width, self.height = pygame.display.get_surface().get_size()
        self.screen = screen
        self.sound_status = True
        self.bg = pygame.transform.scale(
            pygame.image.load(IMAGES_PATH + "bg.png"),
            (self.width, self.height))
        self.title = pygame.transform.scale(
            pygame.image.load(MENU_IMAGES_PATH + "titulo.png"),
            (int(self.width / 12 * 7), int(self.height / 5)))
        self.new_game = NewGame(screen, self.bg)
        self.controller = Controller(screen, self.sound_status)

        self.has_save = Data.has_save()
        self.continue_img = self.scale_it(
            pygame.image.load(MENU_IMAGES_PATH +
                              "continuar-jogo.png").convert_alpha())
        self.new_img = self.scale_it(
            pygame.image.load(MENU_IMAGES_PATH +
                              "novo-jogo.png").convert_alpha())
        self.leave_img = self.scale_it(
            pygame.image.load(MENU_IMAGES_PATH + "sair.png").convert_alpha())
        self.sound_img = pygame.transform.scale(
            pygame.image.load(MENU_IMAGES_PATH +
                              "sound_on.png").convert_alpha(), (215, 150))
コード例 #8
0
    def get_character(self, person):
        try:
            rows = Data.get_character(person)
            row = rows[0]

            self.person = row[0]
            self.days = row[1]
            self.coins = row[2]
            self.speed = row[3]
            self.stamina = row[4],
            self.resistance = row[5]

        except Exception as e:
            pass
コード例 #9
0
 def __init__(self, screen, sound):
     self.screen = screen
     self.width, self.height = pygame.display.get_surface().get_size()
     self.bg = pygame.transform.scale(
         pygame.image.load(IMAGES_PATH + "bg.png"),
         (self.width, self.height))
     self.on = False
     self.saves = Data.get_saves()
     self.sound_status = sound
     self.buttons = {
         "image":
         pygame.transform.scale(
             pygame.image.load(
                 "assets/img/fundo-cinza.png").convert_alpha(), (420, 50)),
         "image_pressed":
         pygame.transform.scale(
             pygame.image.load(
                 "assets/img/fundo-cinza-pressed.png").convert_alpha(),
             (420, 50)),
         "pressed":
         -1,
         "bounds": [
             [(self.width // 3, 275), (self.width // 3 + 420, 275 + 50)],
             [(self.width // 3, 350), (self.width // 3 + 420, 350 + 50)],
             [(self.width // 3, 425), (self.width // 3 + 420, 425 + 50)],
             [(self.width // 3, 500), (self.width // 3 + 420, 500 + 50)],
             [(self.width // 3, 575), (self.width // 3 + 420, 575 + 50)],
         ]
     }
     self.backbutton = {
         "pressed":
         False,
         "image":
         pygame.transform.scale(
             pygame.image.load(NEW_GAME_IMAGES_PATH + "voltar.png"),
             (80, 80)),
         "image_pressed":
         pygame.transform.scale(
             pygame.image.load(NEW_GAME_IMAGES_PATH + "voltar-pressed.png"),
             (80, 80)),
         "bounds": [(16, 16), (16 + 80, 16 + 80)]
     }
コード例 #10
0
ファイル: hud.py プロジェクト: rogigs/run_away_from_fat
 def show_status(self):
     width = 300
     font = pygame.font.Font("assets/font/FreePixel.ttf", 22)
     back = pygame.Surface((312, 124))
     back.set_alpha(128)
     back.fill((128, 128, 128))
     status = Data.get_status()
     self.screen.blit(back, (900, 594))
     # speed
     pygame.draw.rect(self.screen, (0, 255, 0), (906, 600, width / 100 * status["speed"], 30))
     pygame.draw.rect(self.screen, (0, 0, 0), (906, 600, width, 30), width=3)
     text = font.render("VELOCIDADE", True, (0, 0, 0))
     self.screen.blit(text, (906+300/2-text.get_width()/2, 605))
     # strength
     pygame.draw.rect(self.screen, (255, 0, 0), (906, 640, width / 100 * status["strength"], 30))
     pygame.draw.rect(self.screen, (0, 0, 0), (906, 640, width, 30), width=3)
     text = font.render("FORÇA", True, (0, 0, 0))
     self.screen.blit(text, (906+300/2-text.get_width()/2, 645))
     # resistance
     pygame.draw.rect(self.screen, (0, 0, 255), (906, 680, width / 100 * status["resistance"], 30))
     pygame.draw.rect(self.screen, (0, 0, 0), (906, 680, width, 30), width=3)
     text = font.render("RESISTÊNCIA", True, (0, 0, 0))
     self.screen.blit(text, (906+300/2-text.get_width()/2, 685))