本文整理汇总了Python中menu.Menu.event_handler方法的典型用法代码示例。如果您正苦于以下问题:Python Menu.event_handler方法的具体用法?Python Menu.event_handler怎么用?Python Menu.event_handler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类menu.Menu
的用法示例。
在下文中一共展示了Menu.event_handler方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import event_handler [as 别名]
#.........这里部分代码省略.........
self.running = False
self.win_message = False
elif self.about_menu:
self.screen.blit(images["intro"],(0,0))
text = self.text_font.render("Author: Eduardo Alejandro Grando",True,(128,128,255))
screen.blit(text,(30,0))
text = self.text_font.render("Platformer graphics: Kenney Vleugels",True,(128,128,255))
screen.blit(text,(5,125))
text = self.text_font.render("press ESC to go back to the menu",True,(128,128,255))
screen.blit(text,(30,300))
elif self.game_over:
self.screen.blit(images["intro"],(0,0))
text = self.text_font.render("GAME OVER",True,(128,128,255))
screen.blit(text,(250,125))
text = self.text_font.render("press ESC to go back to the menu",True,(128,128,255))
screen.blit(text,(30,300))
else:
self.menu.display_frame()
#-------------------------------------------------------------------
def number_image(self,n):
""" return a image with the number given in it. """
if n == 1:
return images["hud_1"]
elif n == 2:
return images["hud_2"]
elif n == 3:
return images["hud_3"]
elif n == 4:
return images["hud_4"]
elif n == 5:
return images["hud_5"]
elif n == 6:
return images["hud_6"]
elif n == 7:
return images["hud_7"]
elif n == 8:
return images["hud_8"]
elif n == 9:
return images["hud_9"]
else:
return images["hud_0"]
#-------------------------------------------------------------------
def eventHandler(self):
flag = False
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
flag = True # Flag that we are done so we exit this loop
pygame.mixer.music.stop()
#---------KEY DOWN EVENTS-----------------------------------
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
self.player.move_left()
elif event.key == pygame.K_RIGHT:
self.player.move_right()
elif event.key == pygame.K_UP:
if self.running:
self.player.jump()
elif event.key == pygame.K_DOWN:
if self.running:
self.player.down()
elif event.key == pygame.K_ESCAPE:
if self.running:
self.running = False
pygame.mixer.music.stop()
self.lives = 3
self.help_menu = False
self.about_menu = False
self.game_over = False
elif event.key == pygame.K_RETURN and not self.running:
if not self.about_menu and not self.game_over:
if self.menu.state == 0:
self.__init__(self.screen)
self.lives = 3
self.running = True
pygame.mixer.music.play(-1)
elif self.menu.state == 1:
self.about_menu = True
else:
self.quitGame = True
if not self.running:
self.menu.event_handler(event)
#---------KEY UP EVENTS-------------------------------------
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
self.player.stop()
elif event.key == pygame.K_RIGHT:
self.player.stop()
if event.type == pygame.MOUSEBUTTONDOWN:
print (self.player.rect.left + abs(self.level.world_shift[0]),
self.player.rect.top - (500 - abs(self.level.world_shift[1])))
if self.quitGame:
flag = True
return flag
示例2: Game
# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import event_handler [as 别名]
#.........这里部分代码省略.........
return images["hud_2"]
elif n == 3:
return images["hud_3"]
elif n == 4:
return images["hud_4"]
elif n == 5:
return images["hud_5"]
elif n == 6:
return images["hud_6"]
elif n == 7:
return images["hud_7"]
elif n == 8:
return images["hud_8"]
elif n == 9:
return images["hud_9"]
else:
return images["hud_0"]
#-------------------------------------------------------------------
def eventHandler(self):
flag = False
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
flag = True # Flag that we are done so we exit this loop
pygame.mixer.music.stop()
#---------KEY DOWN EVENTS-----------------------------------
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
self.player.move_left()
elif event.key == pygame.K_RIGHT:
self.player.move_right()
elif event.key == pygame.K_UP:
if self.running:
self.player.jump()
elif event.key == pygame.K_DOWN:
if self.running:
self.player.down()
elif event.key == pygame.K_ESCAPE:
if self.running:
self.pausa = True
self.running = False
self.menu_menuPausa = False
self.continuar_menuPausa = False
self.menu1 = False
pygame.mixer.music.stop()
elif self.menu1:
self.lives = 2
self.ayuda_menu = False
self.opciones_menu = False
self.game_over = False
elif event.key == pygame.K_RETURN and not self.running:
if self.menu1 :
if not self.opciones_menu and not self.ayuda_menu and not self.game_over:
if self.menu.state == 0:
self.__init__(self.screen)
self.lives = 2
self.running = True
pygame.mixer.music.play(-1)
elif self.menu.state == 1:
self.opciones_menu = True
self.running = False
elif self.menu.state == 2:
self.ayuda_menu = True
else:
self.quitGame = True
#self.menu = False
if self.pausa :
if not self.menu_menuPausa and not self.game_over:
if self.menuPausa.state == 0:
# self.__init__(self.screen)
#self.lives = 2
self.running = True
pygame.mixer.music.play(-1)
elif self.menuPausa.state == 1:
self.menu_menuPausa = True
#self.menuPausa = False
if not self.running:
if self.menu1:
self.menu.event_handler(event)
if self.pausa:
self.menuPausa.event_handler(event)
#---------KEY UP EVENTS-------------------------------------
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
self.player.stop()
elif event.key == pygame.K_RIGHT:
self.player.stop()
if event.type == pygame.MOUSEBUTTONDOWN:
print (self.player.rect.left + abs(self.level.world_shift[0]),
self.player.rect.top - (500 - abs(self.level.world_shift[1])))
if self.quitGame:
flag = True
return flag