倾巢出动_飞机大战敌机类_pygame enemy class

"""
   倾巢出动_飞机大战敌机类, 这是一个动画.

   读者再加是一个玩家,让它射击就可以把这个动画变成一个射击游戏了.
"""
import glob
import pygame
from pygame.locals import *
from random import randint,choice

class Enemy():
    def __init__(self,costume,screen):
        """参数说明:
        costume:造型
        explosion_costume:爆炸造型
        screen:渲染面
        """                      
        self.image = pygame.image.load(costume).convert_alpha()        
        self.image = pygame.transform.flip(self.image,False,True)
        self.image.set_colorkey((255,255,255))
        self.screen = screen
        self.sw = screen.get_width()    #引用屏幕宽度
        self.sh = screen.get_height()   #引用屏幕高度
        self.rect = self.image.get_rect()
        self.rect.centerx = randint(0,self.sw)
        self.rect.centery = randint(-2000,-50)
        self.xspeed = 0
        self.yspeed = 15
        
    def update(self):
        self.rect.move_ip(self.xspeed,self.yspeed)
        if self.rect.top > self.sh:
            self.rect.bottom = randint(-2000,-10)
     

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