You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
3.2 KiB
98 lines
3.2 KiB
from typing import Any
|
|
|
|
import pygame
|
|
from pygame.sprite import Sprite
|
|
|
|
|
|
class Explode0(Sprite):
|
|
def __init__(self, ai_game):
|
|
super().__init__()
|
|
# 获取屏幕设置
|
|
self.screen = ai_game.screen
|
|
self.screen_rect = ai_game.screen.get_rect()
|
|
self.settings = ai_game.settings
|
|
|
|
|
|
class Explode(Explode0): # 敌人的爆炸
|
|
def __init__(self, ai_game):
|
|
super().__init__(ai_game)
|
|
self.images = self.settings.frame_images
|
|
self.frame = 0
|
|
self.image = self.images[self.frame]
|
|
self.rect = self.image.get_rect()
|
|
self.last_frame = 15
|
|
|
|
self.last_time = pygame.time.get_ticks()
|
|
self.now_time = None
|
|
self.frame_rate = 0
|
|
|
|
sound = pygame.mixer.Sound('resource/Bonus/boom.wav')
|
|
# sound.set_volume(0.9)
|
|
sound.play()
|
|
|
|
def update(self):
|
|
self.now_time = pygame.time.get_ticks()
|
|
if self.now_time - self.last_time > self.frame_rate:
|
|
self.last_time = self.now_time
|
|
if self.frame <= self.last_frame:
|
|
self.image = self.images[self.frame]
|
|
self.frame += 1
|
|
else:
|
|
self.kill()
|
|
|
|
|
|
class Explode1(Explode0): # 飞船被击毁时的爆炸
|
|
def __init__(self, ai_game):
|
|
super().__init__(ai_game)
|
|
# 导入图片
|
|
self.images = [pygame.image.load("resource/Damage/playerShip3_damage" + str(i) + ".png") for i in range(1, 4)]
|
|
self.image_index = 2
|
|
self.image = self.images[self.image_index]
|
|
self.image_rect = self.image.get_rect()
|
|
self.image_index = 3
|
|
# 改变爆炸
|
|
self.ready_to_change = 0
|
|
|
|
# 播放声音
|
|
sound = pygame.mixer.Sound('resource/Bonus/sfx_lose.ogg')
|
|
sound.play()
|
|
|
|
def update(self, *args: Any, **kwargs: Any) -> None:
|
|
if self.image_index > 0:
|
|
self.ready_to_change += 1
|
|
if self.ready_to_change % 10 == 0:
|
|
self.image_index -= 1
|
|
self.image = self.images[self.image_index]
|
|
else:
|
|
self.kill()
|
|
# print("dw")
|
|
|
|
|
|
class Explode2(Explode0): # 飞船被击中的提示
|
|
def __init__(self, ai_game):
|
|
super().__init__(ai_game)
|
|
# 导入图片
|
|
self.ship = ai_game.ship
|
|
self.images = [pygame.image.load("resource/Effects/shield" + str(i) + ".png") for i in range(1, 4)]
|
|
self.image_index = 2
|
|
self.image = self.images[self.image_index]
|
|
self.image_rect = self.image.get_rect()
|
|
self.rect = self.image_rect
|
|
# 改变爆炸
|
|
self.ready_to_change = 0
|
|
|
|
# 播放声音
|
|
sound = pygame.mixer.Sound("resource/Bonus/sfx_zap.ogg")
|
|
sound.set_volume(0.1)
|
|
sound.play()
|
|
|
|
def update(self, *args: Any, **kwargs: Any) -> None:
|
|
self.rect.center = self.ship.rect.center
|
|
if self.image_index >= 0:
|
|
self.ready_to_change += 1
|
|
if self.ready_to_change % 10 == 0:
|
|
self.image_index -= 1
|
|
self.image = self.images[self.image_index]
|
|
else:
|
|
self.kill()
|