diff --git a/子弹类.txt b/子弹类.txt index adaa492..1177a3c 100644 --- a/子弹类.txt +++ b/子弹类.txt @@ -1,9 +1,14 @@ # 子弹类 -# 属性 坐标 速度 图片 -class Bullet(pygame.sprite.Sprite): +self.rect.topleft = [x + 100 / 2 - 22 / 2, y - 25] # 矩形左上角坐 + # 窗口 + self.screen = screen + # 速度 + self.speed = 20 - def __init__(self, screen, x, y): - pygame.sprite.Sprite.__init__(self) - # 图片 - self.image = pygame.image.load('./feiji/bullet.png') - self.rect = self.image.get_rect() # rect属性:矩形 \ No newline at end of file + def update(self): + # 修改子弹坐标 + self.rect.top -= self.speed + # 如果子弹移出屏幕上方,则销毁子弹对象 + if self.rect.top < -22: + # 超出界面 干掉自己 + self.kill() \ No newline at end of file