def __init__(self, bg_size): super(BigEnemy, self).__init__() # 加载敌方飞机图片,其中大型飞机有帧切换的特效: self.image1 = pygame.image.load( resource_path(r"resources\enemy3_n1.png")) self.image2 = pygame.image.load( resource_path(r"resources\enemy3_n2.png")) self.image_hit = pygame.image.load( resource_path(r"resources\enemy3_hit.png")) self.rect = self.image1.get_rect() # 获得敌方飞机的位置 self.width, self.height = bg_size[0], bg_size[1] # 本地化背景图片位置 self.speed = 2 # 设置敌机的速度 # 获取飞机图像的掩膜用以更加精确的碰撞检测: self.mask = pygame.mask.from_surface(self.image1) self.destroy_images = [] # 加载飞机损毁图片 self.destroy_images.extend([ pygame.image.load(resource_path(r"resources\enemy3_down1.png")), pygame.image.load(resource_path(r"resources\enemy3_down2.png")), pygame.image.load(resource_path(r"resources\enemy3_down3.png")), pygame.image.load(resource_path(r"resources\enemy3_down4.png")), pygame.image.load(resource_path(r"resources\enemy3_down5.png")), pygame.image.load(resource_path(r"resources\enemy3_down6.png")) ]) self.reset()
def __init__(self): super(Bullet1, self).__init__() self.image = pygame.image.load(resource_path(r'resources\bullet1.png')) self.rect = self.image.get_rect() self.mask = pygame.mask.from_surface(self.image) self.active = False
def __init__(self, bg_size): super(SmallEnemy, self).__init__() self.image = pygame.image.load( resource_path(r"resources\enemy1.png")) # 加载敌方飞机图片 self.rect = self.image.get_rect() # 获得敌方飞机的位置 self.width, self.height = bg_size[0], bg_size[1] # 本地化背景图片位置 self.speed = 2 # 设置敌机的速度 # 获取飞机图像的掩膜用以更加精确的碰撞检测: self.mask = pygame.mask.from_surface(self.image) self.destroy_images = [] # 加载飞机损毁图片 self.destroy_images.extend([ pygame.image.load(resource_path(r"resources\enemy1_down1.png")), pygame.image.load(resource_path(r"resources\enemy1_down2.png")), pygame.image.load(resource_path(r"resources\enemy1_down3.png")), pygame.image.load(resource_path(r"resources\enemy1_down4.png")) ]) self.reset()
def __init__(self, bg_size): super(BombSupply, self).__init__() self.image = pygame.image.load(resource_path(r'resources\ufo2.png')) self.rect = self.image.get_rect() self.width, self.height = bg_size[0], bg_size[1] self.speed = 5 self.active = False self.mask = pygame.mask.from_surface(self.image) self.rect.left, self.rect.bottom = randint( 0, self.width - self.rect.width), -100
def __init__(self, bg_size): super(Myplane, self).__init__() # pygame.sprite.Sprite.__init__(self) # 加载我方飞机图片,其中飞机有尾气喷射的特效 self.image1 = pygame.image.load(resource_path(r"resources\hero1.png")) self.image2 = pygame.image.load(resource_path(r"resources\hero2.png")) self.rect = self.image1.get_rect() # 得到当前我方飞机的位置 self.width, self.height = bg_size[0], bg_size[1] # 本地化背景图片的尺寸 self.rect.left, self.rect.top = (self.width - self.rect.width) // 2, ( self.height - self.rect.height - 60) # 定义飞机初始化位置,底部预留60像素 self.speed = 10 # 设置飞机移动速度 self.active = True # 设置飞机当前的存着属性,True表示飞机正常飞行 self.invincible = False # 飞机初始化时有三秒的无敌时间 # 获取飞机图像的掩膜用以更加精确的碰撞检测: self.mask = pygame.mask.from_surface(self.image1) self.destroy_images = [] # 加载飞机损毁图片 self.destroy_images.extend([ pygame.image.load(resource_path(r"resources\hero_blowup_n1.png")), pygame.image.load(resource_path(r"resources\hero_blowup_n2.png")), pygame.image.load(resource_path(r"resources\hero_blowup_n3.png")), pygame.image.load(resource_path(r"resources\hero_blowup_n4.png")) ])