2013-06-19 29 views
0

林做一個遊戲來練習mygame和IM創造高分屏,但我似乎無法正確的blit文我多麼希望在pygame的位圖傳輸文本

這裏是高分方法

def high_screen(self): 
    screen.blit(background,(0,0)) 
    myfont = pygame.font.SysFont("impact", 20) 
    scorefile = open('highscores.txt', 'r') 
    highscores = scorefile.read() 
    label = myfont.render((highscores), 1, (0,0,0)) 
    screen.blit(label, (0, 0)) 

    self.back = pygame.image.load('resources/screen/back.png') 
    self.back_r = self.back.get_bounding_rect() 
    self.back_r.x,self.back_r.y = (100,600) 
    screen.blit(self.back,(100, 600)) 
    screen.blit(self.player,(self.mouse_pos)) 
    if self.player_r.colliderect(self.back_r)and pygame.mouse.get_pressed()[0]: 
     self.state = 1 

這ggets從一個.txt文件的高分和blits他們,但它在一條線上blits他們,當我想要每個分數傳遞大約從上面的100個像素

所以我怎麼能使它分裂文本從文件和blits每個分數下降100個像素?

謝謝

-Christian Careaga

回答

0

你可以把一個文件的每個進球,然後簡單地做一些事情,如:

screen.blit(label1, (0, 0)) 
screen.blit(labe2, (0, 100)) 
screen.blit(labe3, (0, 100)) 
#etc 
+0

這就是真實的,但我想我要像10分,但我不希望有10個文件 – Serial

+0

好吧我不是在Python數據存儲太棒了,我認爲你可以使用擱置,而不是10個文件只有10個鍵。 –

+0

有趣....虐待嘗試 – Serial

0

如果你的分數是在假設一個文件看起來是這樣的:


score1 - 10

score2 - 23

score3 - 34


那麼你可以使用這個把分數分成不同的文字

scorelist = [text.split('\n') for text in open('score.txt','r')] 
##when you read the file from python you will get this string : score1 - 10\nscore2 - 23\nscore3 - 34 

再到位這個到表面,使用此代碼:

for i in enumerate(scorelist,1): 
    surface.blit(i[1],(100,100+i[0]*100))