简体   繁体   English

如何获得分数以更新Pong中的文字?

[英]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.

相关问题 如何更新我的分数? - How to update my score? 如何使用 tkinter 在我的乒乓球游戏中添加分数跟踪器,为什么会出现 position 类型错误? - how can i add a score tracker to my pong game using tkinter and why am i getting a position type error? Python / Pygame如何使我的成绩文本永远自我更新? - Python/Pygame How to make my Score Text update itself forever? 如何添加一个分数文本列表,该列表每次单击Cookie精灵时加1? (蟒蛇) - How do I add a score text list that adds 1 each time I click my cookie sprite? (python) 如何随机化我的球与桨的碰撞位置? 乒乓 Pygame - How Do I Randomize Where My Ball Collides With The Paddle? Pong Pygame 如何为乌龟游戏添加高分系统? - How do I add a high score system to my turtle game? 如何在我的程序中重置 A 'Score Bank'? Python - How Do I Reset The A 'Score Bank' In My Program? Python 如何在 pygame 的屏幕顶部显示分数? - How do I display a score at the top of my screen in pygame? 如何在我的海龟游戏中设置最高分系统? - How do I put a top score system to my turtle game? 我为pong创建了一个Score类,当我添加变量count + = 1时,它应该继续添加,但只能保持为1 - I have created a Score class for pong, when I add my variable count += 1 it should continue to add but only stays at one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM