实现敌机类,完成敌机的主要操作。主要是用来更新位置。
- # 敌机类,继承DestroyAnimationMixin, 方便使用显示自毁动画的函数
- class Enemy(DestroyAnimationMixin):
- def __init__(self, image_path=os.path.join(source_dir, 'enemy1.png'), speed=2000, background_size=(480, 700)):
- '''
- :param image_path: 敌机图片地址
- :param speed: 敌机移动整个窗口需要的时间,单位ms,也就是速度
- :param background_size: 游戏窗口的尺寸
- '''
- self.image = pygame.image.load(image_path).convert_alpha()
- self.speed = background_size[1] / speed
- self.background_size = background_size
- self.position = [random.randint(0, background_size[0]-self.image.get_size()[0]), -self.image.get_size()[1]]
- # 开始自毁
- self.start_destroy = False
- # 自毁完成
- self.destroyed = False
- # 自毁图片路径
- self.destroy_images = ['enemy1_down1.png', 'enemy1_down2.png', 'enemy1_down3.png', 'enemy1_down3.png']
- # 距离上次绘制图像到现在的时间
- self.time_passed = 0
- # 自毁图片在self.destroy_images的位置
- self.destroy_image_position = 0
-
- def update(self, time_passed):
- '''
- 更新敌机的位置
- :param time_passed: 距离上次绘制图像到现在的时间
- :return:
- '''
- pass
(编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|