|

楼主 |
发表于 2018-8-19 08:52:23
|
显示全部楼层
import pygame
from random import *
class SmallEnemy(pygame.sprite.Sprite):
def __int__(self, back_size):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("images/enemy0.png").convert_alpha()
self.rect = self.image.get_rect()
self.width = back_size[0]
self.height = back_size[1]
self.rect.left = randint(0, self.width - self.rect.width - 120)
self.rect.top = randint(-2 * self.height, 0)
self.speed = 2
self.alive = True # 是否存活
self.mask = pygame.mask.from_surface(self.image) # 检测非透明部分
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.reset()
def reset(self):
self.alive = True # 是否存活
self.rect.left = randint(0, self.width - self.rect.width - 120)
self.rect.top = randint(-2 * self.height, 0)
class MidEnemy(pygame.sprite.Sprite):
# life = 5
def __int__(self, back_size):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("images/enemy1.png").convert_alpha()
self.rect = self.image.get_rect()
self.MidEnemy_Hit_images = []
self.MidEnemy_Hit_images.extend([
pygame.image.load("images/enemy1_down1.png").convert_alpha(),
pygame.image.load("images/enemy1_down2.png").convert_alpha(),
pygame.image.load("images/enemy1_down3.png").convert_alpha(),
pygame.image.load("images/enemy1_down4.png").convert_alpha()])
self.width = back_size[0]
self.height = back_size[1]
self.rect.left = randint(0, self.width - self.rect.width - 120)
self.rect.top = randint(-5 * self.height, -self.height)
self.speed = 1
self.alive = True # 是否存活
self.mask = pygame.mask.from_surface(self.image) # 检测非透明部分
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.reset()
def reset(self):
self.alive = True # 是否存活
self.rect.left = randint(0, self.width - self.rect.width - 120)
self.rect.top = randint(-5 * self.height, -self.height)
class BigEnemy(pygame.sprite.Sprite):
# life = 10
def __int__(self, back_size):
pygame.sprite.Sprite.__init__(self)
self.image1 = pygame.image.load("images/enemy2.png").convert_alpha()
self.image2 = pygame.image.load("images/enemy2_n2.png").convert_alpha()
self.rect = self.image1.get_rect()
self.BigEnemy_Hit_images = []
self.BigEnemy_Hit_images.extend([
pygame.image.load("images/enemy2_down1.png").convert_alpha(),
pygame.image.load("images/enemy2_down2.png").convert_alpha(),
pygame.image.load("images/enemy2_down3.png").convert_alpha(),
pygame.image.load("images/enemy2_down4.png").convert_alpha(),
pygame.image.load("images/enemy2_down5.png").convert_alpha(),
pygame.image.load("images/enemy2_down6.png").convert_alpha()])
self.width = back_size[0]
self.height = back_size[1]
self.rect.left = randint(0, self.width - self.rect.width - 120)
self.rect.top = randint(-10 * self.height, -2 * self.height)
self.speed = 1
self.alive = True # 是否存活
self.mask = pygame.mask.from_surface(self.image1) # 检测非透明部分
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.reset()
def reset(self):
self.alive = True # 是否存活
self.rect.left = randint(0, self.width - self.rect.width - 120)
self.rect.top = randint(-10 * self.height, -2 * self.height)
|
|