【发布时间】:2021-04-20 15:41:14
【问题描述】:
代码:
import pygame , sys, time, random
from pygame.locals import *
def enemie():
global speed, ball
ball.y += speed
if ball.y == 602:
ball = pygame.Rect(random.randint(0, 450), 0 ,20,20)
def blast():
global bl, blast
blast.y = bl
def player_animation():
global player_speed, playerx
player.x = player_speed
pygame.init()
running = True
clock = pygame.time.Clock()
speed = 7
bl = 1
player_speed = 1
ball = pygame.Rect(random.randint(0, 450), 0 ,20,20)
player = pygame.Rect(250, 450, 50, 50)
blast = pygame.Rect(300, 0 ,20,20)
screen = pygame.display.set_mode((500, 500))
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
enemie()
player_animation()
blast()
screen.fill((255, 255, 255)) #color
pygame.draw.ellipse(screen, [255, 0, 0], ball)
pygame.draw.ellipse(screen, [0, 0, 255], player)
pygame.draw.ellipse(screen, [0, 255, 0], blast)
if ball.colliderect(player):
pygame.quit()
sys.exit()
keys=pygame.key.get_pressed()
if keys[K_LEFT] and player.x != -4 :
player_speed -= 5
if keys[K_RIGHT] and player.x != 451:
player_speed += 5
if event.type == pygame.MOUSEBUTTONDOWN:
bl += 5
pygame.display.flip()
clock.tick(30)
pygame.quit()
错误:
line 54, in <module>
blast()
TypeError: 'pygame.Rect' object is not callable
我正在尝试创建一些会移动的球。当我点击时,绿球或爆炸应该会移动, 错误是否意味着存在不属于的 ) 或 ( ?但我找不到我的错误...我以前遇到过这个错误,我不记得我是如何解决的。什么是错误是什么意思?我该如何解决这个问题?提前谢谢!
【问题讨论】:
标签: python python-3.x pygame