• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python event.get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pygame.event.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: main

def main():
    """Main program loop"""
    
    pygame.init()
    screen = pygame.display.set_mode(opt.window_size)
    
    sys_font = Font(get_default_font(), opt.font_size)
    clock = Clock()
    
    manager = YarsManager()

    running = True
    
    while running:
        #limit framerate and prepare FPS display text
        clock.tick(opt.max_framerate)
        fps = clock.get_fps()
        fps_text = sys_font.render("FPS: {0:.1f}".format(fps), False, opt.white)
        
        if event.get(pygame.QUIT):
            sys.exit()

        running = manager.handle_events(event.get(), key.get_pressed())
        manager.update()

        screen.fill(opt.black)
        manager.draw(screen)
        screen.blit(fps_text, fps_text.get_rect(top = 0, right = opt.width))
        pygame.display.update()
		
    sys.exit()
开发者ID:rubiximus,项目名称:yars-revenge,代码行数:31,代码来源:game.py


示例2: clearEvents

def clearEvents(eventType=None):
    """Clears all events currently in the event buffer.

    Optional argument, eventType, specifies only certain types to be
    cleared.

    :Parameters:
        eventType : **None**, 'mouse', 'joystick', 'keyboard'
            If this is not None then only events of the given type are cleared
    """
    #pyglet
    if not havePygame or not display.get_init():
        #for each (pyglet) window, dispatch its events before checking event buffer
        wins = pyglet.window.get_platform().get_default_display().get_windows()
        for win in wins:
            win.dispatch_events()#pump events on pyglet windows
        if eventType=='mouse':
            return # pump pyglet mouse events but don't flush keyboard buffer
        global _keyBuffer
        _keyBuffer = []
    else:
        #for pygame
        if eventType=='mouse':
            junk = evt.get([locals.MOUSEMOTION, locals.MOUSEBUTTONUP,
                            locals.MOUSEBUTTONDOWN])
        elif eventType=='keyboard':
            junk = evt.get([locals.KEYDOWN, locals.KEYUP])
        elif eventType=='joystick':
            junk = evt.get([locals.JOYAXISMOTION, locals.JOYBALLMOTION,
                  locals.JOYHATMOTION, locals.JOYBUTTONUP, locals.JOYBUTTONDOWN])
        else:
            junk = evt.get()
开发者ID:BrainTech,项目名称:psychopy,代码行数:32,代码来源:event.py


示例3: step

	def step(self,delay):
		if self.joy:
			event.get()
			curve,magnitude=[self.joy.get_axis(x)for x in xrange(2)]
		else:
			curve,magnitude=[random.uniform(-1,1)for _ in xrange(2)]
		self.robot.ApplyLinearImpulse(impulse=b2Vec2(cos(self.robot.angle),-sin(self.robot.angle))*(-magnitude*Robot.IMPULSE),point=self.robot.position)
		self.robot.ApplyTorque(curve*Robot.IMPULSE)
		self.world.Step(delay,10,10)
		self.world.ClearForces()
开发者ID:yingted,项目名称:crio,代码行数:10,代码来源:physics.py


示例4: handle_events

 def handle_events(self):    # handling keyboard
     for evt in event.get():
         if evt.type == QUIT:    # quit the game
             self.quit = True
         if evt.type == KEYDOWN:
             if evt.key == K_u and self.stop:
                 try:
                     if not self.rank:
                         r=str(post_score(self.player.name,self.score))
                         self.msg_center = 'Your Global Rank :'+r
                     self.rank = True
                 except:
                     self.rank = False
                     self.msg_center = 'Sorry! Failed to fetch rank'
             if evt.key == K_ESCAPE: # quit the game
                 self.quit = True
             if evt.key == K_p and not self.stop:  # press p for pause
                 self.pause = True
                 self.msg_center = "Press 'Space' to resume" 
             if evt.key == K_SPACE:  # press space to ...
                 if self.pause:  # ...unpause on pressing p
                     self.pause = False
                     self.msg_center = "" 
                 if self.stop:   #  ...start a new game if gameover
                     self.reset()
                     self.stop = False
开发者ID:nandakishoremmn,项目名称:copter_pygame,代码行数:26,代码来源:main.py


示例5: get

    def get(self):
        events.pump()
        notmine = []
        inp = NOOP
        for event in events.get():
            if event.type == QUIT:
                inp = QUITCOMMAND
            if ((event.type == KEYDOWN or event.type == KEYUP)
                and self.keyDict.has_key(event.key)):
                if event.type == KEYDOWN:
                    inp = self.keyDict[event.key]
                elif event.type == KEYUP:
                    keyDown = key.get_pressed()
                    if(keyDown[self.commandDict[UP]]):
                        inp = UP
                    elif(keyDown[self.commandDict[DOWN]]):
                        inp = DOWN
                    elif(keyDown[self.commandDict[LEFT]]):
                        inp = LEFT
                    elif(keyDown[self.commandDict[RIGHT]]):
                        inp = RIGHT
                    else:
                        inp = STOP
                else:
                    raise UnexpectedInput
            else:
                notmine.append(event)

        for yours in notmine:
            events.post(yours)

        return inp
开发者ID:bry,项目名称:pybomber2,代码行数:32,代码来源:inputdevice.py


示例6: play_scene

 def play_scene(self):
     self.screen.blit(self.img, self.origin)
     while(self.end_cutscene is False):
         PD.flip()
         for event in PE.get():
             if event.type == PG.KEYDOWN and event.key == PG.K_q:
                 #skip cutscene
                 self.end_cutscene = True
                 return False  # end entire cutscene
             elif event.type == PG.KEYDOWN and event.key == PG.K_SPACE:
                 if(len(self.text) > 0 and len(self.textcoords) > 0):
                     self.screen.blit(self.img, self.origin)
                     #find better way to clear text, maybe layers?
                     txt = self.text.pop()
                     txtcoord = self.textcoords.pop()
                     self.screen.blit(self.font.render(txt, True,
                                                       self.text_color),
                                      txtcoord)
                 elif(len(self.over_img) > 0):
                     oimg = self.over_img.pop()
                     oimgcoord = self.over_imgcoords.pop()
                     self.screen.blit(oimg, oimgcoord)
                 else:
                     self.end_cutscene = True  # no more txt or imgs to add
                     return True  # go to next scene
开发者ID:fryingpan,项目名称:Assignment2,代码行数:25,代码来源:Cutscene.py


示例7: pause

def pause(display):
    global main_score
    screen = display.get_surface()

    hsfont = font.Font(FONT, 100)
    ysfont = font.Font(FONT,100)
    hs = hsfont.render("HIGH SCORE :-->" + str(highscore/2), True, HIGHSCORE_COLOR)
    
    y_score = ysfont.render("YOUR SCORE :-->"+str(main_score/2), True, Y_SCORE_COLOR)
    
    main_score = 0
    #score = 0

  
    pause_img=image.load('pause.png').convert_alpha()
    pause_img=transform.scale(pause_img, (1200, 700)) 
 
    screen.blit(pause_img, (0, 0,))
    screen.blit(hs, (200, 60))
    screen.blit(y_score, (200, 200))
    display.flip()

    while True:
        for i in event.get():
            if i.type == MOUSEBUTTONDOWN or i.type == KEYDOWN:
                    return main()
开发者ID:abhishek3022,项目名称:Touch-free-flappy-bird-game,代码行数:26,代码来源:main.py


示例8: push

 def push( self ):
     evts = event.get()
     # Push out all events found 
     for evt in evts:
         print evt            
         self.sock.sendto(self._parse(evt), ('', self.port))
     return len(evts)
开发者ID:uriahjb,项目名称:ujb-projects,代码行数:7,代码来源:joy2mat.py


示例9: handle_general_events

	def handle_general_events(self):
		"""
		set quit true if user clicks the close button
		"""
		for evt in event.get():
			if evt.type == QUIT:
				self.quit = True
开发者ID:nandakishoremmn,项目名称:ants,代码行数:7,代码来源:controller.py


示例10: poll

    def poll(self, pos):
        if self._images[0].get_rect().collidepoint(pos):
            event.get()
            pressed = mouse.get_pressed()[0]
        else:
            pressed = False

        changed = False
        if self._pressed != pressed:
            self._pressed = pressed
            changed = True

        if self._pressed:
            self._down()

        return changed
开发者ID:tps12,项目名称:Dorftris,代码行数:16,代码来源:scrollbutton.py


示例11: main

def main():
	terminou = False
	term.cout (defaultMessageColor, 'Application Started!')
	init ()
	screen = display.set_mode (windowSize)
	snake= Snake(windowSize[0]/2, windowSize[0]/2)
	snake.generateFood (1, 1, screen.get_width(), screen.get_height())
	core = GameCore (screen)
	core.setMainDelay (0.2)
	
	while not terminou:
		for ev in event.get ():
			if ev.type == QUIT:
				terminou = True
				break;
				
			elif ev.type == KEYDOWN:
				term.cout ('warning', 'Keypressed: ' + str (ev.key))
				
				if ev.key == LEFT or ev.key == RIGHT or ev.key == DOWN or ev.key == UP:
					snake.move (ev.key)
		
		core.blitWalls ()
		snake.blit (screen)
		snake.blitFood (screen)
		snake.move (snake.getDirection())
		core.flipDisplay ()
开发者ID:chiforimpola,项目名称:GeneralApps,代码行数:27,代码来源:main.py


示例12: exchangeInput

    def exchangeInput(self):
        """Exchange a round of inputs in a network-safe
           manner.
        """
        inputs = []
        for player in self.playerList:
            inp = self.getPlayerInput(player)
            debug("Player " + str(player.name) +\
                  " input: " + inp + "\n")
            if self.record and inp != NOOP:
                self.playerInputFileList[int(player.name)].write( \
                  str(self.totalGameLoops) +\
                  ',' + inp + '\n')

            # Check players input
            if len(inp) != len(UP):
                print "Bad input from player",player.getHandle()
                inp = DISCONNECT

            # Can quit the game from end splash screen
            if inp == QUITCOMMAND:
                sys.exit()

            inputs.append((player.name,inp))
            for netplayer in self.playerList:
                netplayer.sendCommand(player.getBroadcastable())

        self.totalGameLoops += 1
        # Clear all useless events
        eventsWeWant = events.get([KEYDOWN, KEYUP, JOYBUTTONDOWN,\
                                   JOYAXISMOTION])
        events.clear()
        for event in eventsWeWant:
            events.post(event)
        return inputs
开发者ID:bry,项目名称:pybomber2,代码行数:35,代码来源:game.py


示例13: eventHandle

 def eventHandle(self,optionList,selector):
     self.optionList = optionList
     self.selector = selector
     for dummyEv in event.get():
         if dummyEv.type == QUIT:
             exit()
         elif dummyEv.type == KEYDOWN:
             if dummyEv.key == K_RIGHT: #Does nothing for now...
                 self.optionList[self.selector.vPos].deselect()
                 self.selector.moveRight()
                 self.optionList[self.selector.vPos].select()
             elif dummyEv.key == K_LEFT: #Does nothing for now...
                 self.optionList[self.selector.vPos].deselect()
                 self.selector.moveLeft()
                 self.optionList[self.selector.vPos].select()
             elif dummyEv.key == K_UP:
                 self.optionList[self.selector.vPos].deselect()
                 self.selector.moveUp()
                 self.optionList[self.selector.vPos].select()
             elif dummyEv.key == K_DOWN:
                 self.optionList[self.selector.vPos].deselect()
                 self.selector.moveDown()
                 self.optionList[self.selector.vPos].select()
             elif dummyEv.key == K_SPACE:
                 self.optionList[self.selector.vPos].doOption()
             elif dummyEv.key == K_RETURN:
                 self.optionList[self.selector.vPos].doOption()
开发者ID:Bobsleigh,项目名称:LD35_WarmUp,代码行数:27,代码来源:EventHandlerTitleScreen.py


示例14: clik

def clik():
  for event in EVENTS.get():

    if event.type == GLOBALS.KEYDOWN:
      if event.key == GLOBALS.K_ESCAPE:
        quitter()

      if event.key == GLOBALS.K_RETURN:
        texte("Entree", 0, 0, blancF)
        time.sleep(0.5)

      if event.key == GLOBALS.K_LEFT:
        texte("Gauche", 0, 0, blancF)
        time.sleep(0.5)

      if event.key == GLOBALS.K_RIGHT:
        texte("Droite", 0, 0, blancF)
        time.sleep(0.5)

      if event.key == GLOBALS.K_UP:
        texte("Haut", 0, 0, blancF)
        time.sleep(0.5)

      if event.key == GLOBALS.K_DOWN:
        texte("Bas", 0, 0, blancF)
        time.sleep(0.5)
开发者ID:impPulse,项目名称:PiTFTUInterface,代码行数:26,代码来源:emptyInterface.py


示例15: run

    def run(self):

        window = display.get_surface()

        for evt in event.get():
            if evt.type == pygame.QUIT:
                self.quit()
            elif evt.type == pygame.MOUSEMOTION:
                self.processMouseMotion(evt.pos)

            elif evt.type == pygame.KEYDOWN:
                self.processKeyDown(evt.key)

            elif evt.type == pygame.MOUSEBUTTONDOWN:
                self.processMouseButtonDown(evt.pos)

            elif evt.type == pygame.MOUSEBUTTONUP:
                self.processMouseButtonUp(evt.pos)

        window.fill(self.aColor)

        # self.testObj.rect.x = self.mouseX
        # self.testObj.rect.y = self.mouseY
        # self.activeSprites.draw(window)

        self.activeState.update(self.Clock.get_time())
        self.activeState.activeSprites.draw(window)
        if len(self.activeState.pts) > 1:
            draw.lines(window, (255, 0, 255), False, self.activeState.pts, 3)

        self.Clock.tick(30)
        display.flip()
        self.run()
开发者ID:Berulacks,项目名称:ethosgame,代码行数:33,代码来源:game.py


示例16: update

 def update(self):
     """Update the event loop
     
        Calls the callbacks binded to the mouse and keyboard
        Calls the USEREVENT callback() methods
     """
     self._keys_up = set([])
     for e in event.get():
         if e.type == QUIT:
             pygame.quit()
             sys.exit()
         elif e.type == KEYDOWN:
             self._keys_down.add(e.key)
         elif e.type == KEYUP:
             if e.key in self._keys_down:
                 self._keys_down.remove(e.key)
                 self._keys_up.add(e.key)
         elif e.type in (MOUSEBUTTONDOWN, MOUSEBUTTONUP, MOUSEMOTION):
             self._mouseCallback(self.buttons_down, self.mouse_pos, self.mouse_relpos) 
         elif e.type == USEREVENT:
             try: 
                 e.callback()
             except AttributeError:
                 print e," is a USEREVENT with no callback function defined."
                       
     self._keyboardCallback(self.keysdown, self.keysup)
开发者ID:MrGecko,项目名称:pyguane,代码行数:26,代码来源:eventmanager.py


示例17: update_keys

 def update_keys(self, reply=None):
     """
     Update the map self.keys according to user inputs.
     It uses either the x11 method or the pygame events
     :reply: If the x11 method is used, this is the message returned from x11
     """
     with self.keys_lock:
         if reply:  # Use x11 events
             data = reply.data
             while len(data):
                 evt, data = rq.EventField(None).parse_binary_value(data, self.record_dpy.display, None, None)
                 if evt.type in [X.KeyPress, X.KeyRelease]:
                     if evt.detail==X11_F1:
                         self.keys[0] = evt.type==X.KeyPress
                     elif evt.detail==X11_F2:
                         self.keys[1] = evt.type==X.KeyPress
                     elif evt.detail==X11_F3:
                         self.keys[2] = evt.type==X.KeyPress
                     elif evt.detail==X11_F4:
                         self.keys[3] = evt.type==X.KeyPress
                     elif evt.detail==X11_F5:
                         self.keys[4] = evt.type==X.KeyPress
         else:  # Use pygame events
             for evt in event.get():
                 if evt.type in [KEYDOWN, KEYUP]:
                     if evt.key==K_F1:
                         self.keys[0] = evt.type==KEYDOWN
                     elif evt.key==K_F2:
                         self.keys[1] = evt.type==KEYDOWN
                     elif evt.key==K_F3:
                         self.keys[2] = evt.type==KEYDOWN
                     elif evt.key==K_F4:
                         self.keys[3] = evt.type==KEYDOWN
                     elif evt.key==K_F5:
                         self.keys[4] = evt.type==KEYDOWN
开发者ID:titimoby,项目名称:arbapps,代码行数:35,代码来源:UserHits.py


示例18: ask

 def ask(self, question, text=''):
     "ask(question, text) -> answer"
     qw = self.box('%s: ' % question)
     lasttext = None
     while 1:
         if self.cb and self.cbargs:
             self.cb(*self.cbargs)
         sleep(0.01)
         if lasttext != text:
             self.message(qw, text)
             lasttext = text
         events = event.get((KEYDOWN, QUIT))
         if not events:
             continue
         if QUIT in [e.type for e in events]:
             return e
         elif events[0].key == K_BACKSPACE:
             text = text[:-1]
         elif events[0].key in (K_ESCAPE, K_END):
             return None
         elif events[0].key == K_RETURN:
             return text
         elif 31 < events[0].key < 127:
             key = events[0].unicode.encode('ascii')
             text += (key.translate(self.transtable) if
                      self.transtable else key)
开发者ID:brentnewey,项目名称:Sokoban,代码行数:26,代码来源:inputbox.py


示例19: runtrial

 def runtrial(self):
     surface = display.get_surface()
     surface.fill((255,255,255))
     surface.blit(self.image,TOPLEFT)
     display.flip()
     self.sound.play()
     time.sleep(ST_LENGTH)
     surface.blit(self.fill,TOPLEFT)
     display.flip()
     time.sleep(TB_LENGTH)
     keypresses = []
     for e in event.get(KEYDOWN):
         keypresses += [e.dict['unicode']]
     if SPACE in keypresses:
         return None
     if unicode(KEYLEFT) in keypresses:
         if self.trgtimg:
             #print "user hit key \""+ KEYLEFT +"\" correctly"
             self.result[0] = True
         else:
             #print "user hit key \""+ KEYLEFT +"\" incorrectly"
             self.result[0] = False
     if unicode(KEYRIGHT) in keypresses:
         if self.trgtsnd:
             #print "user hit key \""+ KEYRIGHT +"\" correctly"
             self.result[1] = True
         else:
             #print "user hit key \""+ KEYRIGHT +"\" incorrectly"
             self.result[1] = False
     return True
开发者ID:sfavors3,项目名称:MindMixer,代码行数:30,代码来源:mindmixer.py


示例20: start_editor

    def start_editor(self):
        glyph = self.editor_info
        glyph_rect = glyph.rect
        glyph.input(PAGES['editor'])
        glyph.update()
        editor = self.editor
        editor_rect = editor.rect
        SCREEN.blit(EDITOR_BKGSCREEN, (0, 0))
        SCREEN.blit(glyph.image, glyph_rect)
        SCREEN.blit(editor.image, editor_rect)
        editor_focus = False
        while 1:
            mouse_pos = mouse.get_pos()
            link = glyph.get_collisions(mouse_pos)
            if link: mouse.set_cursor(*HAND_CURSOR)
            else: mouse.set_cursor(*DEFAULT_CURSOR)
            for ev in event.get():
                if ev.type == MOUSEBUTTONDOWN:
                    if link: pass

                    if editor.rect.collidepoint(mouse_pos): editor_focus = True

                    else: editor_focus = False

                if ev.type == KEYDOWN:
                    if ev.key == K_ESCAPE: exit()
                    if editor_focus == True: editor.input(ev)

            cursor = editor.get_cursor()
            editor.image.fill((255, 205, 0), cursor)

            SCREEN.blit(editor.image, editor_rect)
            display.update()
开发者ID:LukeMS,项目名称:glyph,代码行数:33,代码来源:example.py



注:本文中的pygame.event.get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python event.post函数代码示例发布时间:2022-05-25
下一篇:
Python draw.rect函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap