plane_main.py 设置主文件
import pygame
from plane_sprites import*
from Background import BackGround
from Enemy import Enemy
from Hero import Hero
from time import sleep
from Bullet import Bullet
class Plane_main(object):
def __init__(self):
print('游戏初始化')
self.screen = pygame.display.set_mode(SCREEN_RECT.size)
self.clock = pygame.time.Clock()
self.__create_sprites()
pygame.time.set_timer(CREATE_ENEMY_EVENT,1000)
pygame.time.set_timer(HERO_FIRE_EVENT, 500)
self.count = 0
self.score = 0
def __create_sprites(self):
# 背景组
self.back_group = pygame.sprite.Group()
bg1 = BackGround()
bg2 = BackGround(True)
pygame.mixer.init()
pygame.mixer.music.load("./Capo Productions - Journey 00_00_00-00_00_59.ogg")
pygame.mixer.music.play(-1)
self.back_group.add(bg1,bg2)
# 敌机组
self.enemy_group = pygame.sprite.Group()
#敌级销毁组
self.enemy1_down_group=pygame.sprite.Group()
# 英雄组
self.hero_group = pygame.sprite.Group()
self.hero = Hero()
self.hero_group.add(self.hero)
def start_game(self):
pygame.init()
print("开始游戏...")
# pygame.mixer.init()
# pygame.mixer.music.load("./Capo Productions - Journey 00_00_00-00_00_59.ogg")
# pygame.mixer.music.play(-1)
# gameIcon = pygame.image.load("./name.png")
# pygame.display.set_icon(gameIcon)
while True:
self.count+=1
# 1. 设置刷新帧率
self.clock.tick(10)
# 2. 事件监听
self.__event_handler()
# 3. 碰撞检测
self.__check_collide()
# 4. 更新精灵组
self.__update_sprites()
# 5. 更新屏幕显示