示例#1
0
    def render(self, rect):
        (x, y) = (rect.x, rect.y)
        (w, h) = (rect.w, rect.h)
        text_rect = self.surface.get_rect()

        if self.align == 'top left':
            text_rect.topleft = (x, y)
        if self.align == 'top center':
            text_rect.midtop = (x + w / 2, y)
        if self.align == 'top right':
            text_rect.topright = (x + w, y)

        if self.align == 'center left':
            text_rect.midleft = (x, y + h / 2)
        if self.align == 'center center':
            text_rect.center = (x + w / 2, y + h / 2)
        if self.align == 'center right':
            text_rect.midleft = (x + w, y + h / 2)

        if self.align == 'bottom left':
            text_rect.bottomleft = (x, y + h)
        if self.align == 'bottom center':
            text_rect.midbottom = (x + w / 2, y + h)
        if self.align == 'bottom right':
            text_rect.bottomright = (x + w, y + h)

        SCREEN.blit(self.surface, text_rect)
示例#2
0
    def render(self):
        SCREEN.blit(
            pygame.transform.scale(self.bg, (SCREEN_SIZE.W, SCREEN_SIZE.H)),
            (0, 0))

        bad_chars = list('BCDFGHJKLMNPQRSTVWXYZ')
        good_chars = list('AEIOU')
        next_char_at = (self.margin_row + CHAR_SIZE.H) / INCR

        self.frame += 1
        if self.frame % next_char_at == 0:
            if random.random() <= self.probability_of_good_char:
                char = Char(random.choice(good_chars), is_good=True)
            else:
                char = Char(random.choice(bad_chars), is_good=False)
            self.chars_on_screen.append(char)

        if self.body_index_frame is not None:
            for char in self.chars_on_screen:
                char.render()

            self.check_collisions()
            render_player(self.body_index_frame, self.player_size,
                          'bottom center')

            self.chars_on_screen = [
                char for char in self.chars_on_screen if char.fresh
            ]

        pygame.display.update()
示例#3
0
    def render(self):
        SCREEN.blit(pygame.transform.scale(self.bg, (SCREEN_SIZE.W, SCREEN_SIZE.H)), (0, 0))

        if self.solved is True:
            self.solved = False
            self.time_angles = self.generate_time_angles()

        if self.body_index_frame is not None:
            arm_angles = self.generate_arm_angles()
            if arm_angles is not None:
                (hour_angle, minute_angle) = self.time_angles
                (left_arm_angle, rigt_arm_angle) = arm_angles

                print (hour_angle, minute_angle), (left_arm_angle, rigt_arm_angle)
                if ((
                    abs(hour_angle - left_arm_angle) < self.threshold and
                    abs(minute_angle - rigt_arm_angle) < self.threshold
                ) or (
                    abs(hour_angle - rigt_arm_angle) < self.threshold and
                    abs(minute_angle - left_arm_angle) < self.threshold
                )):
                    self.solved = True

            render_player(
                self.body_index_frame,
                self.player_size,
                'bottom right')
示例#4
0
    def render(self):
        SCREEN.blit(
            pygame.transform.scale(self.bg, (SCREEN_SIZE.W, SCREEN_SIZE.H)),
            (0, 0))

        if self.solved is True:
            self.solved = False
            self.time_angles = self.generate_time_angles()

        if self.body_index_frame is not None:
            arm_angles = self.generate_arm_angles()
            if arm_angles is not None:
                (hour_angle, minute_angle) = self.time_angles
                (left_arm_angle, rigt_arm_angle) = arm_angles

                print(hour_angle,
                      minute_angle), (left_arm_angle, rigt_arm_angle)
                if ((abs(hour_angle - left_arm_angle) < self.threshold
                     and abs(minute_angle - rigt_arm_angle) < self.threshold)
                        or
                    (abs(hour_angle - rigt_arm_angle) < self.threshold
                     and abs(minute_angle - left_arm_angle) < self.threshold)):
                    self.solved = True

            render_player(self.body_index_frame, self.player_size,
                          'bottom right')
示例#5
0
    def render(self, rect):
        (x, y) = (rect.x, rect.y)
        (w, h) = (rect.w, rect.h)
        text_rect = self.surface.get_rect()

        if self.align == 'top left':
            text_rect.topleft = (x, y)
        if self.align == 'top center':
            text_rect.midtop = (x + w / 2, y)
        if self.align == 'top right':
            text_rect.topright = (x + w, y)

        if self.align == 'center left':
            text_rect.midleft = (x, y + h / 2)
        if self.align == 'center center':
            text_rect.center = (x + w / 2, y + h / 2)
        if self.align == 'center right':
            text_rect.midleft = (x + w, y + h / 2)

        if self.align == 'bottom left':
            text_rect.bottomleft = (x, y + h)
        if self.align == 'bottom center':
            text_rect.midbottom = (x + w / 2, y + h)
        if self.align == 'bottom right':
            text_rect.bottomright = (x + w, y + h)

        SCREEN.blit(self.surface, text_rect)
示例#6
0
    def render(self):
        SCREEN.blit(pygame.transform.scale(self.bg, (SCREEN_SIZE.W, SCREEN_SIZE.H)), (0, 0))

        bad_chars = list('BCDFGHJKLMNPQRSTVWXYZ')
        good_chars = list('AEIOU')
        next_char_at = (self.margin_row + CHAR_SIZE.H) / INCR

        self.frame += 1
        if self.frame % next_char_at == 0:
            if random.random() <= self.probability_of_good_char:
                char = Char(random.choice(good_chars), is_good=True)
            else:
                char = Char(random.choice(bad_chars), is_good=False)
            self.chars_on_screen.append(char)

        if self.body_index_frame is not None:
            for char in self.chars_on_screen:
                char.render()

            self.check_collisions()
            render_player(
                self.body_index_frame,
                self.player_size,
                'bottom center')

            self.chars_on_screen = [
                char for char in self.chars_on_screen if char.fresh]

        pygame.display.update()
示例#7
0
def game(players):
    input_box = InputBox(440, 340, 480, 50)
    quit_button = Button(690, 520, 80, 50, 'QUIT', 'quit')
    start_button = Button(680, 440, 100, 50, 'START', 'start')
    player_text = Player(140, 160, 130, 50)
    play = GuessWord()
    snowman = SnowMan()
    rand_word = play.random_word()
    print_word = [False for i in range(len(rand_word))]
    in_letter = []
    out_letter = []

    done = False
    start_game = False
    while not done:
        for event in pg.event.get():
            if event.type == pg.QUIT:
                done = True
                pg.quit()
                quit()
            input_box.handle_event(event)
            quit_button.handle_event(event)
            start_game = start_button.handle_event(event)

        SCREEN.fill(PURPLE)
        quit_button.draw(SCREEN)

        if len(out_letter) == 14:
            start_button.draw(SCREEN)
        else:
            if in_letter == list(rand_word):
                if players:
                    won = (len(in_letter) + len(out_letter)) % 2
                    if won:
                        player_text.text = 'Player 2!'
                    else:
                        player_text.text = 'Player 1!'
                    player_text.draw(SCREEN)
                start_button.draw(SCREEN)
            else:
                input_box.draw(SCREEN)
                if input_box.text in rand_word:
                    if input_box.text not in in_letter:
                        in_letter = play.check_in(input_box.text, print_word)
                else:
                    if input_box.text not in out_letter:
                        if len(out_letter) <= 14:
                            out_letter.append(input_box.text)
        play.draw_lines(SCREEN, print_word)
        if start_game:
            done = True
        snowman.wrong_letter = out_letter
        snowman.draw_snowman(SCREEN)

        pg.display.flip()
示例#8
0
    def render(self):
        if self.hidden:
            tint = pygame.Surface((SCREEN_SIZE.W, SCREEN_SIZE.H),
                                  pygame.SRCALPHA)
            tint.fill((0, 0, 0, 150))
            SCREEN.blit(tint, (0, 0))
            self.hidden = False

        SCREEN.fill((100, 100, 100),
                    (SCREEN_SIZE.W - self.width, 0, self.width, SCREEN_SIZE.H))

        self.btn_back.render((SCREEN_SIZE.W - self.width, 0))
        self.btn_menu.render((SCREEN_SIZE.W - self.width, 50))
        self.btn_quit.render((SCREEN_SIZE.W - self.width, 100))

        if self.width < self.max_witdh:
            self.width += 50
示例#9
0
    def render(self):
        SCREEN.blit(self.bg, (0, 0))

        self.game.render(
            ((22 / 1024.0) * SCREEN_SIZE.W, (94 / 768.0) * SCREEN_SIZE.H))
        self.btn_1.render(
            ((345 / 1024.0) * SCREEN_SIZE.W, (94 / 768.0) * SCREEN_SIZE.H))
        self.btn_2.render(
            ((345 / 1024.0) * SCREEN_SIZE.W, (257 / 768.0) * SCREEN_SIZE.H))
        self.btn_3.render(
            ((345 / 1024.0) * SCREEN_SIZE.W, (420 / 768.0) * SCREEN_SIZE.H))
        self.btn_4.render(
            ((184 / 1024.0) * SCREEN_SIZE.W, (420 / 768.0) * SCREEN_SIZE.H))
        self.btn_5.render(
            ((22 / 1024.0) * SCREEN_SIZE.W, (420 / 768.0) * SCREEN_SIZE.H))
        self.profile.render(
            ((22 / 1024.0) * SCREEN_SIZE.W, (582 / 768.0) * SCREEN_SIZE.H))
示例#10
0
    def render(self):
        if self.hidden:
            tint = pygame.Surface(
                (SCREEN_SIZE.W, SCREEN_SIZE.H),
                pygame.SRCALPHA)
            tint.fill((0, 0, 0, 150))
            SCREEN.blit(tint, (0, 0))
            self.hidden = False

        SCREEN.fill(
            (100, 100, 100),
            (SCREEN_SIZE.W - self.width, 0, self.width, SCREEN_SIZE.H))

        self.btn_back.render((SCREEN_SIZE.W - self.width, 0))
        self.btn_menu.render((SCREEN_SIZE.W - self.width, 50))
        self.btn_quit.render((SCREEN_SIZE.W - self.width, 100))

        if self.width < self.max_witdh:
            self.width += 50
示例#11
0
    def render(self, pos):
        (self.x, self.y) = pos

        if self.is_focused:
            icon = self.fg
        else:
            icon = self.bg

        if isinstance(icon, pygame.Surface):
            surface = pygame.transform.scale(icon, (int(self.w), int(self.h)))
            surface_rect = surface.get_rect()
            surface_rect.topleft = (self.x, self.y)
            surface_rect.bottomright = (self.x + self.w, self.y + self.h)

            SCREEN.blit(surface, surface_rect)

        elif isinstance(icon, tuple):
            surface_rect = pygame.draw.rect(SCREEN, icon, (self.x, self.y, self.w, self.h))

        if self.text:
            self.text.render(surface_rect)
示例#12
0
    def render(self, pos):
        (self.x, self.y) = pos

        if self.is_focused:
            icon = self.fg
        else:
            icon = self.bg

        if isinstance(icon, pygame.Surface):
            surface = pygame.transform.scale(icon, (int(self.w), int(self.h)))
            surface_rect = surface.get_rect()
            surface_rect.topleft = (self.x, self.y)
            surface_rect.bottomright = (self.x + self.w, self.y + self.h)

            SCREEN.blit(surface, surface_rect)

        elif isinstance(icon, tuple):
            surface_rect = pygame.draw.rect(SCREEN, icon,
                                            (self.x, self.y, self.w, self.h))

        if self.text:
            self.text.render(surface_rect)
示例#13
0
    def render(self):
        SCREEN.blit(self.bg, (0, 0))

        self.game.render((
            (22 / 1024.0) * SCREEN_SIZE.W,
            (94 / 768.0) * SCREEN_SIZE.H))
        self.btn_1.render((
            (345 / 1024.0) * SCREEN_SIZE.W,
            (94 / 768.0) * SCREEN_SIZE.H))
        self.btn_2.render((
            (345 / 1024.0) * SCREEN_SIZE.W,
            (257 / 768.0) * SCREEN_SIZE.H))
        self.btn_3.render((
            (345 / 1024.0) * SCREEN_SIZE.W,
            (420 / 768.0) * SCREEN_SIZE.H))
        self.btn_4.render((
            (184 / 1024.0) * SCREEN_SIZE.W,
            (420 / 768.0) * SCREEN_SIZE.H))
        self.btn_5.render((
            (22 / 1024.0) * SCREEN_SIZE.W,
            (420 / 768.0) * SCREEN_SIZE.H))
        self.profile.render((
            (22 / 1024.0) * SCREEN_SIZE.W,
            (582 / 768.0) * SCREEN_SIZE.H))
示例#14
0
 def render(self):
     SCREEN.blit(pygame.transform.scale(self.bg, SCREEN_SIZE), (0, 0))
     pygame.display.update()
示例#15
0
        if start_game:
            done = True
        snowman.wrong_letter = out_letter
        snowman.draw_snowman(SCREEN)

        pg.display.flip()


if __name__ == '__main__':
    end_game = False
    player1_button = Button(200, 440, 140, 50, '1 Player', '1')
    player2_button = Button(400, 440, 150, 50, '2 Players', '2')
    while not end_game:
        for event in pg.event.get():
            if event.type == pg.QUIT:
                end_game = True
                pg.quit()
                quit()
            player1 = player1_button.handle_event(event)
            player2 = player2_button.handle_event(event)

        SCREEN.fill(PURPLE)
        player1_button.draw(SCREEN)
        player2_button.draw(SCREEN)

        if player1 == 1:
            game(False)
        if player2 == 2:
            game(True)
        pg.display.flip()
示例#16
0
 def render(self):
     SCREEN.blit(pygame.transform.scale(self.bg, SCREEN_SIZE), (0, 0))
     pygame.display.update()