直接附上源程序了
主程序
plane_main.py
import pygame
import random
from plane_sprite import*
#定义定时常量
CREATE_ENEMY=pygame.USEREVENT
#定义英雄开火定时常量
FIRE=pygame.USEREVENT+1
class Plane_game(object):
#初始化
def __init__(self):
#显示主界面
self.screen=pygame.display.set_mode((480,852))
self.__create_sprites__()
pygame.time.set_timer(CREATE_ENEMY,1000)
pygame.time.set_timer(FIRE, 300)
self.clock=pygame.time.Clock()
self.clock1=pygame.time.Clock()
#开始游戏
def start_game(self):
while True:
#设置英雄毁灭时的帧率
if self.hero.name==3:
self.time=3
else:
self.time=60
self.clock.tick(self.time)
self.__check_collide()
self.__event_handler()
self.__update()
#显示图像
pygame.display.update()
#更新显示
def __update(self):
# 显示背景
self.back_group.update()
self.back_group.draw(self.screen)
# 显示敌人
self.enemy_group.update()
self.enemy_group.draw(self.screen)
#显示英雄
self.hero_group.update()
self.hero_group.draw(self.screen)
#显示子弹
self.bullet_group.update()
self.bullet_group.draw(self.screen)
#创建精灵类
def __cre