def __init__(self,fail): super(VF_Layer, self).__init__() if fail: self.count = 0 self.bg = BG(bg_name="img/fail_bg.jpg") self.fail_window=Sprite("img/f_window.png") self.fail_window.position=620,350 self.lable1 = cocos.text.Label('就', font_name='Times New Roman', font_size=200) self.lable1.position = 10, 170 self.lable2 = cocos.text.Label('这', font_name='Times New Roman', font_size=200) self.lable2.position = 900, 170 self.add(self.bg) self.add(self.fail_window) mixer.init() music.load((address_2 + r"/sound/fail.mp3").encode()) music.play() music.set_volume(1.5) else: self.count=0 self.vic_bg=BG(bg_name="img/vic_bg.jpg") self.vic_word=Sprite("img/vic_word.png") self.vic_word.position=600,400 self.A_word=Sprite("img/A_word.png") self.A_word.position=700,500 self.add(self.vic_bg) self.add(self.vic_word) self.add(self.A_word) self.mr_cai = Mr_cai() self.add(self.mr_cai) mixer.init() music.load((address_2 + r"/sound/happy_bgm.mp3").encode()) music.play() music.set_volume(0.5)
def __init__(self): super(Player_1, self).__init__() self.skin = skeleton.BitmapSkin(animation.model2_skeleton.skeleton, animation.model2_skin.skin) self.add(self.skin, 1) # self.width,self.height = 0,0 #可能有bug self.position = 100, 100 self.skin.position = 100, 100 self.life = 100 self.protect = False img = pyglet.image.load(address + "\dot.png") self.spr = cocos.sprite.Sprite(img, opacity=0) self.spr.position = 100, 100 self.spr.velocity = (0, 0) self.mover = Mover_1() self.spr.do(self.mover) self.add(self.spr) self.life_bar = cocos.sprite.Sprite("img/yellow_bar.png") self.add(self.life_bar) self.fi = Fire() # ParticleSystem self.fi.auto_remove_on_finish = True self.fi.position = (100, 50) self.status = 1 # 1:stop 2:walk 3:保持态 4:attack 5:leg_attack 6 :跳跃 self.change = False self.bullet_move = False self.count = 0 self.beheat = False self.up = False self.down = False fp_1 = open((address_2 + "/animation/MOOOOVE1.anim"), "rb+") self.walk = cPickle.load(fp_1) fp_2 = open((address_2 + "/animation/gun_shot.anim"), "rb+") self.attack = cPickle.load(fp_2) fp_3 = open((address_2 + "/animation/my_frozen.anim"), "rb+") self.frozen = cPickle.load(fp_3) fp_4 = open((address_2 + "/animation/leg_attack.anim"), "rb+") self.leg_attack = cPickle.load(fp_4) fp_5 = open((address_2 + "/animation/jump.anim"), "rb+") self.jump = cPickle.load(fp_5) mixer.init() music.load((address_2 + r"/sound/bgm.mp3").encode()) music.play() music.set_volume(0.4) self.cshape = cm.AARectShape(eu.Vector2(*self.skin.position), 80, 136) self.fire() self.bullet.cshape = cm.AARectShape(eu.Vector2(*self.bullet.position), self.bullet.width / 2, self.bullet.height / 2)
def __init__(self): super(Main_menu, self).__init__() self.items = [] self.items.append(cocos.menu.ImageMenuItem('img/start.png', self.on_start)) self.items.append(cocos.menu.ImageMenuItem('img/setting.png', self.on_setting)) self.items.append(cocos.menu.ImageMenuItem('img/help.png', self.on_help)) self.items.append(cocos.menu.MenuItem("读取武器存档", self.read_weapen)) self.items.append(cocos.menu.MenuItem("读取人物存档", self.read_char)) self.create_menu(self.items, cocos.menu.shake(), cocos.menu.shake_back()) mixer.init() music.load((address_2 + r"/sound/happy_bgm.mp3").encode()) music.play() music.set_volume(0.5)
def playmusic(soundfile, musicstatus=None): """播放背景音乐""" if musicstatus is None: config.read('config.ini', encoding='utf-8') # 读取背景音乐状态 musicstatus = config.getint('setting', 'music_status') if musicstatus == 1: # 播放背景音乐 music.load((RES_PATH + soundfile).encode()) # 加载背景音乐 if music.get_busy(): return music.play(loops=-1) # 循环播放背景音乐 music.set_volume(0.2) # 设置音量最大 else: music.stop()
def __init__(self): # Initialize the director cocos.director.director.init(width=1200, height=700) cocos.director.director.window.set_caption("Pinoy Skater") # Create all the scenes self.start_scene = StartScene(self) self.instructions_scene = InstructionsScene(self) self.game_scene = GameScene(self) self.game_over_scene = GameOverScene(self) # Play the game's soundtract game_music.load("sounds/bg.mp3") game_music.play(-1) # Run the start scene cocos.director.director.run(self.start_scene)
# 程序入口 import cocos import main_scene from cocos.audio.pygame import music # 音乐相关 # 程序开始入口 if __name__ == '__main__': """程序开始入口""" # 创建整体背景 cocos.director.director.init(width=700, height=750, caption="myGame", audio_backend='sdl') background = main_scene.create_mainScene() # 播放背景音乐(音乐为游戏古剑奇谭三背景音乐) music.load('source/sound/背景乐.mp3'.encode()) music.play(loops=-1) # 循环播放 music.set_volume(0.3) # 设置声音大小 # 运行 cocos.director.director.run(background)
pass def menu_setting_callback(self): set_sence = setting_sence.create() donghua = RotoZoomTransition(set_sence, 1.5) # 导包!! cocos.director.director.push(donghua) if __name__ == '__main__': # 初始化导演 cocos.director.director.init(width=640, height=480, caption="dog and cat", audio_backend='sdl') # 将背景层 添加到场景 bg = Game_BG() main_scence = cocos.scene.Scene(bg) # 添加菜单 mainmenu = main_menu() main_scence.add(mainmenu) # 播放背景音乐 music.load('sound/Hop.mp3'.encode()) # 需要转为编码 music.play(loops=-1) # 播放 循环次数 music.set_volume(1) # 声音大小 # 启动场景 cocos.director.director.run(main_scence)
print("call on_set_item_callback") effect = Effect('sound/Blip.wav') effect.play() # new_scene = Setting.create_scene() # director.push(new_scene) new_scene = Setting.create_scene() # dst = RotoZoomTransition(new_scene, 1.2) # dst = JumpZoomTransition(new_scene, 1.2) dst = SlideInLTransition(new_scene, 1.2) director.push(dst) def on_help_item_callback(self): print("call on_help_item_callback") if __name__ == "__main__": # 初始化导演 director.init(width=1136, height=640, caption="场景切换", audio_backend='sdl') # 创建一个场景,并将HelloWorld层实例添加到场景中 main_scene = Scene(BackGroud()) main_scene.add(MainMenu()) # 播放背景音乐 music.load('sound/Synth.ogg'.encode()) music.play(loops=-1) music.set_volume(1.0) # 开始启动main_scene场景 director.run(main_scene)