示例#1
0
    def __init__(self, screen_dim):
        self.screen = None
        pygame.sprite.Sprite.__init__(self)
        self.width = screen_dim[0]
        self.height = screen_dim[1]
        self.image = pygame.Surface((self.width, self.height))
        self.rect = self.image.get_rect()
        self.high_scores = dict()
        self.current_scores = dict()
        self.start_time = 0
        self.display_time = 8
        self.display_over = False

        self.game_over_text = "GAME OVER"
        self.high_score_title_text = "HIGH SCORES"
        self.high_score_labels_text = "RANK     USERNAME     SCORE"

        self.font_super = 100
        self.font_big = 80
        self.font_med = 60
        self.font_small = 50
        self.font_type = 'arial'

        self.game_over = constants.get_text(self.font_type, self.font_super,
                                            constants.RED, self.game_over_text)
        self.high_score_title = constants.get_text(self.font_type,
                                                   self.font_big,
                                                   constants.GREEN,
                                                   self.high_score_title_text)
        self.high_score_labels = constants.get_text(
            self.font_type, self.font_med, constants.GREEN,
            self.high_score_labels_text)
示例#2
0
    def update(self):
        if self.display_over:
            return
        if time.time() - self.start_time > self.display_time:
            self.display_over = True

        self.image.fill(constants.BLACK)
        user1_score_text = self.current_scores['user1'][
            'username'] + "'S SCORE: " + self.current_scores['user1']['score']
        user2_score_text = self.current_scores['user2'][
            'username'] + "'S SCORE: " + self.current_scores['user2']['score']
        user1_score = constants.get_text(self.font_type, self.font_med,
                                         constants.GREEN, user1_score_text)
        user2_score = constants.get_text(self.font_type, self.font_med,
                                         constants.GREEN, user2_score_text)

        for i in range(len(self.high_scores.keys())):
            rank = str(i + 1)
            username = self.high_scores[rank]['username'].upper()
            score = self.high_scores[rank]['score']
            if int(score) < 10:
                score += " "
            high_score_name = f"{rank}            {username}"
            high_score_val = score
            high_score = constants.get_text(self.font_type, self.font_small,
                                            constants.GREEN, high_score_name)
            high_score_val = constants.get_text(self.font_type,
                                                self.font_small,
                                                constants.GREEN,
                                                high_score_val)
            self.image.blit(
                high_score,
                (self.width // 2 - 310, 9 * self.height // 16 +
                 i * self.height // 12 - high_score.get_height() // 2))
            self.image.blit(
                high_score_val,
                (self.width // 2 + 290 - high_score_val.get_width() // 2,
                 9 * self.height // 16 + i * self.height // 12 -
                 high_score.get_height() // 2))

        self.image.blit(self.game_over,
                        (self.width // 2 - self.game_over.get_width() // 2,
                         self.game_over.get_height() // 2))
        self.image.blit(
            self.high_score_title,
            (self.width // 2 - self.high_score_title.get_width() // 2,
             3 * self.height // 8 - self.high_score_title.get_height() // 2))
        self.image.blit(
            self.high_score_labels,
            (self.width // 2 - self.high_score_labels.get_width() // 2,
             self.height // 2 - self.high_score_labels.get_height() // 2))

        self.image.blit(user1_score,
                        (3 * self.width // 16 - user1_score.get_width() // 2,
                         self.height // 4 - user1_score.get_height() // 2))
        self.image.blit(user2_score,
                        (13 * self.width // 16 - user2_score.get_width() // 2,
                         self.height // 4 - user2_score.get_height() // 2))
示例#3
0
 def update(self):
     self.image.fill(constants.BLACK)
     title_text = self.title
     display_text = ""
     if not self.user1_done:
         title_text += "1"
         display_text += self.user1
     elif not self.user2_done:
         title_text += "2"
         display_text += self.user2
     title = constants.get_text(self.font_type, self.font_size,
                                constants.GREEN, title_text)
     display = constants.get_text(self.font_type, self.font_size,
                                  constants.GREEN, display_text)
     self.image.blit(title, (self.width // 2 - title.get_width() // 2,
                             self.height // 3 - title.get_height() // 2))
     self.image.blit(display,
                     (self.width // 2 - display.get_width() // 2,
                      self.height // 2 - display.get_height() // 2))
示例#4
0
    def update(self):
        self.image.fill(constants.BLACK)
        self.image.set_colorkey(constants.BLACK)
        self.time_count += 1
        self.elapsed_time = int(time.time() - self.start_time)
        self.goal1_score = bball1.score
        self.goal2_score = bball2.score

        self.goal1_center = (self.goal1_center[0] + self.goal1_vel,
                             self.goal1_center[1])
        if self.goal1.back_board.right + self.goal1_vel > self.WIDTH // 2 or self.goal1.back_board.left + self.goal1_vel < 0:
            self.goal1_vel = -self.goal1_vel
        self.goal1.draw_goal(self.image, self.goal1_score, self.goal1_center)

        self.goal2_center = (self.goal2_center[0] + self.goal2_vel,
                             self.goal2_center[1])
        if self.goal2.back_board.left + self.goal2_vel < self.WIDTH // 2 or self.goal2.back_board.right + self.goal2_vel > self.WIDTH:
            self.goal2_vel = -self.goal2_vel
        self.goal2.draw_goal(self.image, self.goal2_score, self.goal2_center)

        if self.game_duration - self.elapsed_time >= 0:
            time_text = constants.get_text(
                self.font_type, self.font_size, constants.GREEN,
                f"{self.game_duration - self.elapsed_time}")
            self.image.blit(time_text,
                            (self.WIDTH // 2 - time_text.get_width() // 2,
                             time_text.get_height() // 2))
        else:
            time_text = constants.get_text(self.font_type, self.font_size,
                                           constants.GREEN, "0")
            self.image.blit(time_text,
                            (self.WIDTH // 2 - time_text.get_width() // 2,
                             time_text.get_height() // 2))
        pygame.draw.line(self.image, constants.RED,
                         (self.WIDTH // 2, time_text.get_rect().bottom +
                          time_text.get_height()),
                         (self.WIDTH // 2, self.HEIGHT), 2)
        if self.game_duration - self.elapsed_time < 0:
            self.time_over = True
            if not bball1.in_motion and not bball2.in_motion:
                self.game_over = True
示例#5
0
 def __init__(self, screen_dim):
     pygame.sprite.Sprite.__init__(self)
     self.width = screen_dim[0]
     self.height = screen_dim[1]
     self.image = pygame.Surface((self.width, self.height))
     self.rect = self.image.get_rect()
     self.title_text = "CONTROLLER SELECTION"
     self.sub_text = "PLAYER 1 PRESS YOUR LEFT BUTTON                                                  PLAYER 2 PRESS YOUR RIGHT BUTTON"
     self.font_type = 'arial'
     self.font_big = 100
     self.font_norm = 35
     self.title = constants.get_text(self.font_type, self.font_big,
                                     constants.GREEN, self.title_text)
     self.sub = constants.get_text(self.font_type, self.font_norm,
                                   constants.GREEN, self.sub_text)
     self.image.blit(self.title,
                     (self.width // 2 - self.title.get_width() // 2,
                      self.height // 4 - self.title.get_height() // 2))
     self.image.blit(self.sub,
                     (self.width // 2 - self.sub.get_width() // 2,
                      self.height // 2 - self.sub.get_height() // 2))
示例#6
0
 def draw_point(self, surface):
     score_text = constants.get_text(self.font_type, self.font_size,
                                     constants.GREEN, 'DUNKED!')
     surface.blit(score_text,
                  (self.center_board.right + score_text.get_width() // 2,
                   self.center_board.bottom))
     score_text_rect = score_text.get_rect()
     score_text_rect.center = (self.center_board.right +
                               score_text.get_width(),
                               self.center_board.bottom +
                               score_text.get_height() / 2)
     score_text_rect = score_text_rect.inflate(30, 30)
     pygame.draw.ellipse(surface, constants.GREEN, score_text_rect, 7)
示例#7
0
 def draw_goal(self, surface, score, center):
     self.back_board.center = center
     self.center_board = pygame.Rect(
         self.back_board.center[0] - self.width / 5,
         self.back_board.center[1] + 10, self.width / 2.5,
         self.height / 2.5)
     self.hoop = pygame.Rect(self.back_board.center[0] - self.width / 5,
                             self.back_board.bottom - 2, self.width / 2.5,
                             self.height / 5)
     self.draw_board(surface)
     self.draw_hoop(surface)
     score_text = constants.get_text(self.font_type, self.font_size,
                                     constants.GREEN, f"SCORE: {score}")
     surface.blit(score_text,
                  (self.center_pos[0] - score_text.get_width() // 2,
                   score_text.get_height() // 2))
    def update(self):
        self.image.fill(constants.BLACK)
        title = constants.get_text(self.font_type, self.font_big,
                                   constants.GREEN, self.title)
        if self.hover == 0:
            game_choice0 = constants.get_text(self.font_type, self.font_big,
                                              constants.RED, self.game_choice0)
            game_choice1 = constants.get_text(self.font_type, self.font_small,
                                              constants.GREEN,
                                              self.game_choice1)
            gal_diff_choice0 = constants.get_text(self.font_type,
                                                  self.font_small,
                                                  constants.BLACK,
                                                  self.gal_diff_choice0)
            gal_diff_choice1 = constants.get_text(self.font_type,
                                                  self.font_small,
                                                  constants.BLACK,
                                                  self.gal_diff_choice1)
            gal_diff_choice2 = constants.get_text(self.font_type,
                                                  self.font_small,
                                                  constants.BLACK,
                                                  self.gal_diff_choice2)
            if self.difficulty == 0:
                bball_diff_choice0 = constants.get_text(
                    self.font_type, self.font_small, constants.RED,
                    self.bball_diff_choice0)
                bball_diff_choice1 = constants.get_text(
                    self.font_type, self.font_small, constants.GREEN,
                    self.bball_diff_choice1)
            else:
                bball_diff_choice0 = constants.get_text(
                    self.font_type, self.font_small, constants.GREEN,
                    self.bball_diff_choice0)
                bball_diff_choice1 = constants.get_text(
                    self.font_type, self.font_small, constants.RED,
                    self.bball_diff_choice1)
        else:
            game_choice0 = constants.get_text(self.font_type, self.font_small,
                                              constants.GREEN,
                                              self.game_choice0)
            game_choice1 = constants.get_text(self.font_type, self.font_big,
                                              constants.RED, self.game_choice1)
            if self.difficulty == 0:
                gal_diff_choice0 = constants.get_text(self.font_type,
                                                      self.font_small,
                                                      constants.RED,
                                                      self.gal_diff_choice0)
                gal_diff_choice1 = constants.get_text(self.font_type,
                                                      self.font_small,
                                                      constants.GREEN,
                                                      self.gal_diff_choice1)
                gal_diff_choice2 = constants.get_text(self.font_type,
                                                      self.font_small,
                                                      constants.GREEN,
                                                      self.gal_diff_choice2)
            elif self.difficulty == 1:
                gal_diff_choice0 = constants.get_text(self.font_type,
                                                      self.font_small,
                                                      constants.GREEN,
                                                      self.gal_diff_choice0)
                gal_diff_choice1 = constants.get_text(self.font_type,
                                                      self.font_small,
                                                      constants.RED,
                                                      self.gal_diff_choice1)
                gal_diff_choice2 = constants.get_text(self.font_type,
                                                      self.font_small,
                                                      constants.GREEN,
                                                      self.gal_diff_choice2)
            else:
                gal_diff_choice0 = constants.get_text(self.font_type,
                                                      self.font_small,
                                                      constants.GREEN,
                                                      self.gal_diff_choice0)
                gal_diff_choice1 = constants.get_text(self.font_type,
                                                      self.font_small,
                                                      constants.GREEN,
                                                      self.gal_diff_choice1)
                gal_diff_choice2 = constants.get_text(self.font_type,
                                                      self.font_small,
                                                      constants.RED,
                                                      self.gal_diff_choice2)
            bball_diff_choice0 = constants.get_text(self.font_type,
                                                    self.font_small,
                                                    constants.BLACK,
                                                    self.bball_diff_choice0)
            bball_diff_choice1 = constants.get_text(self.font_type,
                                                    self.font_small,
                                                    constants.BLACK,
                                                    self.bball_diff_choice1)

        self.image.blit(title, (self.width // 2 - title.get_width() // 2,
                                self.height // 4 - title.get_height() // 2))
        self.image.blit(game_choice0,
                        (self.width // 2 - game_choice0.get_width() // 2,
                         self.height // 2 - game_choice0.get_height() // 2))
        self.image.blit(
            game_choice1,
            (self.width // 2 - game_choice1.get_width() // 2,
             self.height * 3 // 4 - game_choice1.get_height() // 2))
        self.image.blit(
            gal_diff_choice0,
            (5 * self.width // 8 + game_choice1.get_width() // 4 -
             gal_diff_choice0.get_width() // 2,
             self.height * 3 // 4 - gal_diff_choice0.get_height() // 2))
        self.image.blit(
            gal_diff_choice1,
            (3 * self.width // 4 + game_choice1.get_width() // 4 -
             gal_diff_choice1.get_width() // 2,
             self.height * 3 // 4 - gal_diff_choice1.get_height() // 2))
        self.image.blit(
            gal_diff_choice2,
            (7 * self.width // 8 + game_choice1.get_width() // 4 -
             gal_diff_choice2.get_width() // 2,
             self.height * 3 // 4 - gal_diff_choice2.get_height() // 2))
        self.image.blit(
            bball_diff_choice0,
            (5 * self.width // 8 + game_choice0.get_width() // 4 -
             bball_diff_choice0.get_width() // 2,
             self.height // 2 - bball_diff_choice0.get_height() // 2))
        self.image.blit(
            bball_diff_choice1,
            (3 * self.width // 4 + game_choice1.get_width() // 4 -
             bball_diff_choice1.get_width() // 2,
             self.height // 2 - bball_diff_choice1.get_height() // 2))