本文整理汇总了Python中pygame.K_g方法的典型用法代码示例。如果您正苦于以下问题:Python pygame.K_g方法的具体用法?Python pygame.K_g怎么用?Python pygame.K_g使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame
的用法示例。
在下文中一共展示了pygame.K_g方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_g [as 别名]
def update(self, events, screen):
""" To integrate with the main program.
Call it once per frame after drawing is done.
"""
for event in events:
if event.type == pg.KEYDOWN:
if event.key == pg.K_g and not self.start_saving:
self.start_saving = time.time()
self.finished_saving = False
print("recording surfs, press g")
elif event.key == pg.K_g and self.start_saving:
self.start_saving = False
self.finished_saving = True
if self.finished_saving:
self.finish()
if self.start_saving:
self.surfs.append(screen.copy())
if self.seconds is not None:
if time.time() - self.start_saving > self.seconds:
self.finish()
示例2: key_event_up
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_g [as 别名]
def key_event_up(event):
global penSize, undoed, holdingCTRL, colorScheme, selectedTool
if event.key == pg.K_1:
colorScheme = 1
elif event.key == pg.K_2:
colorScheme = 2
if event.key == pg.K_e:
selectedTool = 1
B_Buttons[1].clicked = True
for subbutton in B_Buttons:
if B_Buttons.index(subbutton) != selectedTool:
subbutton.clicked = False
elif event.key == pg.K_b:
selectedTool = 0
B_Buttons[0].clicked = True
for subbutton in B_Buttons:
if B_Buttons.index(subbutton) != selectedTool:
subbutton.clicked = False
elif event.key == pg.K_g:
selectedTool = 2
B_Buttons[2].clicked = True
for subbutton in B_Buttons:
if B_Buttons.index(subbutton) != selectedTool:
subbutton.clicked = False
elif event.key == pg.K_i:
selectedTool = 3
B_Buttons[3].clicked = True
for subbutton in B_Buttons:
if B_Buttons.index(subbutton) != selectedTool:
subbutton.clicked = False
if event.key == pg.K_LCTRL:
holdingCTRL = False
if event.key == pg.K_SPACE:
if holdingCTRL:
g1.clean()
undoed = True
if event.key == pg.K_s:
if holdingCTRL:
shortcutPath = FileManager(1)
SaveFile(g1, shortcutPath)
if event.key == pg.K_z:
if holdingCTRL:
for i in range(g1.yCount):
for j in range(g1.xCount):
if round == 1:
g1.change_color(j, i, g1.undoList[1][i][j])
if round == -1:
g1.change_color(j, i, g1.undoList[0][i][j])
undoed = True
示例3: run
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import K_g [as 别名]
def run(self):
# The main game loop
#
while True:
# Limit frame speed to 30 FPS
#
time_passed = self.clock.tick(30)
#~ time_passed = self.clock.tick()
#~ print time_passed
# If too long has passed between two frames, don't
# update (the game must have been suspended for some
# reason, and we don't want it to "jump forward"
# suddenly)
#
if time_passed > 100:
continue
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.quit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
self.paused = not self.paused
elif event.key == pygame.K_g:
if pygame.key.get_mods() & pygame.KMOD_CTRL:
self.options['draw_grid'] = not self.options['draw_grid']
elif ( event.type == pygame.MOUSEBUTTONDOWN and
event.button == 1):
for creep in self.creeps:
creep.mouse_click_event(event.pos)
if not self.paused:
msg1 = 'Creeps: %d' % len(self.creeps)
msg2 = ''
self.mboard_text = [msg1, msg2]
self.creep_spawn_timer.update(time_passed)
# Update and all creeps
for creep in self.creeps:
creep.update(time_passed)
self.draw()
pygame.display.flip()