当前位置: 首页>>代码示例>>Python>>正文


Python Menu.isActive方法代码示例

本文整理汇总了Python中Menu.Menu.isActive方法的典型用法代码示例。如果您正苦于以下问题:Python Menu.isActive方法的具体用法?Python Menu.isActive怎么用?Python Menu.isActive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Menu.Menu的用法示例。


在下文中一共展示了Menu.isActive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Menu import Menu [as 别名]
# 或者: from Menu.Menu import isActive [as 别名]

#.........这里部分代码省略.........
        self.GameFeatures = {}

        return True
    #============================================================================================    
    def Loop(self):    
        """Game loop: Look for events and handle them, update game objects, draw game objects"""
        RunLoop = True
        while(RunLoop == True):    
            EventRunLoop = self._UserEventHandle()
            if not self.freeze:
                UpdateRunLoop = self._Update()
            DrawLoop = self._Draw()
            RunLoop = EventRunLoop and UpdateRunLoop and DrawLoop

    def _UserEventHandle(self):
        EventRunLoop = True
        for event in pygame.event.get():
            EventRunLoop = (EventRunLoop and self._HandleEvent(event))
        return EventRunLoop
    
    def _Update(self):
        self.clock.tick(self.clockrate)
        UpdateRunLoop = self.UpdateGameObjects()
        return UpdateRunLoop

    def _Draw(self):
        DrawRunLoop = self.DrawGameObjects()
        pygame.display.flip()
        self.screen.blit(self.background, (0, 0))
        return DrawRunLoop
    
    def _HandleEvent(self, event):
        """Decides whether to handle menu type events or game type events"""
        if self.Menu.isActive():
            menuEvent = self.Menu.HandleEvent(event)
            return self.HandleMenuEvent(menuEvent)
        else:
            return self.HandleGameEvent(event)

    def HandleMenuEvent(self, menuEvent):
        """When the game menu is activated, this replaces the event handling loop"""
        if menuEvent == True:
            return True
        if menuEvent == False:
            return False
        if menuEvent == "Exit":
            return False
        if menuEvent == "Continue":
            self.unPauseGame()
            self.Menu.Deactivate()
            return True
        if menuEvent == "NewGame":
            self.unPauseGame()
            self.Menu.Deactivate()
            self.Init()
            return True

    def HandleGameEvent(self, event):
        """Overwrite with function to handle all in-game events"""    
        if event.type == QUIT:
            print "Requesting quit"
            return False         
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                self.PauseGame()
                print "Pausing and navigating to menu"
开发者ID:keerthik,项目名称:KRPEngine,代码行数:70,代码来源:Game.py

示例2: Game

# 需要导入模块: from Menu import Menu [as 别名]
# 或者: from Menu.Menu import isActive [as 别名]
class Game():
    FPS = 60
    SCREEN_SIZE = (1280, 720)
    WHITE = (255, 255, 255)
    GREEN = (0, 255, 0)
    DARK_GREY = (10, 10, 10)
    MUSIC_FILE = 'data/singsingsing.ogg'
    
    def __init__(self):
        pygame.init()
        self.font = pygame.font.SysFont('sans-serif', 18, True)
        self.surface = pygame.display.set_mode(self.SCREEN_SIZE, 0, 32)
        self.state = 'intro'
        self.hiscores = Score.read_high_score()
        self.menu = Menu(("Start game", "Quit"))
        pygame.mixer.music.load(self.MUSIC_FILE)
        pygame.mixer.music.play(-1)
        
    def start(self):
        while True:
            if self.state == 'intro':
                # Show the intro and when it's done we move directly to game state
                intro = Intro(pygame, self.surface);
                new_state = intro.show()
                self.state = new_state
            elif self.state == 'menu':
                # Show the menu and run the menu loop
                self.hiscores = Score.read_high_score()
                self.show_menu()
            elif self.state == 'game':
                # Run a game and run the game loop
                self.load_level()
                self.game_loop()
            elif self.state == 'quit':
                # Quit, we're done.
                pygame.quit()
                sys.exit()
    
    # Contains the main menu loop and handles starting and quitting while showing the high scores
    def show_menu(self):
        pygame.mouse.set_visible(1)
        self.menu.drawMenu()
        while True:
            pygame.time.Clock().tick(self.FPS)
            for event in pygame.event.get():
                self.menu.handleEvent(event)
                if event.type == Menu.MENUCLICKEDEVENT or event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
                    if event.text == "Quit":
                        self.state = 'quit'
                        return
                    elif event.text == 'Start game':
                        self.state = 'game'
                        self.menu.deactivate()
                        return
                elif event.type == KEYDOWN and event.key == K_RETURN:
                    self.state = 'game'
                    self.menu.deactivate()
                    return
                        
            if self.menu.isActive():
                self.menu.drawMenu()
                
            Score.draw_high_scores(self.hiscores, self.surface)
            pygame.display.flip()
        
    # Loads and resets a level    
    def load_level(self):
        self.up = False
        self.speed = 6
        self.nameinput = None
        self.level = Level(self)
    
    # The main game loop that updates the level as the game progresses
    def game_loop(self):
        pygame.mouse.set_visible(0)
        while True:
            pygame.time.Clock().tick(self.FPS)
            events = pygame.event.get()
            for event in events:
                if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
                    self.state = 'quit'
                    return
                elif self.state == 'game':
                    if event.type == KEYDOWN:
                        if event.key == K_UP:
                            self.up = True
                    if event.type == KEYUP:
                        if event.key == K_UP:
                            self.up = False
                elif self.state == 'gameover':
                    if event.type == KEYUP:
                        if event.key == K_RETURN:
                            if self.nameinput != None:
                                name = self.nameinput.value
                                if name == '':
                                    name = 'no name'
                                Score.update_highscore(name, self.level.get_score(), self.hiscores)
                            self.state = 'menu'
                            return
             
#.........这里部分代码省略.........
开发者ID:span,项目名称:taxrunner,代码行数:103,代码来源:Game.py


注:本文中的Menu.Menu.isActive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。