Итак, у меня возникает эта ошибка pygame.error: font not initialized, и я устал исправлять, делая отступы, не идентифицировал его, менял шрифт и другие вещи, но он все еще не работает. Это в моем STARTMENUE. Я также пробовал использовать другой шрифт, думая, что это была проблема, но это не так.
была у меня проблема
largeText = pygame.font.Font('freesansblod.ttf',115)
Мой полный код
import pygame
#set screen
window = pygame.display.set_mode((500,500))
#set Name
pygame.display.set_caption("Noob")
class Player:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.color = color
self.speed = 0
self.isJump = False
self.JumpCount = 10
self.fall = 0
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.topleft = (self.x,self.y)
class Floor:
def __init__ (self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.topleft = (self.x,self.y)
pygame.draw.rect(window,self.color,self.rect)
class Coin():
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.width = width
self.height = height
self.color = color
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.topleft = (self.x,self.y)
self.draw.rect(self.color,self.rect)
white = (255,255,255)
green = (0,200,0)
red = (255,0,0)
drakred = (200,0,0)
darkgreen = (0,200,0)
black = (0,0,0)
player1 = Player(50,400,40,40,white)
coin = Coin(100,300,30,30,red)
floor1 = Floor(0,400,600,30,green)
fps = (30)
clock = pygame.time.Clock()
###########################################
#START MENUE
def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()
def button(msg,x,y,w,h,ic,ac,action=None):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
#print(click)
if x+w > mouse[0] > x and y+h > mouse[1] > y:
pygame.draw.rect(window, ac,(x,y,w,h))
if click[0] == 1 and action != None:
action()
else:
pygame.draw.rect(window, ic,(x,y,w,h))
smallText = pygame.font.SysFont("comicsansms",20)
textSurf, textRect = text_objects(msg, smallText)
textRect.center = ( (x+(w/2)), (y+(h/2)) )
window.blit(textSurf, textRect)
def quitgame():
pygame.quit()
def game_intro():
intro = True
while intro:
for event in pygame.event.get():
#print(event)
if event.type == pygame.QUIT:
pygame.quit()
quit()
window.fill((255,255,255))
largeText = pygame.font.Font('freesansblod.ttf',115)
TextSurf, TextRect = text_objects("Jump", largeText)
TextRect.center = ((500/2),(500/2))
window.blit(TextSurf, TextRect)
button("GO!",100,350,100,50,green,darkgreen,main_loop)
button("Quit!",300,350,100,50,orange,darkred,quitgame)
pygame.display.update()
clock.tick(15)
###############################################
def main_loop():
def redrawwindow():
window.fill((0,0,0))
player1.draw()
coin1.draw()
floor1.draw()
window.blit(text,textRect)
font = pygame.font.Font("freesansblod.ttf",30)
score = 0
text = ("Coin"+str(score),True,(255,255,255))
textRect = text.get_rect()
textRect.center = ((100,40))
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT():
run = False
for Coin in coin1:
for coin1 in range(len(coin)-1-1-1):
if player1.rect.colliderect(coin1[one].rect):
del coin1[one]
score += 1
text = pygame.font.Font("blod.ttf",30)
textRect.center ((100,40))
key = pygame.key.get_pressed()
if key[pygame.K_a]:
player1.x -= player1.speed
if key[pygame.K_d]:
player1.x += player1.speed
if key[pygame.K_w]:
player1.y -= player1.speed
if key[pygame.K_s]:
player1.y += player1.speed
redrawwindow()
pygame.display.update()
pygame.quit()
game_intro()
main_loop()