如何让我的分数更新我的乒乓文字?

时间:2017-03-19 19:40:59

标签: python pygame pong

当我的球撞到球拍后面的墙壁或撞到球拍时,我正试图让我的文字更新我的分数。我该怎么做呢?

import pygame
import ball
import paddle


class Points:
    def __init__(self,x,y):

    self.x=x
    self.y=y

    self.color= (255,0,0)
    font_height = 25
    self.Font = pygame.font.SysFont("calibri",font_height)
    self.count = 0
    self.comp = 0
    self.player = 0
    self.point = 0
    self.ball = ball.Ball(x, y)

    self.string = ("player: " + str(self.player)+"   computer: " + str(self.comp))



def draw(self,surface):

    text_object = self.Font.render(self.string, False, self.color)
    text_rect = text_object.get_rect()
    text_rect.center = (self.x, self.y)
    surface.blit(text_object, text_rect)



def score(self, paddle):
    if self.ball.x - self.ball.x2 <= 0:
        self.count += 1
        self.comp = self.count


    elif (self.ball.x < paddle.getX() + paddle.getW()
          and self.ball.y > paddle.getY()
          and self.ball.y <= paddle.getY() + paddle.getH()):
        self.point +=1
        self.player = self.point

我的所有数据成员都在我的分数函数之外,但我觉得这是我表面上的blit

1 个答案:

答案 0 :(得分:0)

您应该将self.string = ...行中的__init__()行移至draw()方法。