这是本人设计的飞机大战中途岛海战的BOSS类。供给单独需要的人。
下面是部分代码预览:
"""
中途岛海战大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)
def bounce_on_edge(self):
"""碰到边缘就反弹"""
def update(self):
"""更新BOSS"""
if __name__ == "__main__":
width,height = 960,720
screen = pygame.display.set_mode((width,height))
pygame.display.set_caption('中途岛海战Boss类设计程序by lixingqiu')
boss_image = pygame.image.load("boss_images/bigboss.png").convert_alpha()
boss_ex_images = [ f"boss_images/explode_{i}.png" for i in range(25)]
boss_ex_images = [pygame.image.load(im).convert_alpha() for im in boss_ex_images]
boss = Boss(boss_image,boss_ex_images,screen)
boss_group = pygame.sprite.GroupSingle()
boss_group.add(boss)
clock = pygame.time.Clock()
running = True
while running:
for event in pygame.event.get():
if event.type == QUIT:running = False
if event.type == KEYDOWN:
boss.lives -= 1
if boss.lives <= 0:
boss.update_interval = 0.2
boss.status = 'explosion'
boss_group.update()
screen.fill((40,60,80))
boss_group.draw(screen)
pygame.display.update()
clock.tick(60)
pygame.quit()
如需要查看完整源代码,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)
