中途岛海战大BOSS类设计

中途岛海战midway war Boss class design

"""
   中途岛海战大BOSS类设计,
   游戏中最后的boss是一架特大的飞机。它会不断地发射大颗粒子弹。
   当它的生命值降到一定的时候,会起火,最后爆炸。
"""
__author__ = "李兴球"
__date__ = "2019/9/13"

import time
import pygame
from pygame.locals import *
from random import * 

class Boss(pygame.sprite.Sprite):
    """继承自角色类的Boss类,在游戏中,它只有一个,
       所以让它属于pygame.sprite.GroupSingle组。
    """
    def __init__(self,image,explosion_images,screen):
        """
           image:造型,explosion_images:爆炸序列,screen:屏幕
        """
        pygame.sprite.Sprite.__init__(self)
        self.sw = screen.get_width()
        self.sh = screen.get_height()
        self._position = self.sw//2,self.sh//2     
        self.image = image
        self.rect = image.get_rect(center=self._position)
        # 以下是爆炸造型属性
        self.explosion_index = 0
        self.explosion_images = explosion_images
        self.explosion_rects = [im.get_rect() for im in explosion_images]
        self.explosion_amounts = len(explosion_images)
        self.dx = randint(-2,2)
        self.dy = randint(-2,2)
        self.update_interval = 0.01
        self.update_begin_time = time.time()
        self.lives = 10
        self.status = 'normal'         #  正常飞行时

    def bounce_on_edge(self):
        """碰到边缘就反弹"""
        if self.rect.left <=0 or self.rect.right>= self.sw:
               self.dx = -self.dx
        if self.rect.top <=0 or self.rect.bottom >= self.sh:
               self.dy = -self.dy
               
    def update(self):
        """更新BOSS"""
        

You must log in to read the rest of this article. Please log in or register as a user.