0

请帮帮我,我有这个代码:

import sys, pygame
pygame.init()

size = width, height = 800, 600
speed = [2, 2]
black = 1, 1, 1

screen = pygame.display.set_mode(size)

ball = pygame.image.load("ball.bmp")
ballrect = ball.get_rect()
player1 = pygame.image.load("player1.png")
player1rect = player1.get_rect()

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()

    ballrect = ballrect.move(speed)
    if ballrect.left < 0 or ballrect.right > width:
        speed[0] = -speed[0]
    if ballrect.top < 0 or ballrect.bottom > height:
        speed[1] = -speed[1]

    player1rect = player1rect.move(speed)
    if player1rect.w < 0 or player1rect.s > heght:
        speed[1] = -speed[1]

    screen.fill(black)
    screen.blit(ball, ballrect) (player1, player1rect)
    pygame.display.flip()

当我尝试启动它时,它只是说:

Traceback (most recent call last):
  File "C:\Users\User\Documents\Pong\pong.py", line 31, in <module>
    screen.blit(ball, ballrect) (player1, player1rect)
TypeError: 'pygame.Rect' object is not callable

那么有人可以帮助我吗?而且我几乎尝试了所有方法,但它不起作用,如果我的代码有更多问题,请写出来。

(对不起,我的英语不好)

4

1 回答 1

0

将第 31 行替换为两行:

screen.blit(ball, ballrect)
screen.blit(player1, player1rect)

这应该可以解决您的问题

于 2013-07-09T15:50:04.877 回答