我正在尝试让我的角色在 pygame 中拍摄。我无法让子弹从他的位置移动,如果它碰到屏幕边缘就停下来。我想要的是它继续移动,直到它与屏幕边缘碰撞。每当我运行以下代码时,它都会崩溃:
class BULLET(pygame.sprite.Sprite):
def __init__(self, speed, location):
self.pos = [0,0]
pygame.sprite.Sprite.__init__(self)
self.image = SHOWBULLET
self.rect = self.image.get_rect()
self.rect.left, self.rect.top = location
self.rect.center = location
self.speed = speed
def move(self):
if AMMO > 0:
if event.type == pygame.MOUSEBUTTONDOWN and Gun.image == NOGUN:
held_down = True
if held_down == True:
self.rect.centerx = Player.rect.centerx
self.rect.centery = Player.rect.centery
if Player.direction == 0:
self.direction = 0
while self.rect.top >= screen.get_rect().top:
self.rect.top = self.rect.top + 20
if self.rect.top <= screen.get_rect().top:
break