def __init__(self, score): super(GameOverLayer, self).__init__() self.score = score # 获得窗口的宽度和高度 s_width, s_height = cocos.director.director.get_window_size() # 创建db文件夹 if not os.path.exists('db'): os.mkdir('db') with dbm.open(DB_NAME, 'c') as db: highscore = db.get(HIGHSCORE_KEY, b'0').decode() logger.info(highscore) if int(highscore) < self.score: highscore = str(self.score) db[HIGHSCORE_KEY] = highscore self.scorelabel = cocos.text.Label(highscore, font_name='Harlow Solid Italic', font_size=17, anchor_x='center', anchor_y='center') self.scorelabel.position = s_width // 2 + 30, 136 self.add(self.scorelabel, 1) # 创建背景精灵 add_to_scene(self, RES_PATH + 'bg.png')
def __init__(self): super(LoadingLayer, self).__init__() logger.info("启动Loading场景") # 获得窗口的宽度和高度 s_width, s_height = cocos.director.director.get_window_size() # 创建背景精灵 add_to_scene(self,RES_PATH + 'bg.png') # 动画帧序列 frames = [pyglet.resource.image(RES_PATH + 'loding1.png'), pyglet.resource.image(RES_PATH + 'loding2.png'), pyglet.resource.image(RES_PATH + 'loding3.png'), pyglet.resource.image(RES_PATH + 'loding4.png')] # 创建动画图片对象 animimage = pyglet.image.Animation.from_image_sequence(frames, 0.3, True) # 创建动画精灵对象 loding = cocos.sprite.Sprite(animimage) # 设置窗口居中位置 loding.position = s_width // 2, s_height // 2 - 60 self.add(loding, 0) # 创建一个子线程加载资源 lodingthread = threading.Thread(target=self.thread_body) # 启动线程 lodingthread.start()
def on_enter(self): """Home层进入方法""" super(HomeLayer, self).on_enter() logger.info('进入Home层') if len(self.get_children()) != 0: # 判断是否层已经初始化 return tools.playmusic('home_bg.ogg') add_to_scene(self,RES_PATH + 'bg.png')
def __init__(self): super(HelpLayer, self).__init__() logger.info('初始化帮助层') # # 获得窗口的宽度和高度 # s_width, s_height = cocos.director.director.get_window_size() # # 创建背景精灵 # background = cocos.sprite.Sprite(RES_PATH + 'bg.png') # background.position = s_width // 2, s_height // 2 # # 添加背景精灵到HelloWorld层 # self.add(background, 0) add_to_scene(self, RES_PATH + 'bg.png')
def __init__(self): super(SettingLayer, self).__init__() logger.info('初始化设置层') add_to_scene(self, RES_PATH + 'bg.png') # # 读取配置信息 self.config = configparser.ConfigParser() self.config.read('config.ini', encoding='utf-8') # 读取音效状态 self.sound = FuncBtn('sound_status') self.music = FuncBtn('music_status') self.sound.status = self.config.getint('setting', 'sound_status') # 读取背景音乐状态 self.music.status = self.config.getint('setting', 'music_status') self.check_on_image = pyglet.resource.image(RES_PATH + 'check-on.png') self.check_off_image = pyglet.resource.image(RES_PATH + 'check-off.png') self.sound.ctl = self.make_check_button(self.sound.status, 210, 328) self.music.ctl = self.make_check_button(self.music.status, 210, 270)