def start(self): #variaveis a serem resetadas com u jogo novo self.is_game_over = False self.is_colliding_left = False self.is_colliding_right = False self.is_colliding_base = False self.currentScore = 0 self.game_time = 0 self.c_manager = game_controller.game_controller.c_manager# obtem instancia do gerenciador de colisao self.keybd_input = Keyboard_Input()# iniciaiza o layer de input do teclado self.wall_limits = Wall_Limits()# iniciaiza o layer para as delimitacoes do jogo self.pieces_wall = Pieces_Wall()# iniciaiza o layer de bloco de pecas self.game_info_layer = Game_Info()# iniciaiza o layer de informacoes do jogo (informacoes no canto direito) self.game_over_lyr = Ranking(is_game_over=True)# iniciaiza o layer de game over para mostrar ranking self.pause_lyr = Pause()# iniciaiza o layer de pause do game # iniciaiza o layer multiplo para alternar entre layer do input,mostrar o game over e pause self.multi_layer = MultiplexLayer(Layer(), self.game_over_lyr, self.pause_lyr) self.add(self.wall_limits)# adiciona layer self.add(self.game_info_layer)# adiciona layer self.add(self.pieces_wall)# adiciona a a layer self.add(self.keybd_input)# adiciona layer self.add(self.multi_layer)# adiciona layer self.add_next_piece()# inicializa a primeira peca self.start_timer()
def __init__(self): Scene.__init__(self) self.add( Sprite(image=pyglet.resource.image('background.png'), position=(self.anchor_x, self.anchor_y))) # Background Image black_fade = ColorLayer(0, 0, 0, 0) black_fade.opacity = 120 self.add(black_fade) menu = Menu("TETRIS") menu.position = (0, -60) menu.font_title["font_name"] = "Tetrominoes" menu.font_title["color"] = (214, 178, 152, 255) menu.font_item["font_name"] = "Ravie" menu.font_item_selected["font_name"] = "Ravie" menu_items = [ MenuItem('Start Game', game_controller.game_controller.init_new_game), MenuItem('Ranking', self.show_ranking), MenuItem('Quit', game_controller.game_controller.close_scene) ] menu.menu_hmargin = 10 menu.create_menu(menu_items) menu.on_quit = self.on_quit self.menu_lyr = Layer() self.menu_lyr.add(menu) self.rank = Ranking() self.multi_layer = MultiplexLayer(self.menu_lyr, self.rank) self.add(self.multi_layer)
def main(): director.init(**resources.settings['window']) scene = Scene() scene.add(MultiplexLayer( MainMenu(scene), LevelSelectMenu(), OptionsMenu(), ScoresLayer(), HelpLayer(), AboutLayer() ), z=1) director.set_show_FPS(resources.settings["general"]["showFps"]) w, h = director.get_window_size() # Music - moved to resources # 1st Try - doesnt play anything # scene.load_music("assets/music.wav") # scene.play_music() # 2nd Try - static noise louder than music # music = pyglet.resource.media("assets/music.wav", streaming = True) # music.play() # 3rd Try - music stops after ca. 1 min (even when piece was longer) # and doesnt repeat as it should # music_player = pyglet.media.Player() # music = pyglet.resource.media("assets/music.wav", streaming = False) # music_player.queue(music) # music_player.eos_action = music_player.EOS_LOOP director.run(scene)
def main(): script_dir = os.path.dirname(os.path.realpath(__file__)) pyglet.resource.path = [join(script_dir, '..')] pyglet.resource.reindex() director.director.init(width=800, height=650, caption="Match 3") scene = Scene() scene.add(MultiplexLayer(MainMenu()), z=1) director.director.run(scene)
self.create_menu([MenuItem('Go Back', self.on_quit)]) def on_quit(self): self.parent.switch_to(0) global keyboard, scroller #https://github.com/los-cocos/cocos/blob/master/samples/demo_grid_effects.py cocos.director.director.init(autoscale=False, resizable=True, width=2000, height=800) keyboardHandler = key.KeyStateHandler() scrollerHandler = cocos.layer.ScrollingManager() cocos.director.director.window.push_handlers(keyboardHandler) #cocos.director.director.window.push_handlers(scroller) mapScene = Scene(keyboardHandler, scrollerHandler) menulayer = MultiplexLayer(MainMenu(), OptionMenu(), ScoreMenu()) scrollerHandler.add(mapScene) scene = cocos.scene.Scene(mapScene, scrollerHandler, menulayer) scene.schedule(mapScene.checkButtons) cocos.director.director.on_resize = mapScene.resize cocos.director.director.run(scene)
self.font_item_selected['font_size'] = 41 self.menu_anchor_x = cocos.menu.CENTER self.menu_anchor_y = cocos.menu.CENTER self.scene = scene self.w, self.h = director.get_window_size() director.interpreter_locals["pyfense_main"] = self items = [] items.append(cocos.menu.MenuItem('Start Game', self.on_start_game)) items.append(cocos.menu.MenuItem('Exit', self.on_quit)) self.create_menu(items) def on_start_game(self): pass def on_quit(self): pyglet.app.exit() if __name__ == "__main__": director.init() scene = Scene() scene.add(MultiplexLayer( MainMenu(scene), ), z=1) w, h = director.get_window_size() director.run(scene)
from os.path import exists, join import pyglet.resource import os.path from cocos import director from cocos.scene import Scene from cocos.layer import MultiplexLayer from Menus import MainMenu script_dir = os.path.dirname(os.path.realpath(__file__)) pyglet.resource.path = [join(script_dir, '..')] pyglet.resource.reindex() director.director.init(width=800, height=650, caption="Pop The Same") scene = Scene() scene.add(MultiplexLayer( MainMenu() #,OptionsMenu(), #ScoresLayer(), ), z=1) director.director.run(scene)
from scene import Scene from game.map.menu import MainMenu, MapOptionMenu, ScoreMenu global keyboard, scroller #https://github.com/los-cocos/cocos/blob/master/samples/demo_grid_effects.py cocos.director.director.init(autoscale=False, resizable=True, width=2000, height=800) keyboardHandler = key.KeyStateHandler() scrollerHandler = cocos.layer.ScrollingManager() cocos.director.director.window.push_handlers(keyboardHandler) sceneHandler = Scene(keyboardHandler, scrollerHandler) scrollerHandler.add(sceneHandler) menulayer = MultiplexLayer(MainMenu(), MapOptionMenu(sceneHandler.map), ScoreMenu()) sceneHandler.setMenuLayer(menulayer) scene = cocos.scene.Scene(sceneHandler, scrollerHandler, menulayer) scene.transform_anchor = (0, 0) sceneHandler.transform_anchor = (0, 0) scene.schedule(sceneHandler.checkButtons) cocos.director.director.on_resize = sceneHandler.resize cocos.director.director.run(scene)
def menu(): return Scene(TitleLayer(), MultiplexLayer(MainMenu(), OptionMenu(), LoadMenu()))
self.background_sprite = cocos.sprite.Sprite( pyglet.resource.image('main_background.png')) self.background_sprite.position = self.width / 2, self.height / 2 self.add(self.background_sprite, z=0) self.name_sprite = cocos.sprite.Sprite( pyglet.resource.image('game_name.png')) self.name_sprite.position = self.width / 2, self.height * 0.8 self.add(self.name_sprite, z=20) self.floor_layer = FloorLayer(self.width) self.floor_layer.position = 0, 50 self.add(self.floor_layer, z=10) if __name__ == "__main__": pyglet.resource.path.append('res') pyglet.resource.reindex() font.add_directory('res') director.init(resizable=True, width=500, height=800) scene = Scene() scene.add(MultiplexLayer(MainMenu(), OptionsMenu(), ScoresLayer()), z=1) scene.add(BackgroundLayer(), z=0) # scene.add(MainLayer()) director.set_show_FPS(True) director.run(scene)
class Main_Game(Scene): is_event_handler = True def __init__(self): Scene.__init__(self) self.anchor = Vector2() def start(self): #variaveis a serem resetadas com u jogo novo self.is_game_over = False self.is_colliding_left = False self.is_colliding_right = False self.is_colliding_base = False self.currentScore = 0 self.game_time = 0 self.c_manager = game_controller.game_controller.c_manager# obtem instancia do gerenciador de colisao self.keybd_input = Keyboard_Input()# iniciaiza o layer de input do teclado self.wall_limits = Wall_Limits()# iniciaiza o layer para as delimitacoes do jogo self.pieces_wall = Pieces_Wall()# iniciaiza o layer de bloco de pecas self.game_info_layer = Game_Info()# iniciaiza o layer de informacoes do jogo (informacoes no canto direito) self.game_over_lyr = Ranking(is_game_over=True)# iniciaiza o layer de game over para mostrar ranking self.pause_lyr = Pause()# iniciaiza o layer de pause do game # iniciaiza o layer multiplo para alternar entre layer do input,mostrar o game over e pause self.multi_layer = MultiplexLayer(Layer(), self.game_over_lyr, self.pause_lyr) self.add(self.wall_limits)# adiciona layer self.add(self.game_info_layer)# adiciona layer self.add(self.pieces_wall)# adiciona a a layer self.add(self.keybd_input)# adiciona layer self.add(self.multi_layer)# adiciona layer self.add_next_piece()# inicializa a primeira peca self.start_timer() def start_timer(self): self.schedule_interval(self.count_time, 1)#inicia timer para contagem do tempo def stop_timer(self): self.unschedule(self.count_time)#remove contagem do tempo def game_over(self): self.is_game_over = True self.c_manager.clear()# limpa lista de objetos com colisao self.unschedule(self.count_time) self.multi_layer.switch_to(1) self.game_over_lyr.show_rank() def add_next_piece(self): self.currPiece = self.game_info_layer.obtain_next_piece() # obtem peca inicial(a primeira proxima peca...) self.currPiece.position = POS_NEW_PIECE self.pieces_wall.add(self.currPiece)# adiciona peca na layer de pecas e blocos self.currPiece.start_fall() for (_, block) in self.currPiece.children:# adiciona peca atual ao gerenciador de colisao self.c_manager.add(block) def sum_score(self, amount): # soma no score a quantidade passada self.currentScore += amount self.game_info_layer.update_score(self.currentScore) def count_time(self, time_elapsed):# metodo chamado com o tempo que passou (1s), entao guarda e atualiza na layer o tempo atual do jogo self.game_time += time_elapsed self.game_info_layer.update_time(self.game_time) def piece_must_stop(self):# executa o necessario para parar a peca e adicionar ao bloco de pecas self.currPiece.stop_fall()# para a peca self.currPiece.update_blk_cshape()# atualiiza a colisao para a ultima posicao da peca apos terminar de cair if(self.currPiece.y >= 525):# finaliza a partida quando nao consegue adicionar mais pecas ao topo self.game_over() return self.sum_score(27)# adiciona o score de uma peca self.pieces_wall.process_piece(self.currPiece) self.add_next_piece() def on_pause(self): self.pause() self.stop_timer() self.currPiece.stop_fall() self.multi_layer.switch_to(2) def on_unpause(self): self.resume() self.start_timer() self.currPiece.start_fall() self.multi_layer.switch_to(0) def on_rank_exit(self): if(self.is_game_over): game_controller.game_controller.close_scene() def on_exit(self): self.remove(self.wall_limits)# adiciona layer self.remove(self.game_info_layer)# adiciona layer self.remove(self.pieces_wall)# adiciona a a layer self.remove(self.keybd_input)# adiciona layer self.remove(self.multi_layer)# adiciona layer self.c_manager.clear()# limpa lista de objetos com colisao if(self.is_game_over):# quando acontece um game over adiciona a pontuacao ao rank score = self.currentScore plyr_name = self.game_over_lyr.player_name time_str = self.game_info_layer.get_time_str() self.game_over_lyr.add_rank({score:(plyr_name, time_str)}) return super().on_exit() def on_enter(self): self.start() return super().on_enter() ''' KEYS INPUT ''' def key_action(self, time_elapsed, key_string):# para cada tecla executa a acao especifica if(key_string == 'P' or key_string == 'ESCAPE'): self.on_pause() if(not self.is_colliding_base and key_string == 'DOWN'): self.unschedule(self.currPiece.do_fall) self.schedule_interval(self.currPiece.do_fall, 0.03) if(not self.is_colliding_left and key_string == 'LEFT'): self.currPiece.move(Vector2(-25,0)) if(not self.is_colliding_right and key_string == 'RIGHT'): self.currPiece.move(Vector2(25,0)) if(key_string == 'SPACE'): self.currPiece.rotate() def time_delay(self, time_elapsed, key_string):# executado depois de um certo delay self.unschedule(self.time_delay) self.schedule_interval(self.key_action, 0.1, key_string)# move a peca a cada 100ms enquanto a tecla ainda estiver pressionada def on_key_press(self, key, modifiers): key_string = symbol_string(key)# obtem o valor em string da tecla pressionada self.key_action(0, key_string)#executa uma acao da tecla quando pressionado self.schedule_interval(self.time_delay, 0.3, key_string)# espera 300ms antes de comecar a mover a peca rapidamente def on_key_release(self, key, modifiers):# quando a tecla deixa de ser pressionada ele para de mover a peca rapidamente self.unschedule(self.key_action) self.unschedule(self.time_delay)
def create_menu_scene(): scene = Scene() scene.add(BackgroundLayer(), z=0) scene.add(SpritesLayer(), z=1) scene.add(MultiplexLayer(MainMenu(), OptionMenu()), z=2) return scene
def start2(): director.set_depth_test() firelayer = FireManager(director.get_window_size()[0], 250) spritelayer = SpriteLayer() menulayer = MultiplexLayer(Ending3()) scene = Scene(firelayer, spritelayer, menulayer) twirl_normal = Twirl(center=(320, 240), grid=(16, 12), duration=15, twirls=6, amplitude=6) twirl = AccelDeccelAmplitude(twirl_normal, rate=4.0) lens = Lens3D(radius=240, center=(320, 240), grid=(32, 24), duration=5) waves3d = AccelDeccelAmplitude(Waves3D(waves=18, amplitude=80, grid=(32, 24), duration=15), rate=4.0) flipx = FlipX3D(duration=1) flipy = FlipY3D(duration=1) #flip = Hide(duration=1) liquid = Liquid(grid=(16, 12), duration=4) ripple = Ripple3D(grid=(32, 24), waves=7, duration=10, amplitude=100, radius=320) shakyt = ShakyTiles3D(grid=(16, 12), duration=3) corners = CornerSwap(duration=1) waves = AccelAmplitude(Waves(waves=8, amplitude=50, grid=(32, 24), duration=5), rate=2.0) shaky = Shaky3D(randrange=10, grid=(32, 24), duration=5) quadmove = QuadMoveBy(delta0=(320, 240), delta1=(-630, 0), delta2=(-320, -240), delta3=(630, 0), duration=2) fadeout = FadeOutTRTiles(grid=(16, 12), duration=2) cornerup = MoveCornerUp(duration=1) cornerdown = MoveCornerDown(duration=1) shatter = ShatteredTiles3D(randrange=16, grid=(16, 12), duration=4) shuffle = ShuffleTiles(grid=(16, 12), duration=1) orbit = OrbitCamera(radius=1, delta_radius=2, angle_x=0, delta_x=-90, angle_z=0, delta_z=180, duration=4) jumptiles = JumpTiles3D(jumps=2, duration=4, amplitude=80, grid=(16, 12)) wavestiles = WavesTiles3D(waves=3, amplitude=60, duration=8, grid=(16, 12)) turnoff = TurnOffTiles(grid=(16, 12), duration=2) scene.do( Delay(5) + ripple + Delay(2) + wavestiles + Delay(1) + twirl + liquid + Delay(2) + shakyt + Delay(2) + ReuseGrid() + shuffle + Delay(4) + ReuseGrid() + turnoff + Reverse(turnoff) + Delay(1) + shatter + #flip + Delay(2) + #Reverse(flip) + flipx + Delay(2) + ReuseGrid() + flipy + Delay(2) + ReuseGrid() + flipx + Delay(2) + ReuseGrid() + flipy + Delay(2) + lens + ReuseGrid() + ((orbit + Reverse(orbit)) | waves3d) + Delay(1) + corners + Delay(2) + Reverse(corners) + waves + Delay(2) + ReuseGrid() + shaky + jumptiles + Delay(1) + cornerup + Delay(1) + Reverse(cornerdown) + Delay(1) + fadeout + Reverse(fadeout) + Delay(2) + quadmove + Delay(1) + Reverse(quadmove) + StopGrid()) scene.do(Delay(10) + OrbitCamera(delta_z=-360 * 3, duration=10 * 4)) firelayer.do(Delay(4) + Repeat(RotateBy(360, 10))) return scene
def __init__(self): super(MenuScene, self).__init__() self.add(MultiplexLayer(ProfileMenu(), CreateProfileMenu(), MainMenu()))
def new_game(): director.init(resizable=False, width=1024, height=768) scene = Scene() scene.add(BackgroundLayer(), z=0) scene.add(MultiplexLayer(MainMenu(), ), z=1) director.run(scene)
def signal_handler(signal_received, frame): """ Handle Ctrl + C signal """ if signal_received is signal.SIGINT: # erase the ^C on Terminal print "\r " exit(0) if __name__ == "__main__": # Add pyglet resources directories resource.path.append('data') resource.reindex() font.add_directory('data/fonts') signal.signal(signal.SIGINT, signal_handler) keyboard = key.KeyStateHandler() EventHandle().keyboard = keyboard director.init(width=WIDTH, height=HEIGHT, caption='SpaceWars') director.window.push_handlers(keyboard) # observer to joystick clock.schedule_interval(connect_joystick, .1) # Create a initial menu scene scene = Scene() scene.add(BackgroundLayer('backgrounds/space_background.png'), z=0) scene.add(MultiplexLayer(MainMenu(), Credits(), OptionsMenu()), z=1) director.run(scene)
if self.button_exit[0] < x < self.button_exit[2] and \ self.button_exit[1] < y < self.button_exit[3]: self.rul.close_window() self.rules = False window_w, window_h = 1300, 800 if platform == 'darwin': director.init(width=window_w, height=window_h, fullscreen=True) else: director.init(width=window_w, height=window_h) game_session = session.Session( 4, ["Player 1", "Player 2", "Player 3", "Player 4"]) scene = Scene(MouseDisplay()) scene.add(MultiplexLayer( menu.MainMenu(), menu.SavedGames(), menu.Rules(), menu.Information(), menu.NewGame(), menu.Endgame(), ), z=1) top_window = menu.Top_Window(game_session.move_player) scene.add(menu.BackgroundLayer(), z=0) director.run(scene)
def get_main_scene(): firelayer = FireManager(director.get_window_size()[0], 250) menulayer = MultiplexLayer(MainMenu(), OptionMenu(), ScoreMenu()) scene = Scene(firelayer, menulayer) return scene
def setup(test=False, phase_source=None, train_end_calls=[]): director.director.init(width=1056, height=700, caption='MatchBrain') scene = Scene() scene.add(MultiplexLayer(MainMenu(test, phase_source, train_end_calls), ), z=1) return scene