我是 pygame 的新手,正在尝试开发一个 8-Bit Shooter。我想要的是当用户按下空格键时,子弹会发射并一直移动,直到它击中暴徒或窗口边缘。这是子弹类:
class BULLET:
def __init__(self, location):
self.pos = [0,0]
self.image = NOBULLET
self.rect = self.image.get_rect()
self.direction = 0
def move(self):
if self.rect.right >= screen.get_rect().right:
self.rect.right = self.rect.right - 10
if self.rect.left <= screen.get_rect().left:
self.rect.right = self.rect.right + 10
if self.rect.top <= screen.get_rect().top:
self.rect.top = self.rect.top + 10
if self.rect.bottom >= screen.get_rect().bottom:
self.rect.bottom = self.rect.bottom - 10
def update(self):
while True:
for event in pygame.event.get():
if event.type == KEYDOWN:
if (event.key == K_SPACE and Gun.image == NOGUN):
self.pos == Player.pos()
self.direction == Player.direction
我想要的是当按下空格键时子弹会飞向玩家,并朝着玩家面对的方向移动,直到它击中一个暴徒或窗户的边缘。
[编辑] 这是主要的拍摄循环:
if AMMO > 0:
if event.type == pygame.KEYDOWN and Gun.image == NOGUN:
if event.key == pygame.K_SPACE and Gun.image == NOGUN:
Bullet.direction = Player.direction
Bullet.pos == Player.pos
shot.play()
print "BANG"
AMMO = AMMO - 1
time.sleep(0.09)
Bullet.image == NOBULLET