def get_test_scene(): template_action = ac.Repeat( # repeat forever ( ac.Delay(1.0) # wait 1 second + # and then ac.Rotate(360, 2.0) # rotate 360 degrees in 2 seconds + # and then ac.Delay(1.0) # wait 1 second + # and then ac.ScaleTo(2.0, 1.0) # zoom to 2x in 1 second + # and then ac.ScaleTo(1.0, 1.0) # zoom to 1x in 1 second ) w, h = director.get_window_size() world = cocos.layer.Layer() # bluish square bluish_square = cocos.layer.ColorLayer(0, 160, 176, 255, width=100, height=100) # transform_anchor set to the center position of itself bluish_square.transform_anchor = (bluish_square.width / 2.0, bluish_square.height / 2.0) bluish_square.position = (w // 3, h // 2) bluish_square.do(template_action) world.add(bluish_square, z=2) mark_anchor = cocos.layer.ColorLayer(161, 191, 54, 255, width=8, height=8) mark_anchor.position = (bluish_square.x + bluish_square.transform_anchor_x, bluish_square.y + bluish_square.transform_anchor_y) world.add(mark_anchor, z=3) # redish square redish_square = cocos.layer.ColorLayer(201, 43, 0, 255, width=100, height=100) # transform_anchor set to the bottomleft corner of itself redish_square.transform_anchor = (0, 0) redish_square.position = (w * 2 // 3, h // 2) redish_square.do(template_action) world.add(redish_square, z=2) mark_anchor = cocos.layer.ColorLayer(161, 191, 54, 255, width=8, height=8) mark_anchor.position = (redish_square.x + redish_square.transform_anchor_x, redish_square.y + redish_square.transform_anchor_y) world.add(mark_anchor, z=3) scene = cocos.scene.Scene() scene.add(world) return scene
def push_sequence_scene(): scene_blue = Scene() layer_blue = ColorLayer(32, 32, 255, 255) scene_blue.add(layer_blue, z=0) scene_blue.do(ac.Delay(2) + ac.CallFunc(pop_scene)) scene_red = Scene() layer_red = ColorLayer(255, 32, 0, 255) scene_red.add(layer_red, z=0) scene_red.do(ac.Delay(2) + ac.CallFunc(pop_scene)) director.push(SequenceScene(scene_blue, scene_red))
def main(): director.init(resizable=True, fullscreen=False) main_scene = cocos.scene.Scene() main_scene.add(BackgroundLayer(), z=0) action1 = ac.ShuffleTiles(grid=(16, 8), seed=2, duration=3) + ac.StopGrid() action2 = (ac.Delay(0.5) + ac.CallFunc(toggle_fullscreen) + ac.Delay(2.0) + ac.CallFunc(toggle_fullscreen)) combo_action = action1 | action2 # In real code after a sequence of grid actions the StopGrid() action # should be called. Omited here to stay in the last grid action render main_scene.do(combo_action) director.run(main_scene)
def win(self): self.winSprite = cocos.sprite.Sprite('assets/winscreen.PNG', position=(g.screenWidth / 2, g.screenHeight / 2)) self.add(self.winSprite) action = ac.Delay(4) + ac.FadeOut(3) self.winSprite.do(action)
def show_message(self, msg, callback=None): w, h = director.get_window_size() self.msg = cocos.text.Label(msg, font_size=52, font_name=consts['view']['font_name'], anchor_y='center', anchor_x='center', width=w, multiline=True, align="center") self.msg.position = (w / 2.0, h) self.add(self.msg) actions = ( ac.Show() + ac.Accelerate(ac.MoveBy((0, -h / 2.0), duration=0.1)) + ac.Delay(1) + ac.Accelerate(ac.MoveBy((0, -h / 2.0), duration=0.1)) + ac.Hide() ) if callback: actions += ac.CallFunc(callback) self.msg.do(actions)
def enemy_actions(self, action_list): # Make the "anchor" action a delay of no seconds self._enemy_actions = ac.Delay(0) # Uses the overloaded + operator to make a chain of # actions for step in action_list: self._enemy_actions += step
def main(): director.init(resizable=True) director.set_depth_test() main_scene = cocos.scene.Scene() main_scene.add(BackgroundLayer(), z=0) action1 = ac.WavesTiles3D(waves=2, amplitude=70, grid=(16, 16), duration=3) action2 = (ac.Delay(0.5) + ac.CallFunc(toggle_fullscreen) + ac.Delay(2.0) + ac.CallFunc(toggle_fullscreen)) combo_action = action1 | action2 # In real code after a sequence of grid actions the StopGrid() action # should be called. Omited here to stay in the last grid action render main_scene.do(combo_action) director.run(main_scene)
def main(): print(description) director.init(resizable=True, width=640, height=480) scene_green = Scene() layer_green = ColorLayer(32, 255, 0, 255) scene_green.add(layer_green) scene_green.do(ac.Delay(2.0) + ac.CallFunc(push_sequence_scene)) # pyglet 1.1.4 needs this to timely pump actions pyglet.clock.schedule(lambda dt: None) director.run(scene_green)
def showMessage(text, duration=3.5): global currentAction if not message in director.scene.get_children(): director.scene.add(message, z=100) if message.active: message.remove_action(currentAction) message.do(message.hideAction) message.lbl.element.text = text currentAction = message.do( actions.CallFunc(message.activate) + message.showAction + actions.Delay(duration) + message.hideAction + actions.CallFunc(message.deactivate)) # + actions.CallFunc(remove))
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 on_page_changed(page, num): # XXX record non-page-changes? def save(num=num): t = time.time() filename = 'screenshot-%d.png' % num f = open(os.path.join(options.record, 'timing.txt'), 'a') f.write('%.1f %s\n' % (t, filename)) filename = os.path.join(options.record, filename) buffer = pyglet.image.get_buffer_manager().get_color_buffer() buffer.save(filename) # delay a moment to allow rendering to complete page.do(actions.Delay(.1) + actions.CallFunc(save))
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 create_ghosts(self): ghosts_start = self.scenario.ghosts_start blinky_x, blinky_y = ghosts_start[0] clyde_x, clyde_y = ghosts_start[1] inky_x, inky_y = ghosts_start[2] pinky_x, pinky_y = ghosts_start[3] self.add( actors.Blinky( blinky_x, blinky_y, ac.Delay(5) + ac.Repeat(self.scenario.ghosts_action[0]))) self.add( actors.Clyde( clyde_x, clyde_y, ac.Delay(7) + ac.Repeat(self.scenario.ghosts_action[1]))) self.add( actors.Inky( inky_x, inky_y, ac.Delay(9) + ac.Repeat(self.scenario.ghosts_action[2]))) self.add( actors.Pinky( pinky_x, pinky_y, ac.Delay(11) + ac.Repeat(self.scenario.ghosts_action[3])))
def __init__(self, line: Line): class Qwq(cac.IntervalAction): def init(self, width, duration): self._width = width self.duration = duration def start(self): self._cur = self.target.scale_y def update(self, t): self.target.scale_y = (self._cur - self._width) * (1 - t) + self._width def p(state: Line.LineState): res = copy.copy(state) res.x *= settings.size res.x += (settings.width - settings.size) / 2 res.y *= settings.size res.y += (settings.height - settings.size) / 2 return res states = list(map(p, sorted(line.states, key=lambda e: e.sec))) super().__init__('line_empty.png', (states[0].x, states[0].y), states[0].angle) for note in line.notes: self.add(NoteSprite(note)) line_sprite = cocos.sprite.Sprite('line.png') self.add(line_sprite) action = None pre = states[0] for i in states[1:]: act = cac.MoveTo((i.x, i.y), i.sec - pre.sec) | cac.RotateBy(i.angle - pre.angle, i.sec - pre.sec) if i.rev != pre.rev: act |= cac.Delay(i.sec - pre.sec) + cac.FlipY(duration=0.01) if not action: action = act else: action += act pre = i if action: self.do(action) action = None sec = 0 for i in states: act = Qwq(i.width, i.sec - sec) if not action: action = act else: action += act sec = i.sec if action: line_sprite.do(action)
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 __onTie(self): u""" Execução dos efeitos quando houver empate """ # Para o jogo para execução dos efeitos self.ableToPlay = False # Definição dos efeitos fade = actions.FadeOut(1) for i in xrange(9): # Faz todos sprites desaparecerem self.sprites[i].do(fade) # Define um atraso de 1 segundo pro jogo reiniciar self.do(actions.Delay(1) + actions.CallFunc(self.newGame))
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 run_opponent_hero_power_animations(layer, event): assert isinstance(event, std_e.HeroPowerPhase) owner, player_id = event.owner, event.player_id i = layer.player_id_to_i(player_id) # Only show for opponent hero power events. if i == 0: return spr_kw = { 'position': pos(*layer.ShowXY), 'scale': 0.6, 'selected_effect': None, 'unselected_effect': None} copied_sprite = HeroPowerFullArtSprite(owner, **spr_kw) copied_sprite.add_to_layer(layer) layer.do_animation( actions.Delay(C.UI.Cocos.Animation.OpponentShowTime) + remove_myself_action(), target=copied_sprite)
def __init__(self, x, y, orientation, target, machine, delay, image): # using universal delay calculate animation speed accordingly self.delay = delay / 2.38 self.num_frames = 7 self.target = target self.machine = machine animation = self.load_animation(image, self.delay) # depending on direction, rotate image accordingly if orientation == 'horizontal': animation = animation.get_transform(rotate=90) # now create actual instance pos = eu.Vector2(x, y) super().__init__(animation, pos) self.do( ac.CallFunc(self.target.replace) + ac.Delay(self.num_frames * self.delay) + ac.CallFunc(self.machine.begin_reload) + ac.CallFunc(self.kill))
def run_opponent_play_animations(layer, event): assert isinstance(event, std_e.OnPlay) owner, player_id = event.owner, event.player_id i = layer.player_id_to_i(player_id) # Only show for opponent play events. if i == 0: return spr_kw = { 'position': pos(*layer.ShowXY), 'is_front': True, 'scale': 0.6, 'sel_mgr_kwargs': {'set_default': False}, 'selected_effect': None, 'unselected_effect': None} copied_sprite = HandSprite(owner, **spr_kw) copied_sprite.add_to_layer(layer) layer.do_animation( actions.Delay(C.UI.Cocos.Animation.OpponentShowTime) + remove_myself_action(), target=copied_sprite)
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 __onWin(self): u""" Execução dos efeitos quando alguém ganhar """ # Para o jogo para execução dos efeitos self.ableToPlay = False # Definição dos efeitos blink = actions.Blink(10, 1.5) fade = actions.FadeOut(1) for i in xrange(9): if self.game.values[i] == self.game.lastTurn: # Se o sprite é do jogador vencedor então fazer ele piscar self.sprites[i].do(blink) else: # Se o sprite é do jogador perdedor então fazer ele desaparecer self.sprites[i].do(fade) # Define um atraso de 2 segundos pro jogo reiniciar self.do(actions.Delay(1.5) + actions.CallFunc(self.newGame))
def e_burn(self): self.state = 'burning' self.color = (180, 0, 0) template_action = ac.Delay(2.0) + ac.CallFunc(self.e_free) self.do(template_action)
enemyWeapons = {} helperWeapons = {} playerShips = tuple() playerGuns = tuple() playerWeapons = tuple() playerDevices = tuple() playerShields = tuple() playerEngines = tuple() playerReactors = tuple() currents = {'avatarObject': None, 'layerObject': None} adata = { None: None, 'aMove': actions.Move(), 'aDelay01': actions.Delay(0.1), 'aDelay03': actions.Delay(0.3), 'aDelay1': actions.Delay(1), 'aDown5': actions.MoveBy((0, -900), duration=5), 'aDown6': actions.MoveBy((0, -900), duration=6), 'aDown9': actions.MoveBy((0, -900), duration=9), 'aFloat60': actions.MoveBy((0, 60), duration=1), 'aFloat100': actions.MoveBy((0, 100), duration=1) } effectsData = {None: None} ''' HELPERS ''' def rel(xRel, yRel):
def create_player(self): player_start = self.scenario.player_start x, y = player_start self.add(actors.Player(x, y, ac.Delay(5)))
def fire(self,x,y): self.do(actions.MoveTo((x,y),0.5) | actions.ScaleTo(0.5,0.5) + actions.Delay(0.5) + actions.CallFunc(self.explode))
def replace(self): self.do(ac.Delay(0.15) + ac.CallFunc(self.load_product)) self.processed = True
def __init__(self, pos): super(Explosion, self).__init__(EXPLOSION_IMG, pos) self.do(ac.Delay(1) + ac.CallFunc(self.kill))
def __init__(self, pos): die_img = load_animation('assets/Player/pacman_die.png', 1, 11, False) super(Die, self).__init__(die_img, pos) self.do(ac.Delay(1) + ac.CallFunc(self.kill))
def __init__(self, pos): super(Explosion, self).__init__(explosion_img, pos) self.do(ac.Delay(1) + ac.CallFunc(self.kill))