[英]How do I get my score to update my text in pong?
I am trying to get my text to update my score when my ball hits the wall behind the paddle or when it hits the paddle. 我试图让我的文字更新我的球时,我的球撞到了桨后面的墙或撞到了桨。 How would I go about this? 我将如何处理?
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
I have all of my data member outside my score function but i feel like it is where I blit the surface 我所有的数据成员都在我的计分功能之外,但我觉得那是我弄污表面的地方
您应该将self.string = ...
行从__init__()
方法移到draw()
方法中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.