예제 #1
0
def on_key_press(symbol, modifiers):
    global evolving, fps_limit, grid, show_help
    if show_help:
        show_help = False
        return

    if symbol == key.H:
        # show help screen
        show_help = True
    if symbol == key.SPACE:
        # toggle evolving
        evolving = not evolving
    if symbol == key.R:
        # reseed grid
        seed_grid()
    if symbol == key.C:
        # clear grid
        grid = [[(0,0)]*50 for i in range(50)]
    if symbol == key.UP:
        fps_limit += 2
        if fps_limit > 40: fps_limit = 40
        clock.set_fps_limit(fps_limit)
    if symbol == key.DOWN:
        fps_limit -= 2
        if fps_limit < 2: fps_limit = 2
        clock.set_fps_limit(fps_limit)
 def __init__(self, input_file_path):
     self.window = Window(1200,
                          800,
                          input_file_path,
                          title='OpenGL Micromegas Event Viewer')
     clock.set_fps_limit(60)
     pyglet.app.run()
예제 #3
0
def instructionScreen(windowSurface, WWIDTH, FRAMES, background_image, background_position):

    while True:

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        windowSurface.blit(background_image, background_position)
        
        displayText(windowSurface, 128, WWIDTH / 2, 125, 'MEGA', RED)
        displayText(windowSurface, 128, WWIDTH / 2, 275, 'JUMP!', GREEN)
        displayText(windowSurface, 20, WWIDTH / 2, 400, 'Space to jump (+ down arrow for small jump, M for MegaJump)', GREEN)
        displayText(windowSurface, 20, WWIDTH / 2, 450, 'Left & Right arrows to move (+ up arrow to move faster)', GREEN)
        displayText(windowSurface, 20, WWIDTH / 2, 500, 'Q to quit, R to reset', GREEN)
        displayText(windowSurface, 20, WWIDTH / 2, 550, 'Only 1 MegaJump per game!', RED)
        displayText(windowSurface, 20, WWIDTH / 2, 600, 'Press ESC to return to main screen', GREEN)

        pygame.draw.circle(windowSurface, GOLD, (510, 550), 10, 0)

        if pygame.key.get_pressed()[K_ESCAPE]:
            return

        pygame.display.flip()

        clock.set_fps_limit(FRAMES)
        clock.tick()
    def test_sprite(self):
        w = pyglet.window.Window(width=320, height=320)

        image = Image2d.load(ball_png)
        ball1 = BouncySprite(0, 0, 64, 64, image, properties=dict(dx=10, dy=5))
        ball2 = BouncySprite(288,
                             0,
                             64,
                             64,
                             image,
                             properties=dict(dx=-10, dy=5))
        view = FlatView(0, 0, 320, 320, sprites=[ball1, ball2])
        view.fx, view.fy = 160, 160

        clock.set_fps_limit(60)
        e = TintEffect((.5, 1, .5, 1))
        while not w.has_exit:
            clock.tick()
            w.dispatch_events()

            ball1.update()
            ball2.update()
            if ball1.overlaps(ball2):
                if 'overlap' not in ball2.properties:
                    ball2.properties['overlap'] = e
                    ball2.add_effect(e)
            elif 'overlap' in ball2.properties:
                ball2.remove_effect(e)
                del ball2.properties['overlap']

            view.clear()
            view.draw()
            w.flip()

        w.close()
예제 #5
0
def main():
    win = pyglet.window.Window( width=800, height=600 )

    anims = []

    @win.event
    def on_key_press(symbol, modifiers):
        #print 'Flipping', anims
        for anim in anims:
            anim.flip()

    anims.append( Anim('subWalkNorm', 5) )
    anims.append( BeerThrowAnim() )

    while not win.has_exit:
        done = False
        clock.set_fps_limit(FRAMES_PER_SECOND)

        while not done:
            timeChange = clock.tick()

            win.dispatch_events()
            for anim in anims:
                anim.update( timeChange )

            win.clear()
            if done or win.has_exit:
                break

            for anim in anims:
                anim.draw()

            win.flip()
예제 #6
0
 def __init__(self, config):
     super().__init__(config=config,
                      width=self.WINDOW_WIDTH,
                      height=self.WINDOW_HEIGHT,
                      visible=False)
     self.background_colour = tuple(self.BACKGROUND_RGB * 4)
     self.img_base = ImageBase()
     self.card_width, self.card_height = self.WINDOW_WIDTH / 12, self.WINDOW_HEIGHT / 4
     self.cards = []
     self.btn_width, self.btn_height = self.WINDOW_WIDTH / 10, self.WINDOW_HEIGHT / 8
     self.set_location(200, 30)
     self.btn_tints = [255, 255, 255, 255, 255, 255]
     if random.random() < .1:
         self.ACTIONS.append("nice")
     self.card_paddding = self.card_width / 4
     self.background_batch = pyglet.graphics.Batch()
     self.background_batch.add(
         4, pyglet.gl.GL_QUADS, None,
         ('v2i',
          (0, 0, self.width, 0, self.width, self.height, 0, self.height)),
         ('c3B', self.background_colour))
     self.batch = pyglet.graphics.Batch()
     self.btns = []
     self.model = Mod.Model(self)
     clock.set_fps_limit(1.0 / 60)
     pyglet.clock.schedule_interval(self.tick, 1.0 / 60)
     self.txt, self.money_lbl, self.lbl = "", None, None
     self.notify("Welcome to BlackJack!")
     self.update_frame()
     self.set_visible(True)
     if self.MUSIC_ON:
         self.play_music()
예제 #7
0
    def __init__(self, window):
        self.win = window
        self.world = World()
        self.camera = Camera(self.win, zoom=100.0)
        self.hud = Hud(self.win)

        clock.set_fps_limit(settings.WINDOW['framerate'])
예제 #8
0
 def __init__(self, *args, **kwargs):
   super(MainWindow, self).__init__(*args, **kwargs)
   self.keys = window.key.KeyStateHandler()
   self.push_handlers(self.keys)
   # self.set_exclusive_mouse()
   self.width, self.height, self.rat3d, self.ratex = 640, 480, 1.05, 0.5
   self.zoom, self.expand, self.mapping, self.blend = 0, 0, 0, 1
   self.fgc, self.bgc = (1.0, 1.0, 1.0, 0.9), (0.1, 0.1, 0.1, 0.1)
   self.loadfgc, self.loadbgc = (0.4, 0.2, 0.4, 0.3), (0.6, 0.3, 0.6, 0.9)
   self.instfgc, self.instbgc = (0.1, 0.1, 0.5, 0.9), (0.5, 0.9, 0.9, 0.8)
   self.instbkwidth, self.instbkheight = 480, 400
   bmplen = (self.instbkwidth / 8) * self.instbkheight
   self.instbkbmp = (ctypes.c_ubyte * bmplen)(*([255] * bmplen))
   self.ticktimer, self.tick, self.insttimer, self.inst = 0.5, 0.0, 30, 1
   self.printing, self.solver = 1, deque()
   self.stat = [None, 0, Queue.Queue(512)] # (key(1-9), direc), count, queue
   self.cmax, self.tanim = 18, [6, 3, 1, 3] # frames in rotate moving, speeds
   self.tcos, self.tsin = [1.0] * (self.cmax + 1), [0.0] * (self.cmax + 1)
   for i in xrange(1, self.cmax):
     t = i * math.pi / (2.0 * self.cmax) # 0 < t < pi/2
     self.tcos[i], self.tsin[i] = math.cos(t), math.sin(t)
   self.tcos[self.cmax], self.tsin[self.cmax] = 0.0, 1.0 # pi/2 regulation
   self.InitRot()
   self.InitAxis()
   self.InitGL(self.width, self.height)
   self.textures = [None] * (len(self.ary_norm) * 2 + 1 + len(TEXIMG_CHAR))
   self.loading, self.dat = 0, [('', 0, 0)] * len(self.textures)
   resource.add_font(FONT_FILE)
   self.font = font.load(FONT_FACE, 20)
   self.fontcolor = (0.5, 0.8, 0.5, 0.9)
   self.fps_display = clock.ClockDisplay(font=self.font, color=self.fontcolor)
   self.fps_pos = (-60.0, 30.0, -60.0)
   clock.set_fps_limit(60)
   clock.schedule_interval(self.update, 1.0 / 60.0)
예제 #9
0
def main():
    win = pyglet.window.Window(width=800, height=600)

    anims = []

    @win.event
    def on_key_press(symbol, modifiers):
        #print 'Flipping', anims
        for anim in anims:
            anim.flip()

    anims.append(Anim('subWalkNorm', 5))
    anims.append(BeerThrowAnim())

    while not win.has_exit:
        done = False
        clock.set_fps_limit(FRAMES_PER_SECOND)

        while not done:
            timeChange = clock.tick()

            win.dispatch_events()
            for anim in anims:
                anim.update(timeChange)

            win.clear()
            if done or win.has_exit:
                break

            for anim in anims:
                anim.draw()

            win.flip()
예제 #10
0
    def test_sprite(self):
        w = pyglet.window.Window(width=320, height=320)

        image = Image2d.load(ball_png)
        ball1 = BouncySprite(0, 0, 64, 64, image, properties=dict(dx=10, dy=5))
        ball2 = BouncySprite(288, 0, 64, 64, image, properties=dict(dx=-10, dy=5))
        view = FlatView(0, 0, 320, 320, sprites=[ball1, ball2])
        view.fx, view.fy = 160, 160

        clock.set_fps_limit(60)
        e = TintEffect((0.5, 1, 0.5, 1))
        while not w.has_exit:
            clock.tick()
            w.dispatch_events()

            ball1.update()
            ball2.update()
            if ball1.overlaps(ball2):
                if "overlap" not in ball2.properties:
                    ball2.properties["overlap"] = e
                    ball2.add_effect(e)
            elif "overlap" in ball2.properties:
                ball2.remove_effect(e)
                del ball2.properties["overlap"]

            view.clear()
            view.draw()
            w.flip()

        w.close()
예제 #11
0
파일: pygland.py 프로젝트: msarch/py
    def __init__(self):
        pyglet.window.Window.__init__(self, vsync=True, fullscreen=True)
        self.set_mouse_visible(False)
        self.bgcolor = bgcolor
        self.size_x, self.size_y = self.get_display_size()
        self.center = self.size_x * 0.5, self.size_y * 0.5
        self.paused = False
        self.camera = Camera((self.center), 0.1)
        self.key_actions = {
            key.ESCAPE: lambda: exit(),
            key.PAGEUP: lambda: self.camera.zoom(2),
            key.PAGEDOWN: lambda: self.camera.zoom(0.5),
            key.LEFT: lambda: self.camera.pan(self.camera.scale, -1.5708),
            key.RIGHT: lambda: self.camera.pan(self.camera.scale, 1.5708),
            key.DOWN: lambda: self.camera.pan(self.camera.scale, 3.1416),
            key.UP: lambda: self.camera.pan(self.camera.scale, 0),
            key.COMMA: lambda: self.camera.tilt(-1),
            key.PERIOD: lambda: self.camera.tilt(+1),
            key.P: lambda: self.toggle_pause(),
        }

        self.gl_setup()
        # schedule the update function at 'fps' times per second
        clock.schedule_interval(self.update, 1.0 / 100.0)
        clock.set_fps_limit(max_fps)
예제 #12
0
def on_key_press(symbol, modifiers):
    global evolving, fps_limit, grid, show_help
    if show_help:
        show_help = False
        return

    if symbol == key.H:
        # show help screen
        show_help = True
    if symbol == key.SPACE:
        # toggle evolving
        evolving = not evolving
    if symbol == key.R:
        # reseed grid
        seed_grid()
    if symbol == key.C:
        # clear grid
        grid = [[(0, 0)] * 50 for i in range(50)]
    if symbol == key.UP:
        fps_limit += 2
        if fps_limit > 40: fps_limit = 40
        clock.set_fps_limit(fps_limit)
    if symbol == key.DOWN:
        fps_limit -= 2
        if fps_limit < 2: fps_limit = 2
        clock.set_fps_limit(fps_limit)
예제 #13
0
    def test_sprite(self):
        w = pyglet.window.Window(width=320, height=320)

        image = Image2d.load(ball_png)
        ball = Sprite(0, 0, 64, 64, image)
        view = FlatView(0, 0, 320, 320, sprites=[ball])

        w.push_handlers(view.camera)

        dx, dy = (10, 5)

        clock.set_fps_limit(30)
        while not w.has_exit:
            clock.tick()
            w.dispatch_events()

            # move, check bounds
            ball.x += dx; ball.y += dy
            if ball.left < 0: ball.left = 0; dx = -dx
            elif ball.right > w.width: ball.right = w.width; dx = -dx
            if ball.bottom < 0: ball.bottom = 0; dy = -dy
            elif ball.top > w.height: ball.top = w.height; dy = -dy

            # keep our focus in the middle of the window
            view.fx = w.width/2
            view.fy = w.height/2

            view.clear()
            view.draw()
            w.flip()

        w.close()
예제 #14
0
파일: application.py 프로젝트: naymen/MELA
    def __init__(self, fullscreen=False,
                 screen=None,
                 width=None, height=None,
                 visible=False, vsync=False, fps=60,
                 show_fps=False):
        platform = get_platform()
        display = platform.get_default_display()
        screens = display.get_screens()
        screen=screens[screen]
        self.window = MyWindow(fullscreen=fullscreen, screen=screen,
            width=width, height=height, visible=visible,
            vsync=vsync
        )
        # glClearColor(0., 0., 0., 0.0)
        # glEnable(GL_BLEND)
        # glEnable(GL_LINE_SMOOTH)
        # glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        self.clockDisplay = clock.ClockDisplay(color=(1., 1., 1., .8)) if show_fps \
                            else None
        self.paused = False
        clock.set_fps_limit(fps)

        self.window.on_draw = self.on_draw
        self.window.on_key_press = self.on_key_press
        self.window.on_mouse_drag = self.on_mouse_drag
        self.window.on_mouse_press = self.on_mouse_press
예제 #15
0
    def test_limit_fps(self):
        """
        Test that the clock effectively limits the
        frames per second to 60 Hz when set to.

        Because the fps are bounded, we expect a small error (1%)
        from the expected value.
        """
        ticks = 20
        fps_limit = 60
        expected_delta_time = ticks*1./fps_limit

        clock.set_fps_limit(fps_limit)

        t1 = time.time()
        # Initializes the timer state.
        clock.tick()
        for i in range(ticks):
            clock.tick()
        t2 = time.time()

        computed_time_delta = t2 - t1

        self.assertAlmostEqual(computed_time_delta,
                               expected_delta_time,
                               delta=0.01*expected_delta_time)
예제 #16
0
파일: pygland.py 프로젝트: msarch/py
    def __init__(self):
        pyglet.window.Window.__init__(self,vsync = True,fullscreen=True)
        self.set_mouse_visible(False)
        self.bgcolor=bgcolor
        self.size_x,self.size_y=self.get_display_size()
        self.center= self.size_x*0.5,self.size_y*0.5
        self.paused=False
        self.camera=Camera((self.center), 0.1)
        self.key_actions = {
            key.ESCAPE: lambda: exit(),
            key.PAGEUP: lambda: self.camera.zoom(2),
            key.PAGEDOWN: lambda: self.camera.zoom(0.5),
            key.LEFT: lambda: self.camera.pan(self.camera.scale, -1.5708),
            key.RIGHT: lambda: self.camera.pan(self.camera.scale, 1.5708),
            key.DOWN: lambda: self.camera.pan(self.camera.scale, 3.1416),
            key.UP: lambda: self.camera.pan(self.camera.scale, 0),
            key.COMMA: lambda: self.camera.tilt(-1),
            key.PERIOD: lambda: self.camera.tilt(+1),
            key.P : lambda: self.toggle_pause(),
            }


        self.gl_setup()
        # schedule the update function at 'fps' times per second
        clock.schedule_interval(self.update, 1.0/100.0)
        clock.set_fps_limit(max_fps)
예제 #17
0
파일: lesson2.py 프로젝트: msarch/py
    def __init__(self):
        clock.set_fps_limit(35)
        self.time = 0

        self.window = snowui.Window((800,600))
        # snowui.GUI is a Widget just like anything else; so it can have a
        # texture just like anything else!
        self.gui = snowui.GUI(texture="data/bg.png")
        self.window.push_handlers(self.gui)

        # This is a nice gradient that we put over our game. We won't in this
        # tutorial but we could do some pretty cool fading stuff with it to
        # change the mood of the game. (such as for levels)
        self.bg_overlay = rabbyt.Sprite("data/bg_overlay.png")
        self.bg_overlay.left = 0
        self.bg_overlay.bottom = 0
        self.bg_overlay.rgba = 0,.7,1,.1

        # snowui has a pre-made Button class because it is so common. It also
        # makes a really good example for how to extend the Widget to do what
        # you want it to do.
        quit_button = snowui.Button(texture="data/exit_button.png",
                rx=5, ry=5,
                default_color=(1,1,1,.7),
                hover_color=(.7,0,0,1),
                callback=sys.exit)
        self.gui.add(quit_button)

        # Notice that we aren't using the snowui Button but our own. It is at
        # the bottom of this tutorial and you'll see how cool it is down there.
        restart_button = RestartButton(texture="data/restart_button.png",
                rx=75, ry=24,
                default_color=(1,1,1,.7),
                hover_color=(0,1,0,1),
                shape=(-20,20,20,-20),
                bounds="rect",
                callback=self.restart_game)
        self.gui.add(restart_button)
        # If you are unsure how all this works take a look at the Button class
        # in snowui/button.py

        # And now for our Happy Glacier icon. If you haven't seen arctic paint
        # you need to check it out at arcticpaint.com! Chance are you got this
        # tutorial from there though.
        hg_icon = snowui.Button(texture="data/hg_icon.png",
                rx=800-89, ry=600-46,
                hover_color=(.7,.7,1,1),
                fade_time=.1,
                bounds="rect")
        self.gui.add(hg_icon)

        # Here is where we store the running game. The Game keeps track of all
        # the gems on the playing field and functions for moving them around and
        # junk like that. You'll see soon.
        self.game = Game(self)

        self.selected_gem = None
        self.selection_marker = rabbyt.Sprite("data/selection_marker.png")
        self.selection_marker.alpha = 0
예제 #18
0
 def main_loop(self):
     clock.set_fps_limit(self.update_fps)
     while not self.has_exit:
         self.dispatch_events()
         self.update_cells()
         self.draw_grid()
         clock.tick()
         self.flip()
예제 #19
0
 def main_loop(self):
     clock.set_fps_limit(self.update_fps)
     while not self.has_exit:
         self.dispatch_events()
         self.update_cells()
         self.draw_grid()
         clock.tick()
         self.flip()
예제 #20
0
파일: main.py 프로젝트: LtnPjk/pyPong
def main():
    @window.event
    def on_draw():
        draw()

    dt = clock.tick()
    pyglet.clock.schedule_interval(update, 1 / 100)
    clock.set_fps_limit(60)
    pyglet.app.run()
예제 #21
0
 def _update_flags(self):
     """Update OpenGL state based on the current flags.
     """
     clock.set_fps_limit(self._animate_rate)
     glLineWidth(float(self._line_width))
     clock.unschedule(SceneViewer.time_event)
     if self._flags['animate'] or self._flags['record']:
         clock.schedule_interval(SceneViewer.time_event,
                                 1.0 / self._animate_rate, self)
예제 #22
0
    def __init__(self):
        self.world = World()
        self.win = window.Window(fullscreen=False, vsync=True, width=window_dimensions[0], height=window_dimensions[1])
        self.camera = Camera(self.win, zoom=200.0)
        self.hud = Hud(self.win)


        self.win.push_handlers(self.world.player.key_handler)

        clock.set_fps_limit(60)
예제 #23
0
def networkScreen1(windowSurface, WWIDTH, FRAMES, background_image,
                   background_position, role):

    time.sleep(0.3)

    while True:

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        windowSurface.blit(background_image, background_position)

        if role != "solo":
            displayText(windowSurface, 16, WWIDTH - 75, 25, 'Network Mode',
                        GOLD)

        displayText(windowSurface, 128, WWIDTH / 2, 125, 'MEGA', RED)
        displayText(windowSurface, 128, WWIDTH / 2, 275, 'JUMP!', GREEN)
        displayText(windowSurface, 24, WWIDTH / 2, 400, 'Network Play:', GREEN)
        displayText(windowSurface, 24, WWIDTH / 2, 450, '1 = Host Game', GREEN)
        displayText(windowSurface, 24, WWIDTH / 2, 500, '2 = Connect to Game',
                    GREEN)
        displayText(windowSurface, 24, WWIDTH / 2, 550,
                    '3 = Exit Network Mode', GREEN)
        displayText(windowSurface, 20, WWIDTH / 2, 620,
                    'Press Esc to Return to Main Menu', RED)

        if pygame.key.get_pressed()[ord('1')]:
            clientSocket = setupServer(windowSurface, background_image,
                                       background_position)
            if clientSocket:
                role = "server"
            else:
                role = "solo"
            return role, clientSocket
        if pygame.key.get_pressed()[ord('2')]:
            serverSocket = setupClient(windowSurface, background_image,
                                       background_position)
            if serverSocket:
                role = "client"
            else:
                role = "solo"
            return role, serverSocket
        if pygame.key.get_pressed()[ord('3')]:
            role = "solo"
            return role, ''
        if pygame.key.get_pressed()[K_ESCAPE]:
            return role, ''

        pygame.display.flip()

        clock.set_fps_limit(FRAMES)
        clock.tick()
예제 #24
0
파일: app.py 프로젝트: jon1012/babytux
    def __init__(self):
        self.world = World()
        self.win = pyglet.window.Window(fullscreen=True, vsync=True)

        for i in dir(self):
            if i.startswith('on_'):
                setattr(self.win, i, getattr(self, i))

        self.camera = Camera(self.win, zoom=100.0)
        self.hud = Hud(self.win)
        clock.set_fps_limit(60)
예제 #25
0
    def test_fps_limit(self):
        clock.set_default(clock.Clock())
        clock.set_fps_limit(20)
        self.assertTrue(clock.get_fps() == 0)

        t1 = time.time()
        clock.tick()  # One to get it going
        for i in range(20):
            clock.tick()
        t2 = time.time()
        self.assertTrue(abs((t2 - t1) - 1.) < 0.05)
예제 #26
0
    def __init__(self):
        self.world = World()
        self.win = window.Window(fullscreen=False, vsync=True, resizable=True)

        self.network = Network(self.world.cube.update_quat)
        self.camera = Camera(self.win, z=4)
        self.hud = Hud()

        self.init_gl()

        clock.set_fps_limit(60)
예제 #27
0
    def __init__(self):
        self.win = pyglet.window.Window(resizable=True, vsync=True)
        self.camera = Camera(self.win, zoom=10)
        self.setup_GL()
        self._setup_win_handlers()

        self.network = Network()
        self.world = World(self.network)
        self.hud = Hud(self)

        clock.set_fps_limit(60)
예제 #28
0
    def __init__(self):
        self.win = pyglet.window.Window(resizable=True, vsync=True)
        self.camera = Camera(self.win, zoom=10)
        self.setup_GL()
        self._setup_win_handlers()

        self.network = Network()
        self.world = World(self.network)
        self.hud = Hud(self)

        clock.set_fps_limit(60)
예제 #29
0
    def test_fps_limit(self):
        clock.set_default(clock.Clock())
        clock.set_fps_limit(20)
        self.assertTrue(clock.get_fps() == 0)

        t1 = time.time()
        clock.tick() # One to get it going
        for i in range(20):
            clock.tick()
        t2 = time.time()
        self.assertTrue(abs((t2 - t1) - 1.) < 0.05)
예제 #30
0
    def test_multisample(self):
        self.set_window()
        self.angle = 0
        clock.set_fps_limit(30)
        while not self.win.has_exit:
            dt = clock.tick()
            self.angle += dt

            self.render()
            self.win.flip()
            self.win.dispatch_events()
        self.win.close()
 def test_multisample(self):
     self.set_window()
     self.angle = 0
     clock.set_fps_limit(30)
     while not self.win.has_exit:
         dt = clock.tick()
         self.angle += dt
         
         self.render()
         self.win.flip()
         self.win.dispatch_events()
     self.win.close()
예제 #32
0
def savedGameScreen(savedGames, windowSurface, WWIDTH, WHEIGHT, FRAMES, background_image, background_position):        

    time.sleep(0.3)
    
    while True:

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        windowSurface.blit(background_image, background_position)
        displayTextLJ(windowSurface, 36, 50, 50, 'Saved Games List', RED)
        displayTextLJ(windowSurface, 24, 50, 100, "Name", RED)
        displayTextLJ(windowSurface, 24, 200, 100, "Difficulty", RED)
        displayTextLJ(windowSurface, 24, 350, 100, "Platforms", RED)
        displayTextLJ(windowSurface, 24, 500, 100, "Record", RED)
        
        displayTextLJ(windowSurface, 20, 50, 550, 'Press number to select game or D plus number to delete game', RED)
        displayTextLJ(windowSurface, 20, 50, 600, 'Escape to return to previous screen', RED)
        
        count = 1
        for game in savedGames:
            displayTextLJ(windowSurface, 20, 50, 100 + (count * 30), str(count) + ". " + game['name'], GREEN)
            displayTextLJ(windowSurface, 20, 200, 100 + (count * 30), game['difficulty'], GREEN)
            displayTextLJ(windowSurface, 20, 350, 100 + (count * 30), game['pnumber'], GREEN)
            if game['difficulty'] == "INSANE":
                displayTextLJ(windowSurface, 20, 500, 100 + (count * 30), "Score: " + game['score'], GREEN)
            else:
                displayTime(windowSurface, int(game['record']), 500, 100 + (count * 30), GREEN, 20, "True")
            count += 1

        if not pygame.key.get_pressed()[ord('d')]:
            for i in range(len(savedGames)):
                if pygame.key.get_pressed()[ord(str(i+1))]:
                    return savedGames[i], i

        if pygame.key.get_pressed()[ord('d')]:
            for i in range(len(savedGames)):
                if pygame.key.get_pressed()[ord(str(i+1))]:
                     del savedGames[i]
                     saveGames(windowSurface, WWIDTH, WHEIGHT, None, savedGames, None, "Delete")
                     time.sleep(0.5)
                     break
                       
        if pygame.key.get_pressed()[K_ESCAPE]:
            return None, None

        pygame.display.flip()

        clock.set_fps_limit(FRAMES)
        clock.tick()
예제 #33
0
    def __init__(self):
        clock.set_fps_limit(fps)
        self.fps_display = clock.ClockDisplay()

        config = pyglet.gl.Config(double_buffer=True)

        pyglet.window.Window.__init__(self, width=window_width, height=window_height, config=config)
        self.batch_draw = pyglet.graphics.Batch()
        x = image_spacing
        y = window_height - 5*(image_size+image_spacing)
        self.square = SquareImage(self.batch_draw, x, y, image_size)
        self.run = False
        self.schedule = pyglet.clock.schedule_interval(func=self.update, interval=1/float(fps*2))
예제 #34
0
 def __init__(self, wIn, hIn, pX, pY):
     self.world = World(pX, pY)
     self.win = window.Window(width=wIn,
                              height=hIn,
                              fullscreen=False,
                              vsync=True)
     self.camera = Camera(self.win, zoom=pX * 5 + 1)
     self.hud = Hud(self.win)
     self.pX = pX
     self.pY = pY
     clock.set_fps_limit(30)
     for x in range(0, pX):
         for y in range(0, pY):
             self.world.addEntity(x, pY - y - 1, pX, pY)
 def run_test(self):
     clock.set_fps_limit(30)
     while not self.w.has_exit:
         clock.tick()
         self.w.dispatch_events()
         self.view.fx += (self.keyboard[key.RIGHT] - self.keyboard[key.LEFT]) * 5
         self.view.fy += (self.keyboard[key.UP] - self.keyboard[key.DOWN]) * 5
         if self.marker is not None:
             self.marker.x = self.view.fx
             self.marker.y = self.view.fy
         self.view.clear()
         self.view.draw()
         self.w.flip()
     self.w.close()
예제 #36
0
 def main_loop(self):
     clock.set_fps_limit(30)
     clock.schedule_interval(self.animate_bird, 0.01)
     
     while not self.has_exit:
         self.dispatch_events()
         self.clear()
     
         self.update()
         self.draw()
     
         #Tick the clock
         clock.tick()
         self.flip()
예제 #37
0
def main():
	title_screen()
	setup_screen()
	join_screen()
	host_screen()
	game_screen()
	end_screen()

	manager.set_media(mp)
	manager.add_widget(my_bg)
	game_window.push_handlers(manager)
	#Pyglet Settings
	schedule_interval(update, 1/120.0)
	set_fps_limit(120)
	run()
    def test_multisample(self):
        self.set_window()
        try:
            self.angle = 0
            clock.set_fps_limit(30)
            while not self.win.has_exit:
                dt = clock.tick()
                self.angle += dt

                self.render()
                self.win.flip()
                self.win.dispatch_events()
        finally:
            self.win.close()
        self.user_verify('Pass test?', take_screenshot=False)
예제 #39
0
def main():
    title_screen()
    setup_screen()
    join_screen()
    host_screen()
    game_screen()
    end_screen()

    manager.set_media(mp)
    manager.add_widget(my_bg)
    game_window.push_handlers(manager)
    # Pyglet Settings
    schedule_interval(update, 1 / 120.0)
    set_fps_limit(120)
    run()
예제 #40
0
	def __init__(self):
		self.Width, self.Height = 640, 480
		self.Window = BannerWindow(self.Width, self.Height)
		self.Window.set_exclusive_mouse(False)
		self.Brlyt = None
		
		glClearColor(0.0, 0.0, 0.0, 0.0)
		glClearDepth(1.0)
		glDepthFunc(GL_LEQUAL)
		glEnable(GL_DEPTH_TEST)
		
		glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
		glEnable(GL_BLEND)
		
		glEnable(GL_TEXTURE_2D)
		
		clock.set_fps_limit(60)
예제 #41
0
    def __init__(self):
        self.Width, self.Height = 640, 480
        self.Window = BannerWindow(self.Width, self.Height)
        self.Window.set_exclusive_mouse(False)
        self.Brlyt = None

        glClearColor(0.0, 0.0, 0.0, 0.0)
        glClearDepth(1.0)
        glDepthFunc(GL_LEQUAL)
        glEnable(GL_DEPTH_TEST)

        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_BLEND)

        glEnable(GL_TEXTURE_2D)

        clock.set_fps_limit(60)
예제 #42
0
    def init(self, *args, **kwargs):
        # Setup a clock for frame rate
        clock.set_fps_limit(settings.FPS_LIMIT)
        # Setup updates to run once per tick
        if kwargs.get('noreset', True):
            clock.schedule(self.update)

        #---------------------------------------------------------
        # MENU.

        # set up a menu system. It is a hack.
        # don't let anyone else tell you otherwise.

        self.menubatch = pyglet.graphics.Batch()
        self.menugroup = pyglet.graphics.OrderedGroup(1)
        self.bggroup = pyglet.graphics.OrderedGroup(0)
        theme = kytten.Theme(fp('theme'))

        menu_choices = {
                'Play Game': self.remove_menu_load_level,
                'Help!'    : partial(show_help, self,
                                     self.menubatch, self.menugroup, theme),
                'Quit'     : pyglet.app.exit,
        }

        def on_select(choice):
            menu_choices.get(choice)()

        self.background = load(fp('background.png'))

        self.dialog = kytten.Dialog(
                kytten.TitleFrame("Altered Panda",
                    kytten.VerticalLayout([
                        kytten.Menu(options=[
                            "Play Game",
                            "Help!",
                            "Quit",],
                            on_select=on_select),
                    ])
                ),
                window=self, batch=self.menubatch,
                group=self.menugroup, anchor=kytten.ANCHOR_TOP_LEFT,
                theme=theme
        )
        self.do_draw = True
예제 #43
0
    def main_loop(self):
        clock.set_fps_limit(30)
        nodeSize = 5

        timer = 0
        while not self.has_exit:
            self.dispatch_events()
            self.clear()

            # White, so reset the colour
            glColor4f(1, 1, 1, 1)
            gl.glLineWidth(1)

            gl.glEnable(gl.GL_BLEND)
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

            glColor4f(0, 0, 0, 1.0)
            clock.tick()
예제 #44
0
 def run(self):
   clock.set_fps_limit(30)
   sim_time = 0.0
   real_time = 0.0
   frames_skipped = 0
   while not self.has_exit:
     real_time += clock.tick()
     self.dispatch_events()
     media.dispatch_events()
     draw = sim_time >= real_time
     if frames_skipped >= 1:
       draw = True
       frames_skipped = 0
       real_time = sim_time
     self.tick(draw)
     if not draw:
       frames_skipped += 1
     sim_time += 1 / 30.0
예제 #45
0
    def main_loop(self):
        #Create a font for our Steps label
        ft = font.load('Arial', 16)
        #The pyglet.font.Text object to display the steps
        steps_text = font.Text(ft, y=10, color=(1.0, 0.0, 0.0, 1.0))

        clock.set_fps_limit(60)

        while not self.has_exit:
            self.dispatch_events()

            self.move()
            self.draw()

            #Tick the clock
            clock.tick()
            #Show the number of steps performed by the ant
            steps_text.text = "Steps: %d" % self.steps
            steps_text.draw()
            self.flip()
예제 #46
0
def clientScreen(s, windowSurface, WWIDTH, FRAMES, background_image,
                 background_position):

    s.setblocking(0)
    serverDecision = ""

    while True:

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        pygame.event.pump()

        windowSurface.blit(background_image, background_position)

        displayTextLJ(windowSurface, 24, 50, 50,
                      "Waiting for host to start new game....", GREEN)
        displayTextLJ(windowSurface, 24, 50, 100,
                      "Press ESC to quit network mode", RED)

        pygame.display.flip()

        if pygame.key.get_pressed()[K_ESCAPE]:
            role = "solo"
            return role

        try:
            serverDecision = receiveData(s)
        except socket.error as err:
            pass

        if serverDecision == "Starting":
            role = "client"
            sendData(s, "Received")
            s.setblocking(1)
            return role

        clock.set_fps_limit(FRAMES)
        clock.tick()
예제 #47
0
    def loop(self):
        #limite les fps pour éviter de planter l'ordi :o
        clock.set_fps_limit(60)
        #variable pour compter les étapes
        steps = 0
        #on fait évoluer l'automate tant que l'user n'a pas cliqué sur la croix (exit)
        while not self.has_exit:
            self.dispatch_events()

            #on fait bouger la fourmi et on met a jour sa case
            self.cells[self.ant.y][self.ant.x] = not self.cells[self.ant.y][self.ant.x]
            self.ant.move(not self.cells[self.ant.y][self.ant.x])
            
            self.draw()
            #update la fenêtre
            self.flip()
            #update l'horloge
            clock.tick()
            #update le nombre d'étape + affichage
            steps += 1
            print steps
예제 #48
0
파일: breakout.py 프로젝트: joniz7/breakout
  def __init__(self, window):
    # Setup the world and the window
    self.world = b2World(gravity = (0,-10), doSleep=True)
    self.window = window
    self.keys = key.KeyStateHandler()
    self.window.push_handlers(self.keys)
    clock.set_fps_limit(60)

    self.drawables = []

    # Setup some physics parameters
    self.timeStep = 1.0/60
    self.vel_iters, self.pos_iters = 10, 10

    #Create the roof
    self.world.CreateStaticBody(
      position=pixelToMeter(self.window.width/2, self.window.height),
      shapes=b2PolygonShape(box=pixelToMeter(self.window.width/2, 1))
    )

    self.board = self.world.CreateKinematicBody(
        position=(15,11),
        shapes=b2PolygonShape(box=(10,1))
    )
    self.board.gravityScale = 0
    self.board.mass = 100

    # Define the ball
    body = self.world.CreateDynamicBody(
        position=(25.5,30)
      )
    body.CreatePolygonFixture(box=(1,1), density=1, friction=0.3, restitution=0.5)
    self.drawables.append(body)
    body.mass = 1
    body.angularVelocity = 1

    # Set up variables for dynamicall creating shapes
    self.tempPosList = []
    self.tempStartPos = (0,0)
예제 #49
0
    def init(self, name, version):
        clock.set_fps_limit(FPS_LIMIT)
        self.fps_display = clock.ClockDisplay()

        self.camera = Camera((0, 0), 800)
        self.renderer = Renderer(self.camera)
        caption = '%s v%s' % (name, version)
        self.window = Window(
            caption=caption, fullscreen=True, visible=False)
        self.window.on_key_press = on_key_press
        self.window.push_handlers(Keyboard.keystate)

        graphics = load_graphics()

        self.world = World()
        builder = LevelBuilder()
        seed(1)
        builder.build(self.world, 75, graphics)

        self.world.player = Player()
        self.world.player.add_to_space(self.world.space, (0, 200), 0)
        self.world.chunks.update(self.world.player.chunks)
예제 #50
0
파일: NewGame.py 프로젝트: lhorgan/miralens
 def __init__(self):
     clock.set_fps_limit(fps)
     self.fps_display = clock.ClockDisplay()
     monitor = Monitor(1080, 1920, 13.12, 23.43)
     image_size = monitor.mm_to_px(42)
     image_spacing = monitor.mm_to_px(3.175)
     rows = 4
     cols = 5
     window_width = (cols+1)*image_spacing+cols*image_size
     # extra row for fps display and sync sensor
     window_height = (rows+2)*image_spacing+(rows+1)*image_size
     pyglet.window.Window.__init__(self, width=window_width, height=window_height)
     self.batch_draw = pyglet.graphics.Batch()
     squares = []
     for i in range(rows + 1):
         for j in range(cols):
             x = image_spacing + (j) * (image_size + image_spacing)
             y = window_height - (i + 1) * (image_size + image_spacing)
             squares.append(SquareImage(self.batch_draw, x, y, image_size))
     self.squares = squares[0:20]
     self.squares.append(squares[-1])
     self.run = False
     self.schedule = pyglet.clock.schedule_interval(func=self.update, interval=1/float(fps*2))
예제 #51
0
    def run(self):
        self.done = False
        clock.set_fps_limit(40)
        win = window.window

        xPos = 0

        while not self.done:
            timeChange = clock.tick()
            events.ConsumeEventQueue()
            win.dispatch_events()
            for miscSprite in self.miscSprites:
                miscSprite.update(timeChange)

            win.clear()
            if self.done or win.has_exit:
                break

            glEnable(GL_BLEND)
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
            glColor4f(0.65, 0.65, 0.65, 1)

            if self.moving_bg:
                for count, bbg in enumerate(self.moving_bg):
                    bbg.blit(count * 800 + xPos, 0)

            glColor4f(1, 1, 1, 1)
            self.bg.blit(0,0)
            for miscSprite in self.miscSprites:
                miscSprite.draw()
            win.flip()

            xPos -= 1
            if xPos == -800:
                xPos = 0

        return self.getNextScene()
예제 #52
0
파일: app.py 프로젝트: mmilewski/pyWorm
    def __init__(self):
        vsync = config.IS_VSYNC

        if config.IS_FULLSCREEN:
            self.__window = window.Window(fullscreen=True, vsync=vsync)
        else:
            width, height = config.WIN_SIZE
            self.__window = window.Window(width=width, height=height, fullscreen=False, vsync=vsync)

        self.__winSize = winSize = (self.__window.width, self.__window.height)

        self.__camera = Camera(winSize)
        self.__hud = HUD(winSize)

        self.__inputManager = InputManager()
        self.__window.on_key_press = self.__inputManager.key_pressed
        self.__window.on_key_release = self.__inputManager.key_released

        if config.IS_FPS_LIMIT:
            clock.set_fps_limit(FPS_LIMIT)

        glDepthFunc(GL_LEQUAL)
        glEnable(GL_DEPTH_TEST)
        self.__world = GameWorld(self)  # to musi być na końcu
예제 #53
0
    def __init__(self, w=800, h=600):
        # leave initially invisible, load fonts, etc. then make visible.

        window.Window.__init__(self, visible=False)
        
        self.fps = clock.ClockDisplay() 

        self.big_font   = font_resource(FONT_NAME, size=24)
        self.small_font = font_resource(FONT_NAME, size=12)

        self.set_size(w, h)
        self.set_visible(True)
        clock.set_fps_limit(30)

        self.status_text = font.Text(self.small_font, '')
        self.status_text.y = self.height - self.status_text.height
        self.status_text.width = self.width

        # enable alpha-blending since some of our images are semi-transparent.
        # this must be done after creating the window (and really only once but
        # it doesn't matter if we have >1 window/view).

        glEnable(GL_BLEND) 
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) 
예제 #54
0
    def main_loop(self):
        clock.set_fps_limit(30)

        while not self.has_exit and not self._over:

            self.dispatch_events()
            self.update()
            self.clear()
            self.draw()

            # pymunk space update. updates position of all children.
            self.space.step(1/30.0)

            clock.tick()
            #Gets fps and draw it
            self.fps_label.text = "%d" % clock.get_fps()
            self.fps_label.draw()

            try:
                self.flip()
            except ctypes.ArgumentError:
                pass
        
        self._window_active = False