예제 #1
0
 def display(self, screen: pygame.display):
     # Set the rect for the text to the center of the button
     text_rect = self.text.get_rect(center=self.rect.center)
     # Draw the button
     pygame.draw.rect(screen, self.color, self.rect)
     # Draw the text
     screen.blit(self.text, text_rect)
예제 #2
0
    def display(self, screen: pygame.display) -> None:
        """Display the current TicTacToe Board on screen"""
        w, h = screen.get_size()
        screen.fill((255, 255, 255))

        # Draw the lines on the board
        pygame.draw.line(screen, (0, 0, 0), (0, h // 3), (w, h // 3))
        pygame.draw.line(screen, (0, 0, 0), (0, 2 * h // 3), (w, 2 * h // 3))
        pygame.draw.line(screen, (0, 0, 0), (w // 3, 0), (w // 3, h))
        pygame.draw.line(screen, (0, 0, 0), (2 * w // 3, 0), (2 * w // 3, h))

        # Draw the markers
        font = pygame.font.SysFont('Calibri', 100)
        for x in range(3):
            for y in range(3):
                piece = font.render(
                    self.board_object(x, y),
                    True,
                    (0, 0, 0)
                )
                screen.blit(
                    piece,
                    (
                        (y + 0.3) * (w // 3),
                        (x + 0.3) * (h // 3)
                    )
                )
        pygame.display.update()
예제 #3
0
    def render(self, display: pygame.display, target: list[tuple[int, int,
                                                                 int]],
               launcher: tuple[int, int,
                               int], ps_t: int, first_time: bool) -> NoReturn:
        if first_time:
            sound_manager.start_in_first_empty_taunt(self.sound)
            self.g_i = gif_manger.CONTACT.get().display(
                (target[0][0] - 60, target[0][1] - 60), 25)

        x1, y1 = launcher[0] + 40, launcher[1] - 50
        x2, y2 = target[0][0], target[0][1] - 30
        a = (y2 - y1) / (x2 - x1)
        b = y1 - a * x1
        max_delta_x = x2 - x1
        if 100 < ps_t < 1000 or 2600 < ps_t < 3500:
            x = min(
                ((ps_t -
                  (100 if ps_t < 1000 else 2600)) / 900), 1) * max_delta_x + x1
            y = (a * x + b) + (0.002 * (x - x1) * (x - x2))
            display.blit(
                pygame.transform.rotate(self.bone, (ps_t % 300) / 300 * 360),
                (x - 32, y - 32))
        elif 1000 <= ps_t <= 1700 or 3500 <= ps_t <= 4200:
            x = x2 - min(
                ((ps_t -
                  (1000 if ps_t <= 1700 else 3500)) / 700), 1) * max_delta_x
            y = (a * x + b) + (-0.002 * (x - x1) * (x - x2))
            display.blit(
                pygame.transform.rotate(self.bone, (ps_t % 300) / 300 * 360),
                (x - 32, y - 32))
예제 #4
0
    def update(self, screen: pygame.display):

        # This will be deprecated pending new methods for movement
        # self.rect.x += self.x_movement
        # self.rect.y += self.y_movement

        screen.blit(self.image, self.rect)
예제 #5
0
    def render(self, display: pygame.display, target: list[type[int, int, int]],
               launcher: tuple[int, int, int], ps_t: int, first_time: bool) -> NoReturn:
        if first_time:
            sound_manager.start_in_first_empty_taunt(self.sound)
            self.random_vec = [
                (random.uniform(-2, 2), random.uniform(-2, 2), random.randint(0, 1000), random.randint(400, 1000)) for _
                in range(20)]

        for t in target:
            if ps_t < 1000:
                x1, y1 = launcher[0] + 40, launcher[1] - 50
                x2, y2 = t[0], t[1] - 30
                a = (y2 - y1) / (x2 - x1)
                b = y1 - a * x1
                max_delta_x = x2 - x1
                x = min((ps_t / 1000), 1) * max_delta_x + x1
                y = (a * x + b) + (0.002 * (x - x1) * (x - x2))
                display.blit(pygame.transform.scale(self.bubble, (64, 64)), (x - 32, y - 32))
            else:
                ps_t -= 1000
                x_start, y_start = t[0], t[1] - 40
                for bu in self.random_vec:
                    vec = [bu[0], bu[1]]
                    if 0 < (n_pst_t := ps_t - bu[2]) < bu[3]:
                        adv = (n_pst_t / bu[3])
                        vec[0] *= adv * 150
                        vec[1] *= adv * 150
                        display.blit(self.bubble, (x_start - 16 + vec[0], y_start - 16 + vec[1]))
예제 #6
0
    def render(self, display: pygame.display, target: list[tuple[int, int,
                                                                 int]],
               launcher: tuple[int, int,
                               int], ps_t: int, first_time: bool) -> NoReturn:
        if first_time:
            self.current_vars = [[False] * self.last_nb_hit,
                                 [(random.randint(-50,
                                                  50), random.randint(-50, 50))
                                  for _ in range(15)]]

        c_hit = min(self.last_nb_hit - 1, ps_t // 1000)
        if not self.current_vars[0][c_hit]:
            self.current_vars[0][c_hit] = True
            sound_manager.start_in_first_empty_taunt(self.sound)

        for t_i in range(len(target)):

            x, y = target[t_i][0], target[t_i][1] - 55

            for i in range(15):
                i_60 = int((i / 15) * ((1000 * (c_hit + 1)) - SPEED))
                if i_60 < ps_t < i_60 + SPEED:
                    rdm = self.current_vars[1][i]
                    display.blit(
                        self.img_y if (ps_t - i_60) // 50 else self.img_g,
                        (x + rdm[0] - 14, y + rdm[1] - 14))
예제 #7
0
파일: cut.py 프로젝트: Kyrokx/PygaMone
    def render(self, display: pygame.display, target: list[type[int, int,
                                                                int]],
               launcher: tuple[int, int,
                               int], ps_t: int, first_time: bool) -> NoReturn:
        if first_time:
            sound_manager.start_in_first_empty_taunt(self.sound)
            self.random_vec = [(random.uniform(-1, 1), random.uniform(-1, 1),
                                random.randint(0,
                                               100), random.randint(300, 400))
                               for _ in range(10)]

        for t in target:
            if 150 < ps_t < 600:
                x_start, y_start = t[0] + 90, t[1] - 150
                edit = (ps_t - 150) / 600 * 80
                display.blit(
                    self.cut,
                    (x_start - self.cut.get_size()[0] - edit, y_start + edit))
            if ps_t > 250:
                ps_t -= 250
                x_start, y_start = t[0], t[1] - 40
                for bu in self.random_vec:
                    vec = [bu[0], bu[1]]
                    if 0 < (n_pst_t := ps_t - bu[2]) < bu[3]:
                        adv = (n_pst_t / bu[3])
                        vec[0] *= adv * 150
                        vec[1] *= adv * 150
                        display.blit(
                            self.ball,
                            (x_start - 16 + vec[0], y_start - 16 + vec[1]))
예제 #8
0
 def update(self, screen: pygame.display) -> bool:
     screen.blit(self.background_image, (0, 0))
     self.exit_button.draw(screen)
     self.start_button.draw(screen)
     self.exit_button.check_state()
     if self.start_button.check_state():
         return True
     return False
예제 #9
0
파일: main.py 프로젝트: jzlotek/tetris-rnn
def show_message(screen: pygame.display, msg: str) -> None:
    screen.fill(colors.BLACK)
    font = pygame.font.FontType('freesansbold.ttf', 20)
    surface = font.render(msg, True, colors.WHITE)
    rectangle = surface.get_rect()
    rectangle.center = (width // 2, height // 2)
    screen.blit(surface, rectangle)
    pygame.display.update()
예제 #10
0
    def end_game(self, screen: pygame.display, grid: Grid) -> None:
        """ Run when the game is over
            Display the score
        """
        print("game is over")
        print("final score = ", grid.get_score())

        # open menu
        surface = pygame.Surface((self._width, self._height))
        surface.set_alpha(128)
        surface.fill((0, 0, 0))

        screen.blit(surface, (0, 0))

        # draw the text
        font = pygame.font.SysFont(self._font, 32)

        pause_text = font.render("Game Over", True, (255, 255, 255))
        text_rect = pause_text.get_rect()
        text_rect.center = (self._width // 2, self._height // 20)
        screen.blit(pause_text, text_rect)

        score_text = font.render(
            "Final Score: " + str(self._player.get_score()), 32,
            (255, 255, 255))
        text_rect = score_text.get_rect()
        text_rect.center = (self._width // 2, self._height // 7.5)
        screen.blit(score_text, text_rect)

        continue_text = font.render("Press any key", 24, (255, 255, 255))
        text_rect = continue_text.get_rect()
        text_rect.center = (self._width // 2, self._height // 4)
        screen.blit(continue_text, text_rect)

        continue_text = font.render("to restart", 24, (255, 255, 255))
        text_rect = continue_text.get_rect()
        text_rect.center = (self._width // 2, self._height // 3.25)
        screen.blit(continue_text, text_rect)

        pygame.display.update()

        restart = False

        # wait for player to hit a key to restart
        while not restart:
            for event in pygame.event.get():
                # player wants to quit
                if event.type == pygame.QUIT:
                    self._quit = True
                    self.quit_game()
                    return False
                # player wants to restart
                if event.type == pygame.KEYDOWN:
                    restart = True

        if self._player:
            self._player.lose()
예제 #11
0
 def draw(self, screen: pygame.display, position: List[int]) -> None:
     """
     Draws the tile on the specified screen and position
     :param screen: The screen the tile should be drawn on to
     :param position:
     """
     self._position = position.copy()
     self._rect = self._image.get_rect().move(position[0], position[1])
     screen.blit(self._image, position)
예제 #12
0
def display_won(screen: pygame.display) -> None:
    text_rect_shadow = copy(win_rect)
    text_rect_shadow.w += 20
    text_rect_shadow.h += 20
    text_rect_shadow.x -= 10
    text_rect_shadow.y -= 10
    gfxdraw.box(screen, text_rect_shadow, (0, 0, 0, 120))
    screen.blit(win_text, win_rect)
    draw_play_again_button(screen)
예제 #13
0
def showDistanceBetweenVertices(vertices: List[Vertex],
                                screen: pygame.display):
    posY = 0
    for vertex in vertices:
        name = vertex.name
        text = f"{name:^3} dist:{vertex._lastIntersectionMemory}"
        keyImage = font.render(text, True, Colors.MainColors.onSurfaceColor)
        screen.blit(keyImage, [0, posY])
        posY += font.size(name)[1]
예제 #14
0
def draw_await_players(layer: pygame.display) -> None:
    """Отрисовка слоя для ожидания игрока.

    :return: None.
    """
    layer.blit(pygame.image.load("Picture/BackGround.jpg").convert(), (0, 0))
    font = pygame.font.SysFont("comicsans", 80)
    text = font.render("Подождите напарника для игры", 1, (255, 0, 0), True)
    layer.blit(text, (size_main_window[0] / 2 - text.get_width() / 2,
                      size_main_window[1] / 2 - text.get_height() / 2))
예제 #15
0
def text_to_screen(screen: pygame.display,
                   font,
                   text: str,
                   position: tuple,
                   color=(0, 0, 0)) -> None:
    """Renders text to a screen objects in a specified color and position.
	Default font color is black and default size is 100px"""

    text = font.render(text, True, color)
    screen.blit(text, (position[0], position[1]))
예제 #16
0
    def display(self, screen: pygame.display):
        screen.blit(self.image, self.pos)
        s = pygame.Surface((self.rect.width, self.rect.height))
        if self.is_highlighted:
            s.set_alpha(100)
        else:
            s.set_alpha(0)

        s.fill(self.highlight_color)
        screen.blit(s, self.rect.topleft)
예제 #17
0
파일: clamp.py 프로젝트: Kyrokx/PygaMone
    def render(self, display: pygame.display, target: list[type[int, int, int]],
               launcher: tuple[int, int, int], ps_t: int, first_time: bool) -> NoReturn:
        if first_time:
            sound_manager.start_in_first_empty_taunt(self.sound)

        move = (ps_t / 600) * 120

        for t in target:
            display.blit(self.img_l, (t[0] - 100 + move, t[1] - 40))
            display.blit(self.img_r, (t[0] + 100 - move, t[1] - 40))
예제 #18
0
 def draw(self, display: pygame.display) -> None:
     """
     A function used to draw a button
     """
     if self.active:
         color = (self._color[0], self._color[1], self._color[2] + 255)
     else:
         color = self._color
     pygame.draw.rect(display, color, self._rect)
     display.blit(self._text_surface, self._text_pos)
예제 #19
0
    def draw(self, display: pygame.display, adjust: (int, int)):
        x, y = adjust

        if self.__transform is None:
            image = self.__image
        else:
            angle, scale = self.__transform
            image = pygame.transform.rotozoom(self.__image, angle, scale)

        display.blit(image, [self.x - x, self.y - y], self.__area_rect)
예제 #20
0
    def show(self, w: pygame.display):
        """Pokazi se na w"""

        # Obrni svojo sliko
        rotated_image = rotate(self.image, self.rotation)

        # Nastavi svojo velikost na velikost nove slike, da bo zaznavanje dotikov bolj natancno
        self.sx, self.sy = rotated_image.get_size()

        w.blit(rotated_image, (self.x, self.y))
예제 #21
0
파일: ej.py 프로젝트: 666graham666/-
def Eyes(screen: pygame.display, x, y, zoom, color_body, color_eye_1,
         color_eye_2):
    ellipse(screen, color_eye_2,
            (x + 52 * zoom, y - 138 * zoom, 24 * zoom, 20 * zoom))
    ellipse(screen, color_eye_1,
            (x + 65 * zoom, y - 133 * zoom, 10 * zoom, 8 * zoom))
    glasik = pygame.Surface((12 * zoom, 6 * zoom), pygame.SRCALPHA)
    ellipse(glasik, color_body, (0, 0, 11 * zoom, 11 * zoom))
    glasik_rot = pygame.transform.rotate(glasik, -30)
    screen.blit(glasik_rot, (x + 58 * zoom, y - 138 * zoom))
예제 #22
0
def flower(screen: pygame.display, cord_x: int, cord_y: int, size: float,
           angle: float, colour_flower_1: tuple, colour_flower_2: tuple,
           colour_flower_3: tuple):
    surface = pygame.Surface((round(size * 49), round(size * 26)),
                             pygame.SRCALPHA)

    ellipse(surface, colour_flower_1,
            (round(size * 18 - size * 8), round(size * 6 - size * 5),
             round(size * 2 * 8), round(size * 2 * 5)))
    ellipse(surface, colour_flower_3,
            (round(size * 18 - size * 8), round(size * 6 - size * 5),
             round(size * 2 * 8), round(size * 2 * 5)), round(size))

    ellipse(surface, colour_flower_1,
            (round(size * 30 - size * 8), round(size * 5 - size * 5),
             round(size * 2 * 8), round(size * 2 * 5)))
    ellipse(surface, colour_flower_3,
            (round(size * 30 - size * 8), round(size * 5 - size * 5),
             round(size * 2 * 8), round(size * 2 * 5)), round(size))

    ellipse(surface, colour_flower_2,
            (round(size * 25 - size * 11), round(size * 10 - size * 4),
             round(size * 2 * 11), round(size * 2 * 4)))

    ellipse(surface, colour_flower_1,
            (round(size * 35 - size * 8), round(size * 10 - size * 5),
             round(size * 2 * 8), round(size * 2 * 5)))
    ellipse(surface, colour_flower_3,
            (round(size * 35 - size * 8), round(size * 10 - size * 5),
             round(size * 2 * 8), round(size * 2 * 5)), round(size))

    ellipse(surface, colour_flower_1,
            (round(size * 13 - size * 8), round(size * 12 - size * 5),
             round(size * 2 * 8), round(size * 2 * 5)))
    ellipse(surface, colour_flower_3,
            (round(size * 13 - size * 8), round(size * 12 - size * 5),
             round(size * 2 * 8), round(size * 2 * 5)), round(size))

    ellipse(surface, colour_flower_1,
            (round(size * 22 - size * 8), round(size * 16 - size * 5),
             round(size * 2 * 8), round(size * 2 * 5)))
    ellipse(surface, colour_flower_3,
            (round(size * 22 - size * 8), round(size * 16 - size * 5),
             round(size * 2 * 8), round(size * 2 * 5)), round(size))

    ellipse(surface, colour_flower_1,
            (round(size * 30 - size * 8), round(size * 15 - size * 5),
             round(size * 2 * 8), round(size * 2 * 5)))
    ellipse(surface, colour_flower_3,
            (round(size * 30 - size * 8), round(size * 15 - size * 5),
             round(size * 2 * 8), round(size * 2 * 5)), round(size))

    surface_rot = pygame.transform.rotate(surface, angle)
    screen.blit(surface_rot,
                (cord_x - round(size * 27), cord_y - round(size * 13)))
예제 #23
0
    def draw(self, display: pygame.display, adjust: (int, int)):
        x = self.x - adjust[0]
        y = self.y - adjust[1]
        font = pygame.font.Font(self.__font_type, self.__font_size)
        text = self.__text

        render = font.render(text, True, (0, 0, 0))
        display.blit(render, [x + 1, y + 1])

        render = font.render(text, True, self.__color)
        display.blit(render, [x, y])
예제 #24
0
파일: pieces.py 프로젝트: Zorz42/PyChess
 def render(self, screen: pygame.display) -> None:
     screen.blit(self.texture, (
         (self.x * cell_size) + window_padding,
         (self.y * cell_size) + window_padding
     ), (
                     self.texture_y * cell_size,
                     self.black * cell_size,
                     cell_size,
                     cell_size
                 )
                 )
예제 #25
0
 def update(self, screen: pygame.display, image: str) -> None:
     """
     Redraws the tile on the given screen with an updated image. Uses
     the stored position as the position on the screen.
     :param screen: The screen the tile should be drawn on to
     :param image: the name of new image to be displayed on the tile
     """
     self._image = pygame.image.load(
         os.path.join(os.path.dirname(__file__), "assets/" + image + ".png"))
     self._image = pygame.transform.scale(self._image, self._size)
     screen.blit(self._image, self._position)
예제 #26
0
def eye(screen: pygame.display, cord_x: int, cord_y: int, size: float,
        colour_body: tuple, colour_eye_1: tuple, colour_eye_2: tuple):
    ellipse(screen, colour_eye_2,
            ((cord_x + round(size * 64)) - round(size * 12), (cord_y - round(size * 128) - round(size * 10)),
             round(size * 2 * 12), round(size * 2 * 10)))
    ellipse(screen, colour_eye_1,
            ((cord_x + round(size * 70) - round(size * 5), (cord_y - round(size * 129)) - round(size * 4),
              round(size * 2 * 5), round(size * 2 * 4))))
    surface = pygame.Surface((round(size * 12), round(size * 6)), pygame.SRCALPHA)
    ellipse(surface, colour_body, (0, 0, round(size * 11), round(size * 5)))
    surface_rot = pygame.transform.rotate(surface, -30)
    screen.blit(surface_rot, (cord_x + round(size * 58), cord_y - round(size * 138)))
예제 #27
0
def display_item_count(window: pygame.display, level: Level):
    """Make of visual of how many items as been picked up

    :param window: Window where item count display
    :param level: Level where MacGyver is collecting item
    """
    green = (0, 255, 0)
    font = pygame.font.Font('freesansbold.ttf', SPRITE_SIZE // 2)
    if level.macgyver.item_count < 3:
        text = font.render(f'Item: {level.macgyver.item_count}/3', True, green)
    else:
        text = font.render('Syringe ready!', True, green)
    window.blit(text, (0, WINDOW_SIZE - SPRITE_SIZE // 2))
예제 #28
0
    def draw(surface: pygame.display, is_valid_move: bool, is_game_over: bool, player: Player):
        font = pygame.font.SysFont('Arial', 30)
        if is_game_over:
            text = f'{player.name.capitalize()} won!!!'
        elif is_valid_move:
            text = player.name
        else:
            text = 'Invalid move!'

        surface.blit(font.render(text, True, (200, 200, 200)), (50, 30))
        x, y = pygame.mouse.get_pos()
        weapon = pygame.transform.scale(player.weapon.picture, (30, 30))
        surface.blit(weapon, (x + 10, y + 10))
예제 #29
0
    def render(self, display: pygame.display, target: list[tuple[int, int, int]],
               launcher: tuple[int, int, int], ps_t: int, first_time: bool) -> NoReturn:
        if first_time:
            self.current_vars = [(random.randint(-100, 0), random.randint(0, 30)) for _ in range(15)]
            sound_manager.start_in_first_empty_taunt(self.sound)

        if ps_t > 1000:
            for i in range(15):
                i_15 = int((i / 15) * (1000 - SPEED_2))
                if i_15 + 1000 < ps_t < i_15 + SPEED_2 + 1000:
                    x = launcher[0] + 40 + self.current_vars[i][0]
                    y = launcher[1] - 50 + self.current_vars[i][1] - ((ps_t - 1000 - i_15) / SPEED_2) * 80
                    display.blit(self.ball, (x, y))
예제 #30
0
 def draw(self, screen: pygame.display) -> None:
     for sensor in self.sensors:
         gfxdraw.line(screen, int(np.round(sensor.coords.xy[0][0])),
                      int(np.round(sensor.coords.xy[1][0])),
                      int(np.round(sensor.coords.xy[0][1])),
                      int(np.round(sensor.coords.xy[1][1])),
                      Const.COLORS.red)
         screen.blit(
             Const.FONT_SENSORS.render(
                 f'{np.round(sensor.length if sensor.length > 0 else 0.0, decimals=1)}',
                 True, Const.COLORS.white),
             (int(np.round(sensor.coords.xy[0][1])),
              int(np.round(sensor.coords.xy[1][1]))))
예제 #31
0
    def show(self, window:pygame.display):
        windowResolution = (window.get_width(),window.get_height())

        windowHeightOn10 = int(windowResolution[1]/10)
        windowHeightOn5 = int(windowResolution[1]/5)

        topResolution = (windowResolution[0],windowHeightOn10)
        bottomResolution = (windowResolution[0],windowHeightOn5)

        #scaling images if they are different from the current resolution
        if (self._topInterface.get_width(), self._topInterface.get_height()) != topResolution :
            topInterface = pygame.transform.scale(self._topInterface,topResolution)
        else:
            topInterface = self._topInterface

        if (self._bottomInterface.get_width(),self._bottomInterface.get_height()) != bottomResolution:
            bottomInterface = pygame.transform.scale(self._bottomInterface,bottomResolution)
        else:
            bottomInterface = self._bottomInterface

        window.blit(topInterface,ANCHOR_AT_00)
        window.blit(bottomInterface,(0,windowResolution[1]-windowHeightOn5))