2017-09-26 4 views
0

내 프로그램을 실행 한 후 "글꼴이 초기화되지 않았습니다"오류가 계속 나타납니다. 여기에 프로그램이 있습니다. 나는 파이 게임을 초기화하고 있다는 것을 안다. 나는 pygame, pygame.font, 그리고 둘 모두를 동시에 초기화하려고 시도했다. 나는 모든 것을 해냈다. 나는 pygames 기본 글꼴을 pygame.font.Font ('freesansbold.ttf', 115)로 사용하려고 시도했다. 그것도 작동하지 않았다.글꼴이 초기화되지 않았습니다.

import pygame 
import time 
import random 
pygame.init 
pygame.font.init 


display_width = 800 
display_height = 600 

black = (0,0,0) 
white = (255,255,255) 
red = (255,0,0) 
green = (0,255,0) 
blue = (0,0,255) 

car_width = 100 
car_height = 100 

gameDisplay = pygame.display.set_mode((display_width,display_height)) 
pygame.display.set_caption('A Bit Racey') 
clock = pygame.time.Clock() 

carImg = pygame.image.load ('racecar.png') 
gameOver = pygame.image.load ('gameover.png') 

def gO (x,y): 
    gameDisplay.blit(gameOver, (x,y)) 

def things(thingx, thingy, thingw, thingh, color): 
    pygame.draw.rect(gameDisplay, color, [thingx, thingy, thingw, thingh]) 

def text_objects(text, font): 
    textSurface = font.render (text, True, black) 
    return textSurface, textSurface.get_rect() 

def message_display(text): 
    font = pygame.font.SysFont("C:\Windows\Fonts\Arial.ttf", 115) 
    TextSurf, TextRect = text_objects(text, font) 
    TextRect.center = ((display_width/2), (display_height/2)) 
    gameDisplay.blit(TextSurf, TextRect) 

    time.sleep(2) 
    game_loop() 

def crash(): 
    message_display('Game Over') 

def car(x,y): 
    gameDisplay.blit(carImg,(x,y)) 

def game_loop(): 

    x = (display_width * 0.45) 
    y = (display_height * 0.8) 

    x_change = 0 

    thing_startx = random.randrange(0, display_width) 
    thing_starty = -600 
    thing_speed = 7 
    thing_width = 100 
    thing_height = 100 

    gameExit = False 

    while not gameExit: 

     for event in pygame.event.get(): 
      if event.type == pygame.QUIT: 
       gameExit = True 

      if event.type == pygame.KEYDOWN: 
       if event.key == pygame.K_LEFT: 
        x_change = -5 
       elif event.key == pygame.K_RIGHT: 
        x_change = 5 

      if event.type == pygame.KEYUP: 
       if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: 
        x_change = 0 


     x += x_change 

     gameDisplay.fill(white) 

     #thingx, thingy, thinkw, thingh, color) 
     things(thing_startx, thing_starty, thing_width, thing_height, black) 
     thing_starty += thing_speed 
     car (x,y) 

     if x > display_width - car_width or x < 0: 
      crash() 


     if thing_starty > display_height: 
      thing_starty = 0 - thing_height 
      thing_startx = random.randrange(0, display_width) 


     if y < thing_starty+thing_height: 
      print('y crossover') 

      if x > thing_startx and x < thing_startx + thing_width or x+car_width > thing_startx and + car_width < thing_startx+thing_width: 
       print('x crossover') 
       gO (display_width/2 - 145.5, display_height/2-200) 
       time.sleep(2) 
       game_loop() 


     if gameExit == True: 
      pygame.quit() 
      quit() 


     pygame.display.update()  
     clock.tick(45) 

game_loop() 
pygame.quit() 
quit() 
+0

재현 할 수 없으므로 오류가 발생하지 않습니다 – davedwards

+0

잘못된 글꼴 경로입니까? 또는 오타? – NeoVe

답변

0

당신은 정말 당신의 조각에 init 기능을 실행하지 않았다.

# didn't run function 
pygame.init 
pygame.font.init 
# instead 
pygame.init() 
pygame.font.init() 
+0

감사. 나는 문자 그대로 파이썬을 어제 시작했고 그것은 내가 작성한 유일한 것입니다. 내가 할게. 다시 한번 감사드립니다. –

0

귀하의 질문은 이상합니다. 정말 이상해. 심지어 문제가되지 않습니다. 함수 pygame.init()을 호출하지 않습니다. 당신은 그것을 평가하고 있습니다. 당신은 그 존재를 확인하고 있습니다. 함수가 존재하지 않는다면 파이썬은 예외를 발생시킬 것입니다.하지만 파이썬은 아무것도하지 않습니다. 함수를 호출하려면 <function_name>(<parameters>)을 사용하십시오. 이. 그렇지. 아니. 루비.

+0

당신 말이 맞아요. 감사. (나는 RUBY로 작성한 적이 없지만 당신이 의미하는 바를 얻는다.) 나는 어제 파이썬을 작성하기 시작했다. 다시 한 번 감사드립니다. –

관련 문제