コード例 #1
0
 def visible(self, visible):
     self._visible = visible
     clock.unschedule(self._blink)
     if visible and self._active and self.PERIOD:
         clock.schedule_interval(self._blink, self.PERIOD)
         self._blink_visible = False  # flipped immediately by next blink
     self._blink(0)
コード例 #2
0
ファイル: conway.py プロジェクト: eordano/random
 def start(self):
     if self.__running:
         unschedule(self.update)
         self.__running = False
     else:
         schedule_interval(self.update, self.speed)
         self.__running = True
コード例 #3
0
ファイル: game.py プロジェクト: nightowl97/invaders_mini_game
    def __init__(self, *args, **kwargs):
        # All arguments go to superclass
        self.win = window.Window.__init__(self, *args, **kwargs)

        clock.schedule_interval(self.update, 1.0 / 30)  # update at 30 Hz
        clock.schedule_interval(self.create_alien, 1.0 / 5)  # update at 5 Hz

        self.score = pyglet.text.Label('Score: 0',
                                       font_name="Tahoma",
                                       font_size=14,
                                       x=self.width / 2,
                                       y=10)

        self.fpstext = pyglet.text.Label('',
                                         font_name="Tahoma",
                                         font_size=14,
                                         y=10)  # object to display the FPS

        # loading image
        self.spaceship_image = pyglet.image.load('images/ship3.png')
        self.spaceship_image.anchor_x = self.spaceship_image.width // 2
        self.spaceship_image.anchor_y = self.spaceship_image.height // 2
        self.spaceship = Spaceship(self.spaceship_image, x=200, y=50)

        self.alien_image = pyglet.image.load('images/invader.png')
        self.alien_image.anchor_x = self.spaceship_image.width // 2
        self.alien_image.anchor_y = self.spaceship_image.height // 2

        self.bullet_image = pyglet.image.load('images/bullet_white_16.png')
        self.bullet_image.anchor_x = self.bullet_image.width // 2
        self.bullet_image.anchor_y = self.bullet_image.height // 2

        self.aliens = []
        self.bullets = []
コード例 #4
0
 def __init__(self, size, color):
     self.zulus = []
     self.ruleset = []
     self.size = size
     self.color = color
     # schedule the update function, 60 times per second
     clock.schedule_interval(self.update, 1.0 / 120.0)
コード例 #5
0
    def __init__(self, width=640, height=480, resizable=True, visible=True):
        super(TestWindow, self).__init__(width=width,
                                         height=height,
                                         resizable=resizable,
                                         visible=visible)

        self.rpoly = 0.0
        clock.schedule_interval(self.update, 0.01)

        vertex1 = Vertex([0.0, 1.0, 0.0], color=RED)
        vertex2 = Vertex([-1.0, -1.0, 1.0], color=GREEN)
        vertex3 = Vertex([1.0, -1.0, 1.0], color=BLUE)
        vertex4 = Vertex([1.0, -1.0, -1.0], color=GREEN)
        vertex5 = Vertex([0.0, -3.0, -3.0], color=GREEN)

        a = Vertex([1.0, 1.0, -1.0], color=RED)
        b = Vertex([-1.0, 1.0, -1.0], color=GREEN)
        c = Vertex([-1.0, 1.0, -2.0], color=ORANGE)
        d = Vertex([-2.0, 1.0, 1.0], color=BLUE)
        e = Vertex([1.0, 1.0, 1.0], color=RED)

        vertex_list1 = [vertex1, vertex2, vertex3]
        vertex_list2 = [vertex1, vertex3, vertex4]
        vertex_list3 = [a, b, c, d, e]
        self.polygon1 = Polygon(vertex_list1)
        self.polygon2 = Polygon(vertex_list2)
        self.polygon3 = Polygon(vertex_list3)

        glShadeModel(GL_SMOOTH)
        glClearColor(1.0, 1.0, 1.0, 0.0)  # bg color
        glClearDepth(1.0)
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LEQUAL)
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
コード例 #6
0
ファイル: agent.py プロジェクト: msarch/py
 def __init__(self, *args, **kwargs):
     self._id = chr((Agent.new_id() % 26) + 97)  # converts int to letters
     self._items = set()
     if args:
         self._items.update(args)
     else:
         self._items.add(dummy)
     for i in kwargs:
         setattr(self, i, kwargs[i])
     if not hasattr(self, 'agenttype'):
         self.agenttype = 'persistent'
     # default agenttype
     if self.agenttype == 'persistent':
         _persistent.add(self)
     # periodic agents, of course agent must have a 'period' attribute
     elif self.agenttype == 'periodic':
         _periodic.add(self)  # is this necessary ?
         schedule_interval(self.tick,
                           self.period)  # or schedule a oneshot agent ?
     # will run only once, then erased from list
     elif self.agenttype == 'oneshot':
         _oneshot.add(self)
     # of course agent must have a 'condition' attribute
     elif self.agenttype == 'conditional':
         _conditional.add(self)
     else:
         print ':: unrecognized type of agent'
     self.setup()
     print "::"
     print ":: new agent :::::::::::::::::::::::::::::::::::::::::::::::::::"
     print "::"
     dumpObj(self)
コード例 #7
0
    def __init__(self, *args, **kwargs):

        #Let all of the arguments pass through
        self.win = window.Window.__init__(self, *args, **kwargs)
        
        clock.schedule_interval(self.update, 1.0/30) # update at 30 Hz
        clock.schedule_interval(self.create_alien, 1.0/2) # update at 5 Hz
        
        
        # setting text objects
        ft = font.load('Tahoma', 20)         #Create a font for our FPS clock
        self.fpstext = font.Text(ft, y=10)   # object to display the FPS
        
        self.score = font.Text(ft, x=self.width, y=self.height, 
                               halign=pyglet.font.Text.RIGHT, 
                               valign=pyglet.font.Text.TOP)
                               
        # loading image
        self.spaceship_image = pyglet.image.load('images/ship3.png')
        self.spaceship = Spaceship(self.spaceship_image, x=200, y=50)
        
        self.alien_image = pyglet.image.load('images/invader.png')
        self.aliens = []
        
        self.bullet_image = pyglet.image.load('images/bullet_white_16.png')
        self.bullets = []
コード例 #8
0
ファイル: rules.py プロジェクト: msarch/py
 def __init__(self, *args, **kwargs):
     self._items=set()
     if args:
         self._items.update(args)
     else:
         self._items.add(dummy)
     for i in kwargs:
         setattr(self,i,kwargs[i])
     if not hasattr (self,'ruletype'):
         self.ruletype='persistent'
     # default ruletype
     if self.ruletype == 'persistent':
         _persistent.add(weakref.ref(self))
     # periodic rules, of course rule must have a 'period' attribute
     elif self.ruletype == 'periodic':
         _periodic.add(weakref.ref(self))  # is this necessary ?
         schedule_interval(self,self.period) # or schedule a oneshot rule ?
     # will run only once, then erased from list
     elif self.ruletype == 'oneshot':
         _oneshot.add(weakref.ref(self))
     # of course rule must have a 'condition' attribute
     elif self.ruletype == 'conditional':
         _conditional.add(weakref.ref(self))
     else:
         print ':: unrecognized type of rule'
     self.setup()
     print "::"
     print ":: new rule :::::::::::::::::::::::::::::::::::::::::::::::::::"
     print "::"
     dumpObj(self)
コード例 #9
0
ファイル: zululand.py プロジェクト: msarch/py
 def __init__(self,size,color):
     self.zulus=[]
     self.ruleset=[]
     self.size=size
     self.color=color
     # schedule the update function, 60 times per second
     clock.schedule_interval(self.update, 1.0/120.0)
コード例 #10
0
ファイル: rcube.py プロジェクト: HatsuneMiku/HatsuneMiku
 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)
コード例 #11
0
    def __init__(self, *args, **kwargs):

        #Let all of the arguments pass through
        self.win = window.Window.__init__(self, *args, **kwargs)
        
        self.maxaliens = 50 # max num of aliens simultaneously on the screen
        
        clock.schedule_interval(self.create_alien, 0.5)
        clock.schedule_interval(self.update, 1.0/30) # update at FPS of Hz
        
        #clock.set_fps_limit(30)
        
        # setting text objects
        ft = font.load('Tahoma', 20)    #Create a font for our FPS clock
        self.fpstext = font.Text(ft, y=10)   # object to display the FPS
        self.score = font.Text(ft, x=self.width, y=self.height, 
                               halign=pyglet.font.Text.RIGHT, 
                               valign=pyglet.font.Text.TOP)
        
        # reading and saving images
        self.spaceship_image = pyglet.image.load('images/ship3.png')
        self.alien_image = pyglet.image.load('images/invader.png')
        self.bullet_image = pyglet.image.load('images/bullet_white_16.png')
        
        # create one spaceship
        self.spaceship = Spaceship(self.spaceship_image, x=50, y=50)
        
        self.aliens=[] # list of Alien objects
        self.bullets=[] # list of Bullet objects
コード例 #12
0
ファイル: dance.py プロジェクト: damilare/dojoism
    def __init__(self):
        super(HelloWorld, self).__init__()

        # a cocos.text.Label is a wrapper of pyglet.text.Label
        # with the benefit of being a cocosnode
        self.left = cocos.sprite.Sprite('foot.png', (300, 100))
        self.right = cocos.sprite.Sprite('footr.png', (375, 100))

        self.add(self.left)
        self.add(self.right)

        self.steps = cycle([
            random.choice([
                self.hop_left,
                self.hop_right,
                self.wait,
                self.step_left,
                self.step_right,
                self.wiggle,
                self.reset,
                self.reset,
            ]) for _ in range(7)] + [self.reset]
        )

        clock.schedule_interval(self.next_step, 0.5)
コード例 #13
0
ファイル: game5.py プロジェクト: ocarneiro/pyglet_tutorial
    def __init__(self, *args, **kwargs):

        #Let all of the arguments pass through
        self.win = window.Window.__init__(self, *args, **kwargs)
        
        clock.schedule_interval(self.update, 1.0/30) # update at 30 Hz
        clock.schedule_interval(self.create_alien, 1.0/2) # update at 5 Hz
        
        
        # setting text objects
        ft = font.load('Tahoma', 20)         #Create a font for our FPS clock
        self.fpstext = font.Text(ft, y=10)   # object to display the FPS
        
        self.score = font.Text(ft, x=self.width, y=self.height, 
                               halign=pyglet.font.Text.RIGHT, 
                               valign=pyglet.font.Text.TOP)
                               
        # loading image
        self.spaceship_image = pyglet.image.load('images/ship3.png')
        self.spaceship = Spaceship(self.spaceship_image, x=200, y=50)
        
        self.alien_image = pyglet.image.load('images/invader.png')
        self.aliens = []
        
        self.bullet_image = pyglet.image.load('images/bullet_white_16.png')
        self.bullets = []
コード例 #14
0
    def __init__(self):
        super(HelloWorld, self).__init__()

        # a cocos.text.Label is a wrapper of pyglet.text.Label
        # with the benefit of being a cocosnode
        self.left = cocos.sprite.Sprite('foot.png', (300, 100))
        self.right = cocos.sprite.Sprite('footr.png', (375, 100))

        self.add(self.left)
        self.add(self.right)

        self.steps = cycle([
            random.choice([
                self.hop_left,
                self.hop_right,
                self.wait,
                self.step_left,
                self.step_right,
                self.wiggle,
                self.reset,
                self.reset,
            ]) for _ in range(7)
        ] + [self.reset])

        clock.schedule_interval(self.next_step, 0.5)
コード例 #15
0
ファイル: test.py プロジェクト: evuez/mutations
def test_view():
	global map_width
	map_ = Map(values.map_width, values.map_height)
	for i in range(values.banks):
		map_.add(EnergyBank(map_, random()))
	for i in range(values.bodies):
		map_.add(Body(map_, random()))

	def update(dt):
		map_.tick()


	sim = Window(map_.width, map_.height)
	sim_view = SimView(map_)
	schedule_interval(update, 0.1)

	@sim.event
	def on_draw():
		glClearColor(.5, .6, .6, 1)
		sim.clear()
		sim_view.draw()


	graph = Window(500, 100)
	graph_view = GraphView(map_)

	@graph.event
	def on_draw():
		graph.clear()
		graph_view.draw()


	app.run()
コード例 #16
0
ファイル: state.py プロジェクト: mjgilles/smile
def _schedule_interval_callback(dt, func, interval, *args, **kwargs):
    """
    Schedule a callback with specified interval.
    
    Parameters
    ----------
    dt: float
        The number of seconds since the last function call.
    func:function
        The function to call when the timer lapses.
    interval: float
    	The number of seconds to wait between each call
    
    Example
    -------
    
    _schedule_interval_callback(dt, function, 1.0)
    	The function will be called one second after it
    	was last called.

    """
    # schedule it
    if interval > 0:
        clock.schedule_interval(func, interval, *args, **kwargs)
    # call it
    func(dt, *args, **kwargs)
コード例 #17
0
ファイル: animate.py プロジェクト: msarch/py
def animate(field):
    e = Engine(field,fullscreen=True)
    # normal loop : run the preview at good rate
    clock.schedule_interval(e.paint_a_frame, FRAMERATE)
    # and try (soft) to run anim at same speed
    clock.schedule_interval_soft(e.tick, FRAMERATE)
    pyglet.app.run()
コード例 #18
0
 def run(self):
     if not self.ticking:
         self.ticking = True
         clock.schedule_interval(self.tick, 1 / self.get_val('speed'))
         self.buttons['tick'].off()
         self.buttons['run'].off()
         self.buttons['stop'].on()
コード例 #19
0
ファイル: engine.py プロジェクト: msarch/py
def main():
        # schedule pyglet  loop at max framerate
        # and the tick function at more than fps
        # frame / time driven loop
    options = {
    'DEBUG': 1,
    'PREVIEW_SIZE': (800, 600),
    'BGCOLOR': (0.95, 0.95, 0.95, 0),  # background
    'FPS': 60,  # display max framerate
    'PicPS': 25,  # images per second for movie export
    'MODE': 'PREVIEW',  # options are: 'FULL'; 'PREVIEW'; 'EXPORT'
    'DURATION' : 3,
    'SCENE_FOLDER' : 'scene',
    }

    engine = Engine(**options)

    #---run loop options-------------------------------------------------------
    if  engine.MODE in ('FULL','PREVIEW'):
        clock.schedule_interval(engine.frame_paint,1.0/engine.FPS)
        clock.schedule_interval_soft(engine.tick, 1.0/(1.0*engine.FPS))
    elif engine.MODE == 'EXPORT': # export loop
        # try (soft) to run export method at final anim speed,
        clock.schedule_interval_soft(engine.export_loop,1.0/engine.PicPS)
        # while (soft) run the preview at good rate
        #clock.schedule_interval_soft(self.frame_, 1.0/self.FPS,scene)

    pyglet.app.run()
コード例 #20
0
ファイル: viewport.py プロジェクト: Zildj1an/cassopi
    def __init__(self, width=640, height=480, resizable=True, visible=True):
        super(TestWindow, self).__init__(width=width,
                                         height=height,
                                         resizable=resizable,
                                         visible=visible)

        self.viewport = PerspectiveViewport(0, 0, self.width, self.height,
                                            YELLOW, [1.0, 0.5, -5.0],
                                            [0.0, 0.0, 0.0])
        self.rpoly = 0.0
        self.pressed_key = None

        clock.schedule_interval(self.update, 0.01)
        clock.schedule_interval(self.update_pressed_key, 0.1)

        a = Vertex([1.0, 1.0, -1.0], color=RED)
        b = Vertex([-1.0, 1.0, -1.0], color=GREEN)
        c = Vertex([-1.0, 1.0, -2.0], color=ORANGE)
        d = Vertex([-2.0, 1.0, 1.0], color=BLUE)
        e = Vertex([1.0, 1.0, 1.0], color=RED)

        vertex_list = [a, b, c, d, e]
        self.polygon = Polygon(vertex_list)

        glShadeModel(GL_SMOOTH)
        glClearColor(1.0, 1.0, 1.0, 0.0)  # bg color
        glClearDepth(1.0)
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LEQUAL)
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
コード例 #21
0
ファイル: transition.py プロジェクト: Bogdanp/ymage
 def add_transition(self, previous, next):
     self.queue.append({
         "previous": previous,
         "next": next,
         "phase": 1.,
     })
     clock.schedule_interval(self.tick, 1.0 / 30)
コード例 #22
0
ファイル: caret.py プロジェクト: bitcraft/pyglet
 def visible(self, visible):
     self._visible = visible
     clock.unschedule(self._blink)
     if visible and self._active and self.PERIOD:
         clock.schedule_interval(self._blink, self.PERIOD)
         self._blink_visible = False  # flipped immediately by next blink
     self._blink(0)
コード例 #23
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)
コード例 #24
0
ファイル: engine.py プロジェクト: msarch/py
def animate():
    VIEW.set_fullscreen(True)
    # normal loop : run the preview at good rate
    # clock.schedule_interval(paint, FRAMERATE)
    # and try (soft) to run anim at same speed
    clock.schedule_interval(tick, FRAMERATE)
    pyglet.app.run()
コード例 #25
0
 def __init__(self, *k, **d):
     super(Window, self).__init__(*k, **d)
     self.img = pyglet.resource.image('undo.png')
     self._enable_alpha()
     self._load_cursors()
     clock.schedule_interval(self.update, 1/60.0)
     self.logo = Logo()
コード例 #26
0
ファイル: agent.py プロジェクト: msarch/py
 def __init__(self, *args, **kwargs):
     self._id = chr((Agent.new_id()%26)+97)  # converts int to letters
     self._items=set()
     if args:
         self._items.update(args)
     else:
         self._items.add(dummy)
     for i in kwargs:
         setattr(self,i,kwargs[i])
     if not hasattr (self,'agenttype'):
         self.agenttype='persistent'
     # default agenttype
     if self.agenttype == 'persistent':
         _persistent.add(self)
     # periodic agents, of course agent must have a 'period' attribute
     elif self.agenttype == 'periodic':
         _periodic.add(self)  # is this necessary ?
         schedule_interval(self.tick,self.period) # or schedule a oneshot agent ?
     # will run only once, then erased from list
     elif self.agenttype == 'oneshot':
         _oneshot.add(self)
     # of course agent must have a 'condition' attribute
     elif self.agenttype == 'conditional':
         _conditional.add(self)
     else:
         print ':: unrecognized type of agent'
     self.setup()
     print "::"
     print ":: new agent :::::::::::::::::::::::::::::::::::::::::::::::::::"
     print "::"
     dumpObj(self)
コード例 #27
0
def village_scene(dt):
    clock.unschedule(spawn_troll)
    s.Narration("This time")
    s.Narration("They will say")
    s.Title("You are the Villain")
    clock.schedule_interval(village_callback, 5)
    for i in range(counter + 4):
        s.Villager(on_death = decrement_counter)
コード例 #28
0
ファイル: game.py プロジェクト: jgumbley/quad-game
    def __init__(self):
        super(GameWindow, self).__init__()
        clock.schedule_interval(self.on_update, 1.0 / 60)

        self.quad_sprite = Quad(self, 1, 1, scale=3)
        self.game_map = Map(self, 0, 0)

        app.run()
コード例 #29
0
ファイル: field.py プロジェクト: msarch/py
 def animate(cls):
     VIEW.set_fullscreen(True)
     cls.focus()
     # normal loop : run the preview at good rate
     clock.schedule_interval(cls.redraw, FRAMERATE)
     # and try (soft) to run anim at same speed
     clock.schedule_interval(cls.tick, FRAMERATE)
     pyglet.app.run()
コード例 #30
0
ファイル: credits.py プロジェクト: jribbens/wasabi-root
 def __init__(self, difficulties, camera):
     self.difficulties = difficulties
     self.counter = 0
     self.labels = deque()
     self.credit_it = self.credit_text()
     self.camera = camera
     schedule_interval(self.update_position, 0.017)
     schedule_once(self.update_text, 0)
コード例 #31
0
def scene1():
    print "scene1"
    s.Narration('Sending me into the snow-storm')
    s.Narration('Without any help')
    s.Narration('Again')
    s.Narration('Alone')
    clock.schedule_interval(spawn_troll, 5)
    clock.schedule_once(scene2, 20)
コード例 #32
0
ファイル: field.py プロジェクト: msarch/py
 def animate(cls):
     VIEW.set_fullscreen(True)
     cls.focus()
     # normal loop : run the preview at good rate
     clock.schedule_interval(cls.redraw, FRAMERATE)
     # and try (soft) to run anim at same speed
     clock.schedule_interval(cls.tick, FRAMERATE)
     pyglet.app.run()
コード例 #33
0
ファイル: engine18.py プロジェクト: msarch/py
 def run(self):
     if self.mode in ('FULL', 'PREVIEW'):  # normal loop
         # run the preview at good rate
         clock.schedule_interval(self.frame_paint, self.framerate)
         # and try (soft) to run export method at final anim speed,
         clock.schedule_interval_soft(self.tick, self.framerate)
     elif self.mode == 'EXPORT':  # trigger the export loop
         clock.schedule_interval_soft(self.pic_export_loop, movie_framerate)
     pyglet.app.run()
コード例 #34
0
ファイル: Game.py プロジェクト: varnie/snake
    def _setup_overlay(self, text):
        self._overlay = BouncingLabel(FIELD_WIDTH//2,FIELD_HEIGHT//2,text,DEFAULT_OVERLAY_COLOR)
        self.win.pop_handlers()
        def on_draw():
            self.win.clear()
            self._overlay.draw()
        self.win.push_handlers(on_draw)

        schedule_interval(func=self._overlay.update, interval=OVERLAY_UPDATE_INTERVAL)
コード例 #35
0
ファイル: gui.py プロジェクト: msarch/py
 def run(self):
     if MODE in ('FULLSCREEN', 'PREVIEW'):  # normal loop
         # run the preview at good rate
         clock.schedule_interval(self.frame_paint, FRAMERATE)
         # and try (soft) to run export method at final anim speed,
         clock.schedule_interval_soft(self.tick, FRAMERATE)
     elif MODE == 'EXPORT':  # trigger the export loop
         clock.schedule_interval_soft(self.pic_export_loop, MOVIE_FRAMERATE)
     pyglet.app.run()
コード例 #36
0
ファイル: engine.py プロジェクト: msarch/py
 def run(self):
     if MODE in ('FULLSCREEN', 'PREVIEW'):  # normal loop
         # run the preview at good rate
         clock.schedule_interval(self.frame_paint, FRAMERATE)
         # and try (soft) to run export method at final anim speed,
         clock.schedule_interval_soft(self.tick, FRAMERATE)
     elif MODE == 'EXPORT':  # trigger the export loop
         clock.schedule_interval_soft(self.pic_export_loop, MOVIE_FRAMERATE)
     pyglet.app.run()
コード例 #37
0
ファイル: menu.py プロジェクト: MentalMarriott/SideScroll-1
	def __init__(self):
	        """This is run when the game is created"""
		super(main_menu, self).__init__()

		self.keyboard = KeyStateHandler()
		self.set_handlers(self.keyboard)

		# Call update() 60 times a second
	        clock.schedule_interval(self.update, 1/60.0)
コード例 #38
0
ファイル: kbhandler.py プロジェクト: kearnh/4xgame
 def __init__(self, parent, step=16):
     super(KBHandler, self).__init__(self)
     self.parent = parent
     self.parent.push_handlers(self)
     clock.schedule_interval(self.update, 1/60.0)
     self.repeat = 0
     self.step = step
     self._KEYS = set([key.UP, key.DOWN, key.LEFT, key.RIGHT, key.K, key.J,
             key.H, key.L])
コード例 #39
0
ファイル: state.py プロジェクト: chadillac2313/smile
def _schedule_interval_callback(dt, func, interval, *args, **kwargs):
    """
    Schedule a callback with specified interval.
    """
    # schedule it
    if interval > 0:
        clock.schedule_interval(func, interval, *args, **kwargs)
    # call it
    func(dt, *args, **kwargs)
コード例 #40
0
ファイル: state.py プロジェクト: psederberg/smile
def _schedule_interval_callback(dt, func, interval, *args, **kwargs):
    """
    Schedule a callback with specified interval.
    """
    # schedule it
    if interval > 0:
        clock.schedule_interval(func, interval, *args, **kwargs)
    # call it
    func(dt, *args, **kwargs)
コード例 #41
0
ファイル: engine18.py プロジェクト: msarch/py
 def run(self):
     if self.mode in ('FULL', 'PREVIEW'):  # normal loop
         # run the preview at good rate
         clock.schedule_interval(self.frame_paint, self.framerate)
         # and try (soft) to run export method at final anim speed,
         clock.schedule_interval_soft(self.tick, self.framerate)
     elif self.mode == 'EXPORT':  # trigger the export loop
         clock.schedule_interval_soft(self.pic_export_loop, movie_framerate)
     pyglet.app.run()
コード例 #42
0
ファイル: viewer.py プロジェクト: xfarxod/meshrender
 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)
コード例 #43
0
def scene2(dt):
    print "scene2"
    s.Narration('Why me?')
    s.Narration('Alone')
    s.Narration('Why me?')
    s.Narration('Alone')
    s.Narration('This is not fair')
    clock.unschedule(spawn_troll)
    clock.schedule_interval(spawn_troll, 3)
    clock.schedule_once(scene3, 20)
コード例 #44
0
def main():
    window = pyglet.window.Window(width=400, height=400)

    model = Model()
    view = View(model, window)

    clock.schedule_interval(model.update, 0.001)
    clock.schedule(view.render)

    pyglet.app.run()
コード例 #45
0
    def __init__(self, *args, **kwargs):

        #Let all of the arguments pass through
        self.win = window.Window.__init__(self, *args, **kwargs)

        clock.schedule_interval(self.update, 1.0 / 30)  # update at 30 Hz

        # setting text objects
        ft = font.load('Tahoma', 20)  #Create a font for our FPS clock
        self.fpstext = font.Text(ft, y=10)  # object to display the FPS
コード例 #46
0
    def __init__(self, *args, **kwargs):

        #Let all of the arguments pass through
        self.win = window.Window.__init__(self, *args, **kwargs)
        
        clock.schedule_interval(self.update, 1.0/30) # update at 30 Hz
        
        # setting text objects
        ft = font.load('Tahoma', 20)         #Create a font for our FPS clock
        self.fpstext = font.Text(ft, y=10)   # object to display the FPS
コード例 #47
0
ファイル: pygtools.py プロジェクト: msarch/py
 def __init__(self,land):
     pyglet.window.Window.__init__(self,fullscreen=True)
     self.set_mouse_visible(False)
     self.land=land
     glClearColor(self.land.color[0],self.land.color[1],\
             self.land.color[2],self.land.color[3])
     #glClearColor(1.0, 1.0, 1.0, 1.0) # set background color to white
     glLoadIdentity() # reset transformation matrix
             # schedule the update function, 60 times per second
     clock.schedule_interval(self.update, 1.0/30.0)
コード例 #48
0
ファイル: menu.py プロジェクト: Goggles/SideScroll
    def __init__(self, main_menu, keyboard, *args, **kwargs):
        super(Select, self).__init__(*args, **kwargs)

        # Reference the keyboard object so that we can watch it
        self.keyboard = keyboard

	self.main_menu = main_menu

        # Call move_player() 60 times a second
        clock.schedule_interval(self.move, 1/60.0)
コード例 #49
0
ファイル: asteroids.py プロジェクト: notgitter/asteroids
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # batch for efficient drawing
        self.batch = graphics.Batch()
        background = graphics.OrderedGroup(0)
        foreground = graphics.OrderedGroup(1)

        self.gamelayer = graphics.OrderedGroup(2)

        toplayer = graphics.OrderedGroup(3)

        # window size
        self.size = self.get_size()

        # start with empty asteroid set
        self.asteroids = set()

        # empty explosions set
        self.explosions = set()

        # background and moving foreground sprites
        self.background = physicalobject.ScaledMovingSprite(img=resources.background_image,
                screensize=self.size, batch=self.batch, group=background)
        self.debris = load.debris(screensize=self.size, batch=self.batch, group=foreground)
        self.splashscreen = load.ClickableSprite(hook_function=self.start,
                img=resources.splashscreen,
                x = self.size[0] / 2.0, y=self.size[1] / 2.0,
                batch=self.batch, group=toplayer)


        # player ship
        self.player = load.ship(screensize=self.size, batch=self.batch, group=self.gamelayer)

        self.score = 0
        self.lives = LIVES
        self.started = False

        self.fps_display = clock.ClockDisplay()

        # Lives and score labels
        self.lives_label = text.Label(font_size=20, text="Lives: %d" % self.lives, x=40, y=self.size[1]-40,
                    batch=self.batch, group=toplayer)
        self.score_label = text.Label(font_size=20, anchor_x='right', text="Score: %d" % self.score, x=self.size[0]-40,
                    y=self.size[1]-40, batch=self.batch, group=toplayer)

        # update frequency
        clock.schedule_interval(self.update, 1 / 120)

        # spawn a new asteroid each second
        clock.schedule_interval(self.spawn_asteroid, 1)

        # add event handlers to the ship and splashscreen
        self.push_handlers(self.player)
        self.push_handlers(self.splashscreen)
コード例 #50
0
def main():
    import ctypes
    import time

    from pyglet import app, clock, font, gl, image, window

    from MusicDefs import MusicDefs

    #pic = PianoOctavePic(width=400, height=200)
    pic = HexagonalLayoutPic(D=100, scale=SCALE_MAJOR_DIATONIC, tonic=1, h=4)

    window = window.Window(width=pic.width, height=pic.height)
    #ft = font.load('Arial', 24)
    #text = font.Text(ft, 'Hello World')

    # create data shared by ImageSurface and Texture
    data = (ctypes.c_ubyte * (pic.width * pic.height * 4))()
    stride = pic.width * 4
    surface = cairo.ImageSurface.create_for_data(data, cairo.FORMAT_ARGB32,
                                                 pic.width, pic.height, stride)
    texture = image.Texture.create_for_size(gl.GL_TEXTURE_2D,
                                            pic.width * pic.height, gl.GL_RGBA)

    def update_surface(dt, surface):
        ctx = cairo.Context(surface)
        pic.draw_pic(ctx)

    @window.event
    def on_draw():
        window.clear()

        gl.glEnable(gl.GL_TEXTURE_2D)

        gl.glBindTexture(gl.GL_TEXTURE_2D, texture.id)
        gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, pic.width, pic.height,
                        0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, data)

        gl.glBegin(gl.GL_QUADS)
        gl.glTexCoord2f(0.0, 1.0)
        gl.glVertex2i(0, 0)
        gl.glTexCoord2f(1.0, 1.0)
        gl.glVertex2i(pic.width, 0)
        gl.glTexCoord2f(1.0, 0.0)
        gl.glVertex2i(pic.width, pic.height)
        gl.glTexCoord2f(0.0, 0.0)
        gl.glVertex2i(0, pic.height)
        gl.glEnd()

        #text.draw()

        #print('FPS: %f' % clock.get_fps())

    clock.schedule_interval(update_surface, 1 / 120.0, surface)
    app.run()
コード例 #51
0
ファイル: game.py プロジェクト: sirrus233/pong
    def set_screen(self, next_screen: "Screen") -> None:
        """Change the active screen.

        :param next_screen: The new screen to be active.
        """
        if self.screen:
            self.window.pop_handlers()
            unschedule(self.screen.update)
        self.window.push_handlers(next_screen.on_draw)
        schedule_interval(next_screen.update, 0.01)
        self.screen = next_screen
コード例 #52
0
ファイル: player.py プロジェクト: wtmuller22/Dungeonerator
 def start_moving(self):
     clock.schedule_interval(self.update, 1 / 60.0)
     if (self.facing == Direction.SOUTH):
         self.image = Player.south_animation
     elif (self.facing == Direction.WEST):
         self.image = Player.west_animation
     elif (self.facing == Direction.NORTH):
         self.image = Player.north_animation
     else:
         self.image = Player.east_animation
     self.is_moving = True
コード例 #53
0
ファイル: part.py プロジェクト: RoobixCube/side-projects
    def __init__(self, parent_x: int, parent_y: int, parent_w: int,
                 parent_h: int):
        super().__init__(parent_x, parent_y, parent_w, parent_h)
        self.jitter = 2
        self._x = int(parent_x + (parent_w / 2))
        self.sway_right = True
        self._y = parent_y

        self.x = randint(self._x - self.jitter, self._x + self.jitter)
        self.y = self._y

        clock.schedule_interval(self.set_x, 0.25)
コード例 #54
0
ファイル: test.py プロジェクト: shussain/babytux
    def __init__(self):
        super(Main, self).__init__()
        clock.schedule_interval(self.new_triangle, 0.25)

        #car = SImage('res/ring.png',0,0)
        #self.world.objects.append(car)

        w = self.win.width / 10.0
        h = self.win.height / 10.0
        for i in range(11):
            s = SImage('res/ring.png', i * w, i * h)
            self.world.objects.append(s)
コード例 #55
0
    def __init__(self,
                 width,
                 height,
                 caption='Window Caption',
                 bg=(0, 0, 0),
                 ticktime=0,
                 *args,
                 **kwargs):
        """
        Window constructor.

        :type width: int
        :param width: width
        :type height: int
        :param height: height
        :type caption: str
        :param caption: caption
        :type bg: list(int * 3)
        :param bg: background color
        :type ticktime: float
        :param ticktime: interval between ticks in seconds, zero to disable ticking
        """
        super().__init__(width=width,
                         height=height,
                         caption=caption,
                         *args,
                         **kwargs)
        self.set_minimum_size(width, height)
        self.real_width, self.real_height = width, height

        self.set_bg(bg)

        self._batch = _graphics.Batch()
        self.screens = {}
        self.buttons = {}
        self.labels = {}
        self.fields = {}
        self.sliders = {}
        self.labelrows = {}
        self.boxes = {}
        self.valset = ValSet()

        self.focus = None
        self.hover = None
        self.mousedown = False

        self.set_vars()
        self.update_labels()

        self.ticktime = ticktime
        if ticktime > 0:
            _clock.schedule_interval(self.tick, ticktime)
        '''
コード例 #56
0
ファイル: client.py プロジェクト: Nordvegr/CataclysmLD
    def login(self, dt):
        # we'll do the below to login and recieve a list of characters.
        self.connect(self.LoginWindow.serverIP.text,
                     int(self.LoginWindow.serverPort.text))

        # set our client_name for future sending.
        self.client_name = self.LoginWindow.username.text

        command = Command(self.LoginWindow.username.text, "login", ["noargs"])
        self.send(command)
        # -------------------------------------------------------
        clock.schedule_interval(self.check_messages_from_server, 0.1)
コード例 #57
0
ファイル: timer.py プロジェクト: flintforge/Aris
 def __init__(self, start=0, factor=1., freq=1/120.):
     ''' if we suppose the refresh frequency is 60hz,
     the timer must run at least two times faster
     in case an out of sync rendering occurs,
     wich leads to glitches.
     recomputing the timer on every frame is safer
     if we need high fréquency or expect slowdowns.
     '''
     self.init = time.time()
     self.start = start
     self.factor = factor
     self.time = start
     schedule_interval(self.update, freq)
コード例 #58
0
ファイル: part.py プロジェクト: RoobixCube/side-projects
    def __init__(self, parent_x: int, parent_y: int, parent_w: int,
                 parent_h: int, get_trunk_y: classmethod,
                 get_trunk_w: classmethod):
        super().__init__(parent_x, parent_y, parent_w, parent_h)
        self.get_trunk_y = get_trunk_y
        self.get_trunk_w = get_trunk_w
        self.x_jitter = 1
        self.y_jitter = 3
        self.t_num = 1
        self.t_variance = 1

        clock.schedule_interval(self.set_x, 0.50)
        clock.schedule_interval(self.set_y, 0.12)