コード例 #1
0
    def set_title(self, screen: pygame.surface, text: str):
        text_surf = self.font_title.render(text, True,
                                           const.COLOR_DASHBOARD_TEXT)

        text_rect = text_surf.get_rect()
        text_rect.top = const.DASHBOARD_BORDER_WIDTH + 20
        text_rect.left = (const.ARENA_WIDTH + const.DASHBOARD_BORDER_WIDTH +
                          (self.rect.width / 2 - text_rect.width / 2))
        screen.blit(text_surf, text_rect)
コード例 #2
0
ファイル: pgUtils.py プロジェクト: wilgnne/2D-Raycasting
def translate(surface: pg.surface, pos: tuple):
    temp_surf = surface.copy()
    surface.fill((0, 0, 0))

    rect = temp_surf.get_rect()

    surface.blit(temp_surf, pos)

    return pos
コード例 #3
0
    def draw(self, screen: pygame.surface):
        '''
        This blits the text to the provided surface.

        Parameters
        ----------
        screen : pygame.surface
            The surface to be blitted to.

        Returns
        -------
        None.

        '''
        screen.blit(self._text, self._textRect)
コード例 #4
0
ファイル: StartGame.py プロジェクト: muziing/retro-snake
def start_game(start_flag: bool, window: pygame.surface):
    quit_flag = False

    while start_flag and not quit_flag:
        events = pygame.event.get()
        for event in events:
            if event.type == pygame.QUIT:
                quit_flag = True
        keys = pygame.key.get_pressed()
        if keys[pygame.K_SPACE]:
            break
        window.blit(StartingBackground, (0, 0))
        pygame.display.update()
    if quit_flag:
        pygame.display.quit()
コード例 #5
0
    def draw(self, screen: pygame.surface):
        '''
        This draws the button to the provided surface.

        Parameters
        ----------
        screen : pygame.surface
            The surface the button will be drawn to.

        Returns
        -------
        None.

        '''
        pygame.draw.rect(screen, self._buttonColor, self._buttonRect)
        screen.blit(self._text, self._nameRect)
コード例 #6
0
ファイル: button.py プロジェクト: sophiaabolore/Map-Slider-
    def draw(self, win: surface, outline: Tuple[int, int, int]) -> None:
        """draws the button on the surface that is passed in

        Preconditions:
            - 0 <= outline[0] <= 255
            - 0 <= outline[1] <= 255
            - 0 <= outline[2] <= 255
        """
        pygame.draw.rect(
            win, outline,
            (self.x - 2, self.y - 2, self.width + 4, self.height + 4), 0)

        pygame.draw.rect(win, self.colour,
                         (self.x, self.y, self.width, self.height), 0)

        font = pygame.font.SysFont('timesnewromanms', 60)
        text = font.render(self.text, True, (0, 0, 0))
        win.blit(text,
                 (self.x + (self.width / 2 - text.get_width() / 2), self.y +
                  (self.height / 2 - text.get_height() / 2)))
コード例 #7
0
    def set_info(self, screen: pygame.surface, dic_info: dict):
        width_offset = 20
        height_offset = 60
        index_offset = 20

        max_key_len = max(map(len, dic_info))
        max_value_len = max(dic_info.values(), key=lambda x: len(str(x)))
        for index, (key, value) in enumerate(dic_info.items()):
            text = str(key).ljust(max_key_len +
                                  1) + ': ' + str(value).rjust(max_value_len +
                                                               1)

            text_surf = self.font_info.render(text, True,
                                              const.COLOR_DASHBOARD_TEXT)
            text_rect = text_surf.get_rect()
            text_rect.top = const.DASHBOARD_BORDER_WIDTH + height_offset + index * index_offset
            text_rect.left = (const.ARENA_WIDTH +
                              const.DASHBOARD_BORDER_WIDTH + width_offset)
            if text_rect.right > self.border_rect.right:
                raise Exception(
                    '\n  Real ugly. Smaller font, or shorter name, or something.'
                    + '\n  Will somebody please think of the children?!?' +
                    '\n  ' + text)
            screen.blit(text_surf, text_rect)
コード例 #8
0
ファイル: track.py プロジェクト: nikhil-garg/l2race
 def draw(self, surface: pygame.surface):
     """
     Draw a track png
     :param surface: Pygame surface to which track png should be drawn
     """
     surface.fill((65, 105, 225))
     # surface.blit(self.track, (SCREEN_WIDTH//2 - car.car_state.position.x, SCREEN_HEIGHT//2 - car.car_state.position.y))
     surface.blit(self.track_image, (0, 0))
     if self.surface_waypoints is not None:
         surface.blit(self.surface_waypoints, (0, 0))
コード例 #9
0
ファイル: main.py プロジェクト: Iconejey/shootemup
def drawText(surface: pg.surface,
             text: str,
             x: int,
             y: int,
             fontsize: int = 24,
             color: list = [255] * 4,
             bold: bool = False,
             side: str = 'left') -> None:
    f = pg.font.Font('../Consolas.ttf', fontsize)
    f.set_bold(bold)
    t = f.render(text, False, color)
    w = t.get_size()[0]

    if side == 'left':
        surface.blit(t, [x, y])

    if side == 'center':
        surface.blit(t, [x - w // 2, y])

    if side == 'right':
        surface.blit(t, [x - w, y])
コード例 #10
0
ファイル: track.py プロジェクト: neuromorphs/l2race
 def draw(self, surface: pygame.surface):
     """
     Draw a track png
     :param surface: Pygame surface to which track png should be drawn
     """
     surface.fill((65, 105, 225))
     # surface.blit(self.track, (SCREEN_WIDTH//2 - car.car_state.position.x, SCREEN_HEIGHT//2 - car.car_state.position.y))
     surface.blit(self.track_image, (0, 0))
     if self.surface_waypoints is not None:
         surface.blit(self.surface_waypoints, (0, 0))
     if self.game_font is None:
         try:
             self.game_font = pygame.freetype.SysFont(
                 GAME_FONT_NAME, GAME_FONT_SIZE)
         except:
             logger.warning(
                 'cannot get specified globals.py font {}, using pygame default font'
                 .format(GAME_FONT_NAME))
             self.game_font = pygame.freetype.SysFont(
                 pygame.font.get_default_font(), GAME_FONT_SIZE)
     self.game_font.render_to(surface, (0, 0 + GAME_FONT_SIZE), self.name,
                              (255, 255, 255)),
コード例 #11
0
def draw_stats(surface: pygame.surface, position: (int, int), fps: int, score: int, average_score: float, font: pygame.font.Font):
    text_fps_name = font.render('FPS:', True, COLOR_KEY_NAME)
    text_fps_value = font.render(str(fps), True, COLOR_VALUE)

    text_score_name = font.render('SCORE:', True, COLOR_KEY_NAME)
    text_score_value = font.render(str(score), True, COLOR_VALUE)

    text_avg_score_name = font.render('AVG SCORE:', True, COLOR_KEY_NAME)
    text_avg_score_value = font.render(str(average_score)[:7], True, COLOR_VALUE)

    surface.blit(
        text_fps_name, position
    )
    position = (
        position[0] + text_fps_name.get_rect().width + 10,
        position[1],
    )

    surface.blit(
        text_fps_value, position
    )
    position = (
        position[0] + text_fps_value.get_rect().width + 30,
        position[1],
    )

    surface.blit(
        text_score_name, position
    )
    position = (
        position[0] + text_score_name.get_rect().width + 10,
        position[1],
    )

    surface.blit(
        text_score_value, position
    )
    position = (
        position[0] + text_score_value.get_rect().width + 30,
        position[1],
    )

    surface.blit(
        text_avg_score_name, position
    )
    position = (
        position[0] + text_avg_score_name.get_rect().width + 10,
        position[1],
    )

    surface.blit(
        text_avg_score_value, position
    )
    position = (
        position[0] + text_avg_score_value.get_rect().width + 30,
        position[1],
    )
コード例 #12
0
 def draw(self, screen: pygame.surface):
     """Draw on the screen."""
     screen.blit(self.surface, self.rect_s)
     screen.blit(self.layer, self.rect_l)