本文整理汇总了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
示例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()
示例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
示例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
示例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
示例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))
示例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
示例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)
示例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)
示例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
示例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)
示例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
示例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()
# 游戏初始化
示例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)
示例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