def char_die(self): global lives if (lives > 0): lives -= 1 self.osd.update() director.replace(FadeTransition(game_scene.cur_level(), duration=1)) else: director.replace( FadeTransition(game_scene.GameOverScene(), duration=1)) lives = char_initial_lives
def step(self, dt): if (self.playing): delta = self.speed * dt self.fx += delta self.parent.wobble.x -= delta self.manager.set_focus(self.fx, self.fy) if (self.parent.px_width - self.fx <= 400): director.replace( FadeTransition(game_scene.next_level(), duration=1)) self.playing = False
def game_over(): w, h = director.get_window_size() layer = cocos.layer.Layer() text = cocos.text.Label('Game Over', position=(w*0.5, h*0.5), font_name='Oswald', font_size=72, anchor_x='center', anchor_y='center') layer.add(text) scene = cocos.scene.Scene(layer) new_scene = FadeTransition(mainmenu.new_menu()) #FadeTransition轉場景特效 func = lambda: director.replace(new_scene) scene.do(ac.Delay(3) + ac.CallFunc(func)) #如同在main.menu.py的self.create_menu所說,場景也可以做動作,故在3秒後才切換至新場景 return scene
def game_over(): w, h = director.get_window_size() layer = cocos.layer.Layer() text = cocos.text.Label('Game Over', position=(w/2, h/2), font_name='Oswald', font_size=72, anchor_x='center', anchor_y='center') layer.add(text) scene = cocos.scene.Scene(layer) new_scene = FadeTransition(mainmenu.new_menu()) func = lambda: director.replace(new_scene) scene.do(ac.Delay(3)+ac.CallFunc(func)) return scene
def next_level(stay=False): if stay == False: #new_level = Scenario.INSTANCE.level_id+1 Scenario.INSTANCE.level_id += 1 else: #new_level = Scenario.INSTANCE.level_id pass filename = "level/level-%i.txt" % (Scenario.INSTANCE.level_id) if os.path.isfile(filename): game_layer = GameLayer(Scenario.INSTANCE) director.push(FadeTransition(cocos.scene.Scene(game_layer), duration=2)) else: director.replace(SplitColsTransition(game_over(False)))
def game_over(): w, h = director.get_window_size() layer = cocos.layer.Layer() text = cocos.text.Label('Game Over', position=(w * 0.5, h * 0.5), font_name=constants.OSWALD, font_size=72, anchor_x=constants.CENTER, anchor_y=constants.CENTER) layer.add(text) scene = cocos.scene.Scene(layer) new_scene = FadeTransition(mainmenu.new_menu()) replace_scene = lambda: director.replace(new_scene) scene.do(ac.Delay(3) + ac.CallFunc(replace_scene)) return scene
def game_over(): # create a text label w, h = director.get_window_size() layer = cocos.layer.Layer() text = cocos.text.Label('Game Over', position=(w * 0.5, h * 0.5), font_name='Oswald', font_size=72, anchor_x='center', anchor_y='center') layer.add(text) scene = cocos.scene.Scene(layer) menu_scene = FadeTransition(mainmenu.new_menu()) show_menu = lambda: director.replace(menu_scene) scene.do(ac.Delay(3) + ac.CallFunc(show_menu)) return scene
def game_over(over=True): #print("game_over") w, h = director.get_window_size() layer = cocos.layer.Layer() if over: label_txt = "Game Over" else: label_txt = "Game Pass" text = cocos.text.Label(label_txt, position=(w * 0.5, h * 0.5), font_name='Oswald', font_size=72, anchor_x='center', anchor_y='center') layer.add(text) scene = cocos.scene.Scene(layer) new_scene = FadeTransition(mainmenu.new_menu()) func = lambda: director.replace(new_scene) scene.do(ac.Delay(3) + ac.CallFunc(func)) return scene
def on_mouse_press(self, x, y, buttons, modifiers): director.replace(FadeTransition(game_scene.first_level(), duration=0.4))
def on_key_press(self, key, modifiers): director.replace(FadeTransition(game_scene.first_level(), duration=0.4))
def on_story(self): director.push(FadeTransition(reader_scene.StoryScene(), duration=0.4))
def on_credits(self): director.push(FadeTransition(reader_scene.CreditsScene(), duration=0.4))
def on_new_game(self): #director.push(game_scene) director.push(FadeTransition(intro_scene.get_scene(), duration=0.4))
def on_key_press(self, key, modifiers): if symbol_string(key) == "ENTER": director.replace(FadeTransition(scene.Scene(FirstStage()))) elif symbol_string(key) == "BACKSPACE": director.replace(JumpZoomTransition(scene.Scene(WelcomeScreen())))
def play(): cocos.director.director.replace(FadeTransition(GameScene()))
def __init__(self): super().__init__() mi_etiqueta = cocos.text.Label('Gladiator', font_name='Consolas', font_size=22, anchor_x='center', anchor_y='center') mi_etiqueta.position = (320, 240) self.add(mi_etiqueta) class VerTexto2(cocos.layer.Layer): def __init__(self): super().__init__() mi_etiqueta = cocos.text.Label('Roma 980 AC...', font_name='Consolas', font_size=22, anchor_x='center', anchor_y='center') mi_etiqueta.position = (320, 240) self.add(mi_etiqueta) if __name__ == '__main__': cocos.director.director.init(caption='Gladiator') escena_1 = cocos.scene.Scene(VerTexto()) escena_2 = cocos.scene.Scene(VerTexto2()) cocos.director.director.run(FadeTransition(escena_2, 5, escena_1))