создал функцию для вывода текста но текст появляется на миллисекунду и сразу исчезает
если поставить time.sleep(2) , то текст не появляется
import random
import time
import pygame
pygame.init()
pygame.font.init()
points1 = 0
points2 = 0
def print_text(message, x, y, font_color=(0, 0, 0), font_type='comic.ttf', font_size=30):
font_type = pygame.font.Font(font_type,font_size)
text = font_type.render(message, True, font_color)
display.blit(text, (x, y))
DISPLAY_WIDTH = 800
DISPLAY_HEIGHT = 590
FPS = 30
PLAYER_1_WIDTH = 20
PLAYER_1_HEIGHT = 100
PLAYER_1_X = 50
PLAYER_1_Y = 300
PLAYER_2_HEIGHT = 100
PLAYER_2_WIDTH = 20
PLAYER_2_X = 730
PLAYER_2_Y = 300
BALL_RADIUS = 12
BALL_X = 400
BALL_Y = 300
BALL_SPEED_X = 6
BALL_SPEED_Y = random.randint(-BALL_SPEED_X, BALL_SPEED_X)
display = pygame.display.set_mode((DISPLAY_WIDTH, DISPLAY_HEIGHT))
pygame.display.set_caption("dino")
clock = pygame.time.Clock()
icon = pygame.image.load('icon.png')
pygame.display.set_icon(icon)
background = pygame.image.load('background.png')
player_img = pygame.image.load('player.png')
def run_game():
game = True
global PLAYER_1_Y, PLAYER_1_X, PLAYER_2_X, PLAYER_2_Y, BALL_X, BALL_Y, BALL_SPEED_X, BALL_SPEED_Y, points2, points1
while game:
# Контроль фпс
clock.tick(FPS)
# Обработка событий
for event in pygame.event.get():
#
if event.type == pygame.QUIT:
pygame.quit()
quit()
# Обновление
keys = pygame.key.get_pressed()
if BALL_Y <= 10:
BALL_SPEED_Y = -BALL_SPEED_Y
elif BALL_Y >= 580:
BALL_SPEED_Y = -BALL_SPEED_Y
if keys[pygame.K_UP]:
PLAYER_2_Y -= 12
if PLAYER_2_Y <= 0:
PLAYER_2_Y = 0
elif keys[pygame.K_DOWN]:
PLAYER_2_Y += 12
if PLAYER_2_Y >= 510:
PLAYER_2_Y = 510
if keys[pygame.K_w]:
PLAYER_1_Y -= 12
if PLAYER_1_Y <= 0:
PLAYER_1_Y = 0
elif keys[pygame.K_s]:
PLAYER_1_Y += 12
if PLAYER_1_Y >= 510:
PLAYER_1_Y = 510
BALL_X += BALL_SPEED_X
BALL_Y += BALL_SPEED_Y
# Рендеринг
display.blit(background, (0, 0))
player_1 = display.blit(player_img, (PLAYER_1_X, PLAYER_1_Y))
player_2 = display.blit(player_img, (PLAYER_2_X, PLAYER_2_Y))
ball = pygame.draw.circle(display, (103, 194, 95), (BALL_X, BALL_Y), BALL_RADIUS)
players = [player_1, player_2]
if ball.colliderect(players[1]):
BALL_SPEED_X = -(BALL_SPEED_X + 1)
elif ball.colliderect(players[0]):
BALL_SPEED_X = -(BALL_SPEED_X - 1)
if BALL_X <= 0:
points2 += 1
print_text("У вас" + str(points2), 500, 50, (255, 255, 255))
BALL_SPEED_X = 6
BALL_X = 400
BALL_Y = 300
BALL_X += BALL_SPEED_X
BALL_SPEED_Y = random.randint(-12, 12)
if BALL_X >= 800:
points1 += 1
print_text("У вас" + str(points1), 300, 50, (255, 255, 255))
BALL_SPEED_X = 6
BALL_X = 400
BALL_Y = 300
BALL_X += BALL_SPEED_X
BALL_SPEED_Y = random.randint(-12, 12)
# Показ экрана пользователю
pygame.display.flip()
run_game()