中途岛海战敌机发射的子弹类测试模块

"""
   中途岛海战敌机发射的子弹类
   本程序新建敌机子弹类,子弹有一个目的地,
   它实例化后会朝目的地不断地移动。
"""
import math
import pygame
from pygame.locals import *
from random import randint

class Enemy_Bullet(pygame.sprite.Sprite):
    """
       敌机子弹类      
    """
    def __init__(self,image,pos,dest,screen):
        """
           image:图形,pos:初始坐标,dest:目标,screen:屏幕
        """
        pygame.sprite.Sprite.__init__(self)       
        self.image = image         
        self.rect = self.image.get_rect(center=pos)
        self.dx = (dest[0] - pos[0]) //15
        self.dy = (dest[1] - pos[1]) //15
        self.screen = screen

    def update(self):
        """更新"""
        self.rect.move_ip(self.dx,self.dy)
        c = self.screen.get_rect().contains(self.rect)
        if not c:
            self.kill()
def main():
    """主要函数"""
    bg = 'images/海洋.png'
    image = "images/Shot.png"
    width,height = size = 960,720
    center = width//2,height//2
    
    screen = pygame.display.set_mode(size)
    pygame.display.set_caption("中途岛海战敌机发射的子弹类by lixingqiu")
    bg = pygame.image.load(bg)
    

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