예제 #1
0
 def create_scene(self, bg_path, bg_music, bg_speed, hero_path):
     '''
     创建游戏场景
     :param bg_path: 背景图片路径
     :param bg_music: 背景音乐
     :param bg_speed: 背景速度
     :param hero_path: 英雄路径
     :param hero_mul: 英雄倍数
     :return:
     '''
     # 定义背景精灵和游戏精灵
     self.bg1 = game_sprites.BackgroudSprite(bg_path,
                                             bg_music,
                                             speed=bg_speed)
     self.bg2 = game_sprites.BackgroudSprite(bg_path,
                                             bg_music,
                                             speed=bg_speed,
                                             prepare=True)
     self.hero = game_sprites.HeroSprite(hero_path=hero_path)
     # 定义精灵组对象
     self.resources = pygame.sprite.Group(self.bg1, self.bg2)
     # 定义英雄飞机精灵组
     self.hero_group = pygame.sprite.Group(self.hero)
     # self.resources = (self.bg1, self.bg2, self.hero)
     # 定义敌机精灵组对象
     self.enemys = pygame.sprite.Group()
     # 初始化英雄飞机得分
     data.score = 0
예제 #2
0
    def create_scene(self):
        self.bg1 = game_sprites.BackgroudSprite('./images/bg_img_2.jpg')
        self.bg2 = game_sprites.BackgroudSprite('./images/bg_img_2.jpg',
                                                prepare=True)
        self.hero = game_sprites.HeroSprite(hp=500)
        # 定义精灵组对象
        self.resources = pygame.sprite.Group(self.bg1, self.bg2, self.hero)
        # 定义敌机精灵组对象
        self.enemys = pygame.sprite.Group()

        data.enemys = self.enemys
        data.hero = self.hero
        data.resources = self.resources

        # 间隔一定的时间,触发一次创建敌机的事件
        pygame.time.set_timer(self.ENEMY_CREATE, 2000)

        # bgm
        pygame.mixer_music.load('./music/fight.wav')
        pygame.mixer_music.play(-1)
예제 #3
0
    def one(self):
        '''
        游戏初始界面方法
        :return:
        '''
        data.first = False
        self.bg0 = game_sprites.BackgroudSprite(
            image_path='./images/theone.jpg',
            bg_music='./music/拳皇97开始.wav',
            speed=0)
        start_m = pygame.mixer.Sound('./music/拳王开始音效.wav')
        self.resources = pygame.sprite.Group(self.bg0)

        while True:
            # 定义时钟刷新帧,每秒让循环运行多少次!
            self.clock.tick(data.game_tick)
            # 监听所有的事件
            event_list = pygame.event.get()
            if len(event_list) > 0:
                # print(event_list)
                for event in event_list:
                    # 如果当前的事件是QUIT事件
                    if event.type == pygame.QUIT:
                        # 卸载所有的pygame资源,退出程序
                        pygame.quit()
                        exit()
                    # 按任意键进入游戏事件
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        start_m.play()
                        time.sleep(3.6)
                        self.resources.remove(self.bg0)
                        self.bg0.kill()
                        return self.start()
            # 精灵组渲染
            self.resources.update()
            self.resources.draw(self.screen)
            # 屏幕更新
            pygame.display.update()