def __init__(self): sceneManager = SceneManager() scene = MenuScene() sceneManager.Startup(scene) sceneManager.run()
def show(self, callback=None): Scene.show(self) if callback: self.callback = callback self.img = PIL.Image.open( ResourceManager.get(Config.get("photomaton")["template"])) self.img_counter = 0 SceneManager.get_instance().show_scene("snap", self._process_img)
def main(argv): desc = u'{0} [Args] [Options]\nDetailed options -h or --help'.format( __file__) parser = ArgumentParser(description=desc) parser.add_argument('-debug', action='store_true', dest='debug') parser.add_argument('-scene', type=str, dest='initScene', required=False, help='initial scene') parser.add_argument('-proxy', type=str, dest='proxy', required=False, help='https proxy setting') args = parser.parse_args() #print str(args.debug) #print str(args.initScene) pCTX = CTX() pCTX.httpsProxy = args.proxy pRender = RenderManager() #pRender.RenderBaseFrame() pWanem = WanemManager(pCTX, pRender) pSceneManager = SceneManager(pCTX, pRender, pWanem, initScene=args.initScene, debug=args.debug) pTouch = TouchManager(pSceneManager) now = time.time() while True: pSceneManager.Update() pCTX.current = time.time() waitBy = now + (1 / 60.0 * pCTX.tick) #pTouch.Update(pWanem, TouchDownHandler, TouchUpHandler, waitBy - pCTX.current) pTouch.Update(waitBy - pCTX.current) pCTX.current = time.time() if waitBy > pCTX.current: time.sleep(waitBy - pCTX.current) pCTX.current = time.time() if pCTX.current - now >= 1.0: # print "pCTX.tick : %02d / %d" % (pCTX.tick, int(pCTX.current * 1000)) now += 1.0 pCTX.tick = 0 pCTX.tick += 1 pRender.Finalize() pTouch.Finalize()
def _default_cb(self, path, img): Screen.get_instance().get_window().blit(img, (0, 0)) Screen.get_instance().update() start_time = time.time() if not os.path.isfile(path): Logger.log_error("File '%s' was not created" % path) else: SnapScene.create_qrcode(os.path.basename(path), "cache/last_qrcode.png") elapsed = time.time() - start_time to_wait = Config.get("picture_show_delay") - elapsed if to_wait > 0: time.sleep(to_wait) SceneManager.get_instance().show_main_scene()
def main(): screen = pygame.display.set_mode( (Settings.screenWidth, Settings.screenHeight), pygame.RESIZABLE) pygame.display.set_caption("NBack Test") timer = pygame.time.Clock() running = True manager = SceneManager() startTestTicks = pygame.time.get_ticks() while running: timer.tick(60) #Event Handling events = [] for event in pygame.event.get(): events.append(event) if event.type == pygame.QUIT: running = False #if event.type == pygame.VIDEORESIZE: #screen = pygame.display.set_mode(event.dict['size'], pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.RESIZABLE) manager.scene.handle_events(events) #Updating seconds = float(pygame.time.get_ticks() - startTestTicks) / 1000 manager.scene.update(seconds) manager.scene.render(screen) pygame.display.flip() pygame.quit()
def load(self): pygame.init() self._display = pygame.display.set_mode( self.size, pygame.HWSURFACE | pygame.DOUBLEBUF) self.currentScene = SM.getScene(SM.HomeScene, self._display) self._running = True
def __init__(self): self._running = False self.target_fps = 60 self.clock = pg.time.Clock() self.scene_manager = SceneManager() self.scene_manager.update_window_size(WIDTH, HEIGHT) self.scene_manager.retarget_drawing(pg.display.get_surface()) self.scene_manager.begin(GameScene)
class Screens(Screen): ''' Screens is an abstract class that blueprints the creation of kivy screens. This class works closely with the SceneManager to make transition of screens easier. Note that the only parent class method that should be called is the on_init method ''' __metaclass__ = type('Screens', (type(Screen), ABCMeta), {}) _manager = SceneManager() ''' This is the default constructor. Here in the constructor ''' def __init__(self, name): ''' Constructor ''' Screen.__init__(self) self.name = name Screens._manager.add_screen(self) ''' This method changes the background color of the screen ''' def background_color(self, r, g, b, alpha): with self.canvas: Color(r, g, b, alpha) Rectangle(pos=self.pos, size=Window.size) ''' This method makes this specific screens class instance as the currently viewed screen. ''' def make_active(self): Screens._manager.active_screen(self.name) ''' This method is used to init all properties for the specific instance of the screens class this should be the last class method called ''' @abstractmethod def on_init(self): pass ''' This method will update all objects painted on screen ''' @abstractmethod def update(self): pass
def __init__(self): self.scene_manager = SceneManager(self) pygame.init() self.size = self.width, self.height = 640, 640 self.background_color = 200, 200, 200 self.screen = pygame.display.set_mode(self.size) self.clock = pygame.time.Clock() self.scene_manager.set_scene('Menu') while True: delta_time = 1 / float(self.clock.tick(60)) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: sys.exit() self.update(delta_time, events) self.screen.fill(self.background_color) self.draw(self.screen) pygame.display.flip()
class Game(): def __init__(self): self.sceneManager = SceneManager(self) pygame.init() self.size = self.width, self.height = 480, 320 self.backgroundColor = 0, 0, 0 self.screen = pygame.display.set_mode(self.size) self.clock = pygame.time.Clock() self.sceneManager.setScene('Menu') self.cursor = Cursor(self) while 1: deltaTime = 1 / float(self.clock.tick(60)) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: sys.exit() self.update(deltaTime, events) self.screen.fill(self.backgroundColor) self.draw(self.screen) pygame.display.flip() def update(self, deltaTime, events): self.cursor.update(deltaTime, events) self.sceneManager.update(deltaTime, events) def draw(self, screen): self.sceneManager.draw(screen) self.cursor.draw(screen)
def _process_img(self, path, img): if self.img_counter < self.nb_imgs - 1: Scene.show(self, self.one_more_imgs[self.img_counter]) else: Scene.show(self, self.wait_img) start_time = time.time() Logger.log_debug( "process img %d / %d" % (self.img_counter, len(Config.get("photomaton")["placeholders"]))) rect = Config.get("photomaton")["placeholders"][self.img_counter] pic = PIL.Image.open(path) pic.thumbnail((rect["w"], rect["h"])) self.img.paste(pic, (rect["x"], rect["y"])) self.img_counter += 1 if self.img_counter < self.nb_imgs: elapsed = time.time() - start_time to_wait = Config.get("photomaton")["wait"] - elapsed if to_wait > 0: time.sleep(to_wait) SceneManager.get_instance().show_scene("snap", self._process_img) else: self.callback(self.img)
def _default_cb(self, img): now = time.strftime( "%Y-%m-%d_%H.%M.%S" ) #get the current date and time for the start of the filename filename = "photomaton_%s.jpg" % now path = os.path.join(SnapScene.get_folder(), filename) self.img.save(path) if not os.path.isfile(path): Logger.log_error("File '%s' was not created" % path) else: img = Screen.get_instance().create_image("tmp") img.load(path) img.adapt_to_screen() Scene.show(self, img) SnapScene.create_qrcode( filename, os.path.join(ResourceManager.get_instance().get_folder(), "last_qrcode.png")) to_wait = Config.get("picture_show_delay") if to_wait > 0: time.sleep(to_wait) SceneManager.get_instance().show_main_scene()
def _default_cb(self, path, img): now = time.strftime("%Y-%m-%d_%H.%M.%S") #get the current date and time for the start of the filename filename = "special_%s.jpg" % now new_path = os.path.join(SnapScene.get_folder(), filename) img = PIL.Image.open(path) pic = PIL.Image.open(ResourceManager.get(self.selected_overlay)) img.paste(pic, (0, 0), pic) img.save(new_path) if not os.path.isfile(path): Logger.log_error("File '%s' was not created" % path) else: img = Screen.get_instance().create_image("tmp") img.load(new_path) img.adapt_to_screen() Scene.show(self, img) SnapScene.create_qrcode(filename, "cache/last_qrcode.png") to_wait = Config.get("picture_show_delay") if to_wait > 0: time.sleep(to_wait) SceneManager.get_instance().show_main_scene()
from Panel import Panel from Square import Square from Square import BouncingSquares import time import random from Disperse import Disperse from Scene import Scene from SceneManager import SceneManager from ImgSizer import ImgSizer p = Panel() sceneManager = SceneManager() sceneManager.addScene(Scene(BouncingSquares(1,1,400,p), 300)) stamp = p.getMillis() fRate = 60.0 while True: if (p.getMillis() - stamp > (1/fRate) * 1000): sceneManager.update() p.show() stamp = p.getMillis()
def on_button1(self): if self.shown: Logger.log_debug("WelcomScene.on_button1") SceneManager.get_instance().show_scene("select_mode") return True return False
def on_button2(self): if self.shown: Logger.log_debug("WelcomScene.on_button2") SceneManager.get_instance().show_scene("settings") return True return False
def _action_shutdown(self): Logger.log_info("Quit") SceneManager().get_instance().stop() os.system("sudo halt")
def _action_back(self): SceneManager.get_instance().show_main_scene()
from SceneManager import SceneManager from Camera import Camera from Exercise import Exercise from Menu import Menu # Define the managers, which handle the inputs and the scenes. This needs to be done before mostly everything sceneManager = SceneManager() # Create the necessary inputs camera = Camera() exerciseScene = Exercise([], sceneManager, camera) menuScene = Menu(sceneManager, camera) sceneManager.addScene(exerciseScene, "Exercise") sceneManager.addScene(menuScene, "Menu") sceneManager.setActiveScene("Exercise") # Main loop while True: sceneManager.update()
from Panel import Panel from Square import Square from Square import BouncingSquares import time import random from Disperse import Disperse from Scene import Scene from SceneManager import SceneManager from ImgSizer import ImgSizer from SinWave import SinWave from ColorLerp import ColorLerp from GifPlayer import GifPlayer p = Panel() sceneManager = SceneManager() # sceneManager.addScene(Scene(ColorLerp(0.05,p), 40)) # sceneManager.addScene(Scene(Disperse(10,p), 14, True)) # sceneManager.addScene(Scene(ImgSizer("tree.png", p), 25)) # sceneManager.addScene(Scene(Disperse(10,p), 14, True)) # sceneManager.addScene(Scene(ImgSizer("RoughDong.png", p), 10)) # sceneManager.addScene(Scene(Disperse(10,p), 14, True)) # sceneManager.addScene(Scene(ImgSizer("Mario.png", p), 30)) # sceneManager.addScene(Scene(Disperse(10,p), 14, True)) # sceneManager.addScene(Scene(SinWave(p), 35)) # sceneManager.addScene(Scene(Disperse(10,p), 30, True)) # sceneManager.addScene(Scene(BouncingSquares(4,4,10,p), 30)) # sceneManager.addScene(Scene(Disperse(10,p), 14, True)) # sceneManager.addScene(Scene(BouncingSquares(3,3,20,p), 30)) # sceneManager.addScene(Scene(Disperse(10,p), 14, True)) # sceneManager.addScene(Scene(BouncingSquares(1,1,200,p), 30)) # sceneManager.addScene(Scene(Disperse(10,p), 14, True))
if __name__ == "__main__": Strings.get_instance().load(ResourceManager.get( Config.get("strings_file"))) camera = Camera() arduino = Arduino() Screen.get_instance().init(camera) try: camera.start() arduino.start() try: arduino.register_callback(Arduino.BUTTON_3, quit, Config.get("halt_delay")) sm = SceneManager().get_instance() sm.add_scene(WelcomeScene(arduino)) sm.add_scene(SettingsScene(arduino)) sm.add_scene(SelectModeScene(arduino)) sm.add_scene(SnapScene(arduino, camera)) sm.add_scene(SnapPhotomatonScene()) sm.add_scene(SnapSpecialScene(arduino, camera)) sm.add_scene(SelectEffectScene(arduino)) sm.set_main_scene("welcome") sm.start() finally: arduino.stop() arduino.close() camera.stop() finally: Screen.get_instance().close()
def quit(): Logger.log_info("Quit") SceneManager().get_instance().stop() return True
# create window window = pyglet.window.Window(WIDTH,HEIGHT, vsync=not DEBUG, style=pyglet.window.Window.WINDOW_STYLE_BORDERLESS, ) window.set_caption(GAMENAME) # create physics space space = pymunk.Space() space.damping = .6 if DEBUG: debugDrawOptions = pyglet_util.DrawOptions() # start managers inputManager = InputManager(key,mouse) sceneManager = SceneManager() #TODO audioManager objectManager = ObjectManager() # create scenes gameScene = GameScene(objectManager, inputManager, space, WIDTH, HEIGHT) mainMenuScene = MainMenuScene(window, inputManager, lambda:sceneManager.changeScene(gameScene)) # switch to main menu scene sceneManager.changeScene(gameScene) # debug if DEBUG: print("pyglet version: "+str(pyglet.version)) print("pymunk version: "+str(pymunk.version)) print("vsync: "+str(window.vsync))
class Application: def __init__(self): self._running = False self.target_fps = 60 self.clock = pg.time.Clock() self.scene_manager = SceneManager() self.scene_manager.update_window_size(WIDTH, HEIGHT) self.scene_manager.retarget_drawing(pg.display.get_surface()) self.scene_manager.begin(GameScene) def run(self): self._running = True while (self._running): self.events() self.update() self.draw() self.clock.tick(self.target_fps) print("\nfps:" + str(self.clock.get_fps())) def events(self): self.scene_manager.update_keys(pg.key.get_pressed()) self.scene_manager.update_buttons(pg.mouse.get_pressed()) self.scene_manager.update_mouse(pg.mouse.get_pos()) for ev in pg.event.get(): if ev.type == pg.QUIT: self.stop() def update(self): if not self.scene_manager.scene: self.stop() return self.scene_manager.update() def draw(self): self.scene_manager.draw() pg.display.flip() def stop(self): self._running = False
def _snap_simple(self): SceneManager.get_instance().show_scene("snap")
def _snap_photomaton(self): SceneManager.get_instance().show_scene("photomaton")
def _snap_special(self): SceneManager.get_instance().show_scene("select_effect")
def _effect(self, overlay): SceneManager.get_instance().show_scene("snap_special", overlay)
def main(): global window global scene global hud global camera global mousex global mousey global action global frametimer global SceneMgr global SceneMstr global Signals global speed speed = 10.0 RequestManager.set_time_budget(10) GlobalSettings.set('snapshot',False) #define the scenemaster object for the main scene SceneMstr = SceneMaster('Main Scene') #create the camera object & attach to scenemaster camera = CameraObj() SceneMstr.camera = camera #to be replaced by a setter function #define the scene manager for the switching between main scene and fbos SceneMgr = SceneManager(128,camera) #initialise the globals for mouse control mousex = 0 mousey = 0 action = 'NONE' #init the timer object frametimer = UtilTimer(20) #init the graphic system and create a window glutInit(sys.argv) # Select type of Display mode: double buffer,RGBA color,Alpha components supported , Depth buffer glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) # get a 640 x 480 window glutInitWindowSize(1024, 800) # the window starts at the upper left corner of the screen glutInitWindowPosition(0, 0) window = glutCreateWindow("GL Planet") print(glGetIntegerv(GL_DEPTH_BITS)) # Register the drawing function with glut, BUT in Python land, at least using PyOpenGL, we need to # set the function pointer and invoke a function to actually register the callback, otherwise it # would be very much like the C version of the code. glutDisplayFunc(DrawGLScene) # Uncomment this line to get full screen. #glutFullScreen() # When we are doing nothing, redraw the scene. glutIdleFunc(DrawGLScene) # Register the function called when our window is resized. glutReshapeFunc(ReSizeGLScene) #registra la funzione per il mouse glutMouseFunc(MouseButton) glutMotionFunc(MouseMove) # Register the function called when the keyboard is pressed. glutKeyboardFunc(keyPressed) # Initialize our window. InitGL(SceneMgr, 800, 480) #create the HUD object & attach to scenemaster hud = HUDObject() SceneMstr.hud = hud #to be replaced by a setter function #DEBUG: register some measurements Signals = {} r1 = ReadableSignal('update time: ',0,10) r2 = ReadableSignal('draw time: ',0,10) hud.registersignal(r1) hud.registersignal(r2) Signals['update'] = r1 Signals['draw'] = r2 #planet_texture = loadTexture('Media/Textures/Planet2.png') SceneUtils = {} SceneUtils['fbo'] = SceneMgr SceneUtils['hud'] = hud SceneUtils['cam'] = camera #initialise materials MaterialManager.load_material('Media/Materials/heightmat1.glsv', 'Media/Materials/heightmat1.glsf', 'fbomatheight') MaterialManager.load_material('Media/Materials/terra_v1.glsv','Media/Materials/terra_v1.glsf','planetmat1') MaterialManager.load_material('Media/Materials/normmat2.glsv','Media/Materials/normmat2.glsf','fbomatnorm') MaterialManager.load_material('Media/Materials/ocean_v1.glsv','Media/Materials/ocean_v1.glsf','planetsea') MaterialManager.load_material('Media/Materials/surfmeasure.glsv','Media/Materials/surfmeasure.glsf','surfacemeasure') MaterialManager.load_material('Media/Materials/sky_int_v1.glsv','Media/Materials/sky_int_v1.glsf','skybox_inside') MaterialManager.load_material('Media/Materials/underwater_v1.glsv','Media/Materials/underwater_v1.glsf','underwater') GlobalSettings.set('nosea',True) #create the planet descriptor P1 = PlanetDescriptor('Primum',10000.0,30.0, 0.2,'fbomatheight','fbomatnorm','planetmat1') #P1.GenerateTexture() # create the cube & attach to scenemaster # TO CHANGE: all various methods to attach things to the rendcubevbo object camera, scenemgr, materialmgr, to be # replaced by a SceneMaster pointer scene = RenderablePlanet.RenderablePlanet('facevbo',0,0,-1500,SceneUtils,P1) SceneMstr.drawables.append(scene) # to be replaced by a setter in scenemaster scene.Timer = frametimer # Start Event Processing Engine glutMainLoop()