求助 飞机大战子弹不会随着飞机动
class hero():def __init__(self,screen):
#获取窗口
self.screen = screen
# 创建玩家飞机
self.player = pygame.image.load('images/me1.png')
#飞机初始坐标
self.screen_rect = self.screen.get_rect()
self.player_rect = self.player.get_rect()
self.player_rect.centerx = self.screen_rect.centerx
self.player_rect.bottom = self.screen_rect.bottom
#飞行控制
self.hero_right = False
self.hero_left = False
self.hero_down = False
self.hero_up = False
#飞行速度与背景滚动速度
self.hero_speed = 10
self.refresh = 5
def hero_control(self):
#飞机的飞行控制
if self.hero_right and self.player_rect.right < self.screen_rect.right:
self.player_rect.centerx += self.hero_speed
if self.hero_down and self.player_rect.bottom < self.screen_rect.bottom:
self.player_rect.centery += self.hero_speed
if self.hero_up and self.player_rect.top > 0:
self.player_rect.centery -= self.hero_speed
if self.hero_left and self.player_rect.left > 0:
self.player_rect.centerx -= self.hero_speed
def hero_update(self):
self.screen.blit(self.player, self.player_rect)
#子弹刷新
class Bullets(GameSprite):
def __init__(self,player_hero):
super().__init__('images/bullet1.png',-2)
#super().hero_control()
self.rect.centerx = player_hero.player_rect.centerx
self.rect.top = player_hero.centery
def update(self):
super().update()
if self.rect.y == 0:
self.kill()
书上带入了飞机的rect属性飞机子弹就能随着飞机动了,我代入子弹都不会随着飞机动,只会在飞机的初始刷新位置发射。
子弹不能获取hero_control中飞机的rect数值,只能获取init中的初始数值,该怎么改才能让子弹和飞机一起动?