[英]How do I get my score to update my text in 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
我所有的數據成員都在我的計分功能之外,但我覺得那是我弄污表面的地方
您應該將self.string = ...
行從__init__()
方法移到draw()
方法中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.