當前位置: 首頁>>代碼示例>>Python>>正文


Python pygame.locals方法代碼示例

本文整理匯總了Python中pygame.locals方法的典型用法代碼示例。如果您正苦於以下問題:Python pygame.locals方法的具體用法?Python pygame.locals怎麽用?Python pygame.locals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pygame的用法示例。


在下文中一共展示了pygame.locals方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: render_normal

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def render_normal(font, text):
    line_spacing = font.get_sized_height() + 1
    line_bounds = font.get_rect(text)
    fsize = (round(2.0 * line_bounds.width), round(1.25 * line_spacing))
    surf = pygame.Surface(fsize, pygame.locals.SRCALPHA, 32)
    x, y = 0, line_spacing
    
    rect = font.render_to(surf, (x, y), text)
    rect.x = x + rect.x
    rect.y = y - rect.y
    
    surf = pygame.surfarray.pixels_alpha(surf).swapaxes(0, 1)
    loc = np.where(surf > 20)
    miny, minx = np.min(loc[0]), np.min(loc[1])
    maxy, maxx = np.max(loc[0]), np.max(loc[1])
    return surf[miny:maxy+1, minx:maxx+1], rect 
開發者ID:youdao-ai,項目名稱:SRNet-Datagen,代碼行數:18,代碼來源:render_standard_text.py

示例2: __init__

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def __init__(self, data, globals=None, locals=None, loader=None, **params):
        super(HTML, self).__init__(**params)
        # This ensures that the whole HTML document is left-aligned within
        # the rendered surface.
        self.style.align = -1

        _globals, _locals = globals, locals

        if _globals == None: _globals = {}
        if _locals == None: _locals = {}
        self._globals = _globals
        self._locals = _locals

        #font = gui.theme.get("label", "", "font")

        p = _html()
        p.init(self, self.style.font, self.style.color, _globals, _locals,
               loader=loader)
        p.feed(data)
        p.close()
        p.mydone() 
開發者ID:parogers,項目名稱:pgu,代碼行數:23,代碼來源:html.py

示例3: handle_events

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def handle_events(self):
        """
        Obsługa zdarzeń systemowych, tutaj zinterpretujemy np. ruchy myszką

        :return True jeżeli pygame przekazał zdarzenie wyjścia z gry
        """
        for event in pygame.event.get():
            if event.type == pygame.locals.QUIT:
                pygame.quit()
                return True

            from pygame.locals import MOUSEMOTION, MOUSEBUTTONDOWN
            if event.type == MOUSEMOTION or event.type == MOUSEBUTTONDOWN:
                self.population.handle_mouse()


# magiczne liczby używane do określenia czy komórka jest żywa 
開發者ID:koduj-z-klasa,項目名稱:python101,代碼行數:19,代碼來源:code2.py

示例4: handle_events

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def handle_events(self):
        """
        Obsługa zdarzeń systemowych, tutaj zinterpretujemy np. ruchy myszką

        :return True jeżeli pygame przekazał zdarzenie wyjścia z gry
        """
        for event in pygame.event.get():
            if event.type == pygame.locals.QUIT:
                pygame.quit()
                return True

            from pygame.locals import MOUSEMOTION, MOUSEBUTTONDOWN
            if event.type == MOUSEMOTION or event.type == MOUSEBUTTONDOWN:
                self.population.handle_mouse()

            from pygame.locals import KEYDOWN, K_RETURN
            if event.type == KEYDOWN and event.key == K_RETURN:
                self.started = True


# magiczne liczby używane do określenia czy komórka jest żywa 
開發者ID:koduj-z-klasa,項目名稱:python101,代碼行數:23,代碼來源:code0.py

示例5: handle_events

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def handle_events(self):
        """
        Obsługa zdarzeń systemowych, tutaj zinterpretujemy np. ruchy myszką

        :return True jeżeli pygame przekazał zdarzenie wyjścia z gry
        """
        for event in pygame.event.get():
            if event.type == pygame.locals.QUIT:
                pygame.quit()
                return True

            if event.type == pygame.locals.MOUSEBUTTONDOWN:
                if self.ai_turn:
                    # jeśli jeszcze trwa ruch komputera to ignorujemy zdarzenia
                    continue
                # pobierz aktualną pozycję kursora na planszy mierzoną w pikselach
                x, y = pygame.mouse.get_pos()
                self.board.player_move(x, y)
                self.ai_turn = True 
開發者ID:koduj-z-klasa,項目名稱:python101,代碼行數:21,代碼來源:tic_tac_toe.py

示例6: run_visualizer_control_loop

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def run_visualizer_control_loop(control_display_stream):
    """Runs a pygame loop that waits for user commands.

    The user commands are send on the control_display_stream
    to control the pygame visualization window.
    """
    import erdos
    import pygame
    clock = pygame.time.Clock()
    from pygame.locals import K_n
    while True:
        clock.tick_busy_loop(60)
        events = pygame.event.get()
        for event in events:
            if event.type == pygame.KEYUP:
                if event.key == K_n:
                    control_display_stream.send(
                        erdos.Message(erdos.Timestamp(coordinates=[0]),
                                      event.key)) 
開發者ID:erdos-project,項目名稱:pylot,代碼行數:21,代碼來源:utils.py

示例7: handle_events

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def handle_events(self):
        """
        Obsługa zdarzeń systemowych, tutaj zinterpretujemy np. ruchy myszką

        :return True jeżeli pygame przekazał zdarzenie wyjścia z gry
        """
        for event in pygame.event.get():
            if event.type == pygame.locals.QUIT:
                pygame.quit()
                return True


# magiczne liczby używane do określenia czy komórka jest żywa 
開發者ID:koduj-z-klasa,項目名稱:python101,代碼行數:15,代碼來源:code1a.py

示例8: draw_on

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def draw_on(self, surface):
    """
    Rysuje komórki na planszy
    """
    for x, y in self.alive_cells():
        size = (self.box_size, self.box_size)
        position = (x * self.box_size, y * self.box_size)
        color = (255, 255, 255)
        thickness = 1
        pygame.draw.rect(surface, color, pygame.locals.Rect(position, size), thickness) 
開發者ID:koduj-z-klasa,項目名稱:python101,代碼行數:12,代碼來源:code1a.py

示例9: draw_on

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def draw_on(self, surface):
        """
        Rysuje komórki na planszy
        """
        for x, y in self.alive_cells():
            size = (self.box_size, self.box_size)
            position = (x * self.box_size, y * self.box_size)
            color = (255, 255, 255)
            thickness = 1
            pygame.draw.rect(surface, color, pygame.locals.Rect(position, size), thickness) 
開發者ID:koduj-z-klasa,項目名稱:python101,代碼行數:12,代碼來源:code2.py

示例10: handle_events

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def handle_events(self):
        """
        Obsługa zdarzeń systemowych, tutaj zinterpretujemy np. ruchy myszką

        :return True jeżeli pygame przekazał zdarzenie wyjścia z gry
        """
        for event in pygame.event.get():
            if event.type == pygame.locals.QUIT:
                pygame.quit()
                return True


# Ta część powinna być zawsze na końcu modułu (ten plik jest modułem)
# chcemy uruchomić naszą grę dopiero po tym jak wszystkie klasy zostaną zadeklarowane 
開發者ID:koduj-z-klasa,項目名稱:python101,代碼行數:16,代碼來源:code1.py

示例11: handle_events

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def handle_events(self):
        """
        Obsługa zdarzeń systemowych, tutaj zinterpretujemy np. ruchy myszką

        :return True jeżeli pygame przekazał zdarzenie wyjścia z gry
        """
        for event in pygame.event.get():
            if event.type == pygame.locals.QUIT:
                pygame.quit()
                return True

            if event.type == pygame.locals.MOUSEMOTION:
                # myszka steruje ruchem pierwszego gracza
                x, y = event.pos
                self.player1.move(x) 
開發者ID:koduj-z-klasa,項目名稱:python101,代碼行數:17,代碼來源:pong_z5.py

示例12: handle_events

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def handle_events(self):
        """
        Obsługa zdarzeń systemowych, tutaj zinterpretujemy np. ruchy myszką

        :return True jeżeli pygame przekazał zdarzenie wyjścia z gry
        """
        for event in pygame.event.get():
            if event.type == pygame.locals.QUIT:
                pygame.quit()
                return True 
開發者ID:koduj-z-klasa,項目名稱:python101,代碼行數:12,代碼來源:pong_z4.py

示例13: press

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def press(keys, snack):
    global score
    # K_w 為 pygame.locals 中的常量
    # keys[K_w] 返回 True or False
    # 上移
    if keys[K_w] or keys[K_UP]:
        snack.toward(0, -1)
    # 下移
    elif keys[K_s] or keys[K_DOWN]:
        snack.toward(0, 1)
    # 左移
    elif keys[K_a] or keys[K_LEFT]:
        snack.toward(-1, 0)
    # 右移
    elif keys[K_d] or keys[K_RIGHT]:
        snack.toward(1, 0)
    # 重置遊戲
    elif keys[K_r]:
        score = 0
        main()
    # 退出遊戲
    elif keys[K_ESCAPE]:
        exit()


# 遊戲初始化 
開發者ID:xflywind,項目名稱:Python-Application,代碼行數:28,代碼來源:snack_pygame.py

示例14: test_issue_208

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def test_issue_208(self):
        """PATCH: pygame.scrap on X11, fix copying into PRIMARY selection

           Copying into theX11 PRIMARY selection (mouse copy/paste) would not
           work due to a confusion between content type and clipboard type.

        """

        from pygame import display, event, freetype
        from pygame.locals import SCRAP_SELECTION, SCRAP_TEXT
        from pygame.locals import KEYDOWN, K_y, QUIT

        success = False
        freetype.init()
        font = freetype.Font(None, 24)
        display.init()
        display.set_caption("Interactive X11 Paste Test")
        screen = display.set_mode((600, 200))
        screen.fill(pygame.Color('white'))
        text = "Scrap put() succeeded."
        msg = ('Some text has been placed into the X11 clipboard.'
               ' Please click the center mouse button in an open'
               ' text window to retrieve it.'
               '\n\nDid you get "{}"? (y/n)').format(text)
        word_wrap(screen, msg, font, 6)
        display.flip()
        event.pump()
        scrap.init()
        scrap.set_mode(SCRAP_SELECTION)
        scrap.put(SCRAP_TEXT, text.encode('UTF-8'))
        while True:
            e = event.wait()
            if e.type == QUIT:
                break
            if e.type == KEYDOWN:
                success = (e.key == K_y)
                break
        pygame.display.quit()
        self.assertTrue(success) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:41,代碼來源:scrap_test.py

示例15: joystick

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import locals [as 別名]
def joystick(ns, event):
    pygame.init()
    pygame.joystick.init()
    
    try:
        js = pygame.joystick.Joystick(0)
        js.init()
        js_name = js.get_name()
        print('Joystick name: ' + js_name)
        if js_name in ('Wireless Controller', 'Sony Computer Entertainment Wireless Controller'):
            buttons = JoystickPS4
        elif js_name in ('PLAYSTATION(R)3 Controller', 'Sony PLAYSTATION(R)3 Controller'):
            buttons = JoystickPS3
        elif js_name == 'Xbox One Wired Controller':
            buttons = JoystickXONE
    except pygame.error:
        pass

    if buttons is None:
        print('no supported joystick found')
        return
    try:
      while True:
        time.sleep(0.01)
        for e in pygame.event.get():
          #if e.type == pygame.locals.JOYAXISMOTION:
          if e.type == pygame.locals.JOYHATMOTION:
            ns.type = e.type
            ns.value = e.value
            ns.button = None
          elif e.type == pygame.locals.JOYBUTTONDOWN:
            ns.type = e.type
            ns.value = None
            ns.button = e.button
          elif e.type == pygame.locals.JOYBUTTONUP:
            ns.type = e.type
            ns.value = None
            ns.button = e.button
          #print(ns.type, " - ", ns.value, " - ", ns.button)
          event.set()
    except Exception as e:
      print(e) 
開發者ID:markwinap,項目名稱:TensorFlow-Tello-Object_Detection-,代碼行數:44,代碼來源:image_object_detection_video_drone_multiprocessing.py


注:本文中的pygame.locals方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。