本文整理汇总了Python中pygame.KEYDOWN属性的典型用法代码示例。如果您正苦于以下问题:Python pygame.KEYDOWN属性的具体用法?Python pygame.KEYDOWN怎么用?Python pygame.KEYDOWN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pygame
的用法示例。
在下文中一共展示了pygame.KEYDOWN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _handle_keyboard_shortcuts
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def _handle_keyboard_shortcuts(self):
while self._running:
event = pygame.event.wait()
if event.type == pygame.KEYDOWN:
# If pressed key is ESC quit program
if event.key == pygame.K_ESCAPE:
self._print("ESC was pressed. quitting...")
self.quit()
if event.key == pygame.K_k:
self._print("k was pressed. skipping...")
self._player.stop(3)
if event.key == pygame.K_s:
if self._playbackStopped:
self._print("s was pressed. starting...")
self._playbackStopped = False
else:
self._print("s was pressed. stopping...")
self._playbackStopped = True
self._player.stop(3)
示例2: loop
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def loop(env, screen, pano_ids_yaws):
"""Main loop of the scan agent."""
for (pano_id, yaw) in pano_ids_yaws:
# Retrieve the observation at a specified pano ID and heading.
logging.info('Retrieving view at pano ID %s and yaw %f', pano_id, yaw)
observation = env.goto(pano_id, yaw)
current_yaw = observation["yaw"]
view_image = interleave(observation["view_image"],
FLAGS.width, FLAGS.height)
graph_image = interleave(observation["graph_image"],
FLAGS.width, FLAGS.height)
screen_buffer = np.concatenate((view_image, graph_image), axis=1)
pygame.surfarray.blit_array(screen, screen_buffer)
pygame.display.update()
for event in pygame.event.get():
if (event.type == pygame.QUIT or
(event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE)):
return
if FLAGS.save_images:
filename = 'scan_agent_{}_{}.bmp'.format(pano_id, yaw)
pygame.image.save(screen, filename)
示例3: ShowStartInterface
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def ShowStartInterface(screen, screensize):
screen.fill((255, 255, 255))
tfont = pygame.font.Font(cfg.FONTPATH, screensize[0]//5)
cfont = pygame.font.Font(cfg.FONTPATH, screensize[0]//20)
title = tfont.render(u'滑雪游戏', True, (255, 0, 0))
content = cfont.render(u'按任意键开始游戏', True, (0, 0, 255))
trect = title.get_rect()
trect.midtop = (screensize[0]/2, screensize[1]/5)
crect = content.get_rect()
crect.midtop = (screensize[0]/2, screensize[1]/2)
screen.blit(title, trect)
screen.blit(content, crect)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
return
pygame.display.update()
示例4: GameOver
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def GameOver(screen, width, height, score, highest):
screen.fill((255, 255, 255))
tfont = pygame.font.Font('./font/simkai.ttf', width//10)
cfont = pygame.font.Font('./font/simkai.ttf', width//20)
title = tfont.render('GameOver', True, (255, 0, 0))
content = cfont.render('Score: %s, Highest: %s' % (score, highest), True, (0, 0, 255))
trect = title.get_rect()
trect.midtop = (width/2, height/4)
crect = content.get_rect()
crect.midtop = (width/2, height/2)
screen.blit(title, trect)
screen.blit(content, crect)
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
return
示例5: __endInterface
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def __endInterface(self, is_win):
if is_win:
text1 = 'Congratulations! You win!'
else:
text1 = 'Game Over! You fail!'
text2 = 'Press <R> to restart the game'
text3 = 'Press <Esc> to quit the game.'
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
pygame.quit()
sys.exit(-1)
if event.type == pygame.KEYDOWN and event.key == pygame.K_r:
return
self.screen.fill(self.cfg.AQUA)
text_render1 = self.font_big.render(text1, False, self.cfg.BLUE)
text_render2 = self.font_big.render(text2, False, self.cfg.BLUE)
text_render3 = self.font_big.render(text3, False, self.cfg.BLUE)
self.screen.blit(text_render1, ((self.cfg.SCREENWIDTH-text_render1.get_rect().width)//2, (self.cfg.SCREENHEIGHT-text_render1.get_rect().height)//4))
self.screen.blit(text_render2, ((self.cfg.SCREENWIDTH-text_render2.get_rect().width)//2, (self.cfg.SCREENHEIGHT-text_render2.get_rect().height)//2))
self.screen.blit(text_render3, ((self.cfg.SCREENWIDTH-text_render3.get_rect().width)//2, (self.cfg.SCREENHEIGHT-text_render2.get_rect().height)//1.5))
pygame.display.flip()
clock.tick(30)
示例6: endInterface
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def endInterface(screen, color, is_win):
screen.fill(color)
clock = pygame.time.Clock()
if is_win:
text = 'VICTORY'
else:
text = 'FAILURE'
font = pygame.font.SysFont('arial', 30)
text_render = font.render(text, 1, (255, 255, 255))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if (event.type == pygame.KEYDOWN) or (event.type == pygame.MOUSEBUTTONDOWN):
return
screen.blit(text_render, (350, 300))
clock.tick(60)
pygame.display.update()
示例7: GameStartInterface
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def GameStartInterface(screen, sounds, cfg):
dino = Dinosaur(cfg.IMAGE_PATHS['dino'])
ground = pygame.image.load(cfg.IMAGE_PATHS['ground']).subsurface((0, 0), (83, 19))
rect = ground.get_rect()
rect.left, rect.bottom = cfg.SCREENSIZE[0]/20, cfg.SCREENSIZE[1]
clock = pygame.time.Clock()
press_flag = False
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE or event.key == pygame.K_UP:
press_flag = True
dino.jump(sounds)
dino.update()
screen.fill(cfg.BACKGROUND_COLOR)
screen.blit(ground, rect)
dino.draw(screen)
pygame.display.update()
clock.tick(cfg.FPS)
if (not dino.is_jumping) and press_flag:
return True
示例8: endGame
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def endGame(screen, sounds, showScore, score, number_images, bird, pipe_sprites, backgroud_image, other_images, base_pos, cfg):
sounds['die'].play()
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE or event.key == pygame.K_UP:
return
boundary_values = [0, base_pos[-1]]
bird.update(boundary_values, float(clock.tick(cfg.FPS))/1000.)
screen.blit(backgroud_image, (0, 0))
pipe_sprites.draw(screen)
screen.blit(other_images['base'], base_pos)
showScore(screen, score, number_images)
bird.draw(screen)
pygame.display.update()
clock.tick(cfg.FPS)
示例9: endInterface
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def endInterface(screen, score_left, score_right):
clock = pygame.time.Clock()
font1 = pygame.font.Font(config.FONTPATH, 30)
font2 = pygame.font.Font(config.FONTPATH, 20)
msg = 'Player on left won!' if score_left > score_right else 'Player on right won!'
texts = [font1.render(msg, True, config.WHITE),
font2.render('Press ESCAPE to quit.', True, config.WHITE),
font2.render('Press ENTER to continue or play again.', True, config.WHITE)]
positions = [[120, 200], [155, 270], [80, 300]]
while True:
screen.fill((41, 36, 33))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
return
elif event.key == pygame.K_ESCAPE:
sys.exit()
pygame.quit()
for text, pos in zip(texts, positions):
screen.blit(text, pos)
clock.tick(10)
pygame.display.update()
示例10: update
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def update(self, frameNumber, editor):
for event, pos in editor.context.events:
if event.type == pygame.KEYDOWN:
bone = editor.getActiveBone()
key = event.key
if key == pygame.K_i:
if bone:
if event.mod & pygame.KMOD_ALT:
if bone.name in self.frames[frameNumber].keys:
del self.frames[frameNumber].keys[bone.name]
else:
key = self.frames[frameNumber].getBoneKey(bone.name)
copyKeyData(bone, key)
self.dirty = True
elif key == pygame.K_o:
if bone:
data = self.getBoneData(bone.name)
data.repeat = not data.repeat
self.dirty = True
elif key == pygame.K_p:
if bone:
data = self.getBoneData(bone.name)
data.reversed = not data.reversed
self.dirty = True
示例11: gameOverScreen
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def gameOverScreen(self):
""" Show game over screen """
global screen
# stop game main loop (if any)
self.running = False
screen.fill([0, 0, 0])
self.writeInBricks("game", [125, 140])
self.writeInBricks("over", [125, 220])
pygame.display.flip()
while 1:
time_passed = self.clock.tick(50)
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
self.showMenu()
return
示例12: _event_looper
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def _event_looper(self, force=False):
has_quit = False
if self._deactivate_display:
return force, has_quit
for event in pygame.event.get():
if event.type == pygame.QUIT:
has_quit = True
return force, has_quit
# pygame.quit()
# exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
has_quit = True
return force, has_quit
if event.key == pygame.K_SPACE:
self._get_plot_pause()
# pause_surface = self.draw_plot_pause()
# self.screen.blit(pause_surface, (320 + self.left_menu_shape[0], 320))
return not force, has_quit
return force, has_quit
示例13: _press_key_to_quit
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def _press_key_to_quit(self):
"""
This utility function waits for the player to press a key to exit the renderer (called when the episode is done)
Returns
-------
res: ``bool``, ``bool``
``True`` if the human player closed the window, in this case it will stop the computation: no other episode
will be computed. ``False`` otherwise.
"""
if self._deactivate_display:
return
has_quit = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
has_quit = True
return True, has_quit
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
has_quit = True
return True, has_quit
if event.key == pygame.K_SPACE:
return True, has_quit
return False, has_quit
示例14: _handle_player_events
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def _handle_player_events(self):
self.dx = 0
self.dy = 0
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
key = event.key
if key == self.actions["left"]:
self.dx -= self.AGENT_SPEED
if key == self.actions["right"]:
self.dx += self.AGENT_SPEED
if key == self.actions["up"]:
self.dy -= self.AGENT_SPEED
if key == self.actions["down"]:
self.dy += self.AGENT_SPEED
示例15: _handle_player_events
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYDOWN [as 别名]
def _handle_player_events(self):
self.dx = 0.0
self.dy = 0.0
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
key = event.key
if key == self.actions["left"]:
self.dx -= self.AGENT_SPEED
if key == self.actions["right"]:
self.dx += self.AGENT_SPEED
if key == self.actions["up"]:
self.dy -= self.AGENT_SPEED
if key == self.actions["down"]:
self.dy += self.AGENT_SPEED