通过学习廖雪峰老师网课编写
主运行程序编写
import pygame
from plane_sprites import *
SCREEN_RECT = pygame.Rect(0, 0, 480, 720)
FRAME_PER_SEC = 60
CREATE_ENEMY_EVENT = pygame.USEREVENT
HERO_FIRE_EVENT = pygame.USEREVENT + 1
class planeGame(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)
def __create_sprites(self):
bg1 = BackGround()
bg2 = BackGround(True)
self.back_group = pygame.sprite.Group(bg1, bg2)
self.enemy_group = pygame.sprite.Group()
self.hero = Hero()
self.hero_group = pygame.sprite.Group(self.hero)
def start_game(self):
print("游戏开始")
while True:
self.clock.tick(FRAME_PER