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


Python Menu.tick方法代码示例

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


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

示例1: test_main_menu

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import tick [as 别名]
 def test_main_menu(self):
     csvfile = "main_menu.csv"
     main_menu = Menu(self, csvfile)
     main_menu.tick()
开发者ID:atowneND,项目名称:paradigms,代码行数:6,代码来源:main.py

示例2: Game

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import tick [as 别名]
class Game(Enableable, Completable, Inputable):
    def __init__(self, levels):
        super().__init__()

        # --- Inits
        os.environ["SDL_VIDEO_CENTERED"] = "1"
        pygame.mixer.pre_init(44100, 16, 2, 4096)
        pygame.init()
        pygame.font.init()

        pygame.display.set_caption(const.gameName)
        self._surface = pygame.display.set_mode((const.screenSize[0] * const.res,
                                                 const.screenSize[1] * const.res))
        self._clock = pygame.time.Clock()
        self._levAttr = levels
        self._world = None
        self._paused = False

        self._menu = Menu(surface=self._surface,
                          pos=(const.screenSize[0] * const.res / 2 - 50,
                               const.screenSize[1] * const.res / 2 - 100),
                          inputStream=self.getInputStream())
        self._menu.addItem("resume", (0, 0, 100, 48), MColor((255, 0, 0), (0, 0, 255)),
                           MText("Resume", (0, 255, 0)), MAction(self._resume))
        self._menu.addItem("start", (0, 50, 100, 48), MColor((255, 0, 0), (0, 0, 255)),
                           MText("Start", (0, 255, 0)), MAction(self.start))
        self._menu.addItem("editor", (0, 100, 100, 48), MColor((255, 0, 0), (0, 0, 255)),
                           MText("Editor", (0, 255, 0)), MAction(self._editor))
        self._menu.addItem("exit", (0, 150, 100, 48), MColor((255, 0, 0), (0, 0, 255)),
                           MText("Exit", (0, 255, 0)), MAction(self.setFinished))

        self._input = Input(inputStream=self.getInputStream())
        self._input.set(pygame.KEYDOWN, self._menuToggle, pygame.K_m)
        self._input.set(pygame.KEYDOWN, self._pause, pygame.K_p)

    def start(self):
        self.enable()
        self._world = World(self._surface, self._levAttr, inputStream=self.getInputStream())
        self._world.nextLevel()
        self._menu.disable()

    def _pause(self):
        self._paused = not self._paused

    def _resume(self):
        if self._world is not None and not self._world.isComplete():
            self.enable()
        else:
            self.start()
        self._menu.disable()

    def _editor(self):
        if self._world:
            self._world.level.editor.enabled()
            self._menu.disable()

    def _menuToggle(self):
        self._menu.toggleEnabled()
        self.toggleEnabled()

    def tick(self):
        self.getEvents()
        self._input()

        if self._menu.enabled():
            self._menu.tick()
            self._menu.draw()
        elif self.enabled:
            if self._world.isComplete():
                if self._world.isFinished():
                    self._win()
                elif self._world.isLost():
                    self._gameOver()
            else:
                if not self._paused:
                    self._world.tick()
        self.clearInputStream()

        self._clock.tick(const.FPS)
        pygame.display.flip()

    def _win(self):
        self._endGame("YOU WIN!")

    def _gameOver(self):
        self._endGame("GAME OVER!")

    def _endGame(self, text):
        try:
            self.__gameOverCount += 1
        except AttributeError:
            self.__gameOverCount = 1
            self.__goText = pygame.font.Font(None, 100).render(text, 1, (255, 0, 0))
            self.__gameOverX = int(self._surface.get_width() / 2 - self.__goText.get_width() / 2)
            self.__gameOverY = int(self._surface.get_height() / 2 - self.__goText.get_height() / 2)

        if self.__gameOverCount < (const.FPS * 5):
            self._surface.fill((0, 0, 0))
            self._surface.blit(self.__goText, (self.__gameOverX, self.__gameOverY))
        else:
#.........这里部分代码省略.........
开发者ID:DanCardin,项目名称:PyPlatformer,代码行数:103,代码来源:game.py

示例3: __init__

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import tick [as 别名]
class GameSpace:
    def __init__(self, queue, port):
        pygame.init()

        self.size = self.width, self.height = (1400, 600)
        self.black = 0, 0, 0

        self.screen = pygame.display.set_mode(self.size, 0, 32)

        self.mouse_pos = [0,0]

        self.gameStarted = False
        self.gameOver = 0
        self.cease = False
        self.queue = queue

        self.player = 0
        if port == 40084:
            self.player = 1
        else:
            self.player = 2

        self.menu = Menu(self, "main_menu.csv")
        self.menu.tick()
        self.myShip = None
        self.otherShip = None

    def update(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                reactor.stop()
                pygame.quit()
                try:
                    sys.exit()
                except BaseException:
                    pass
                break
            elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
                # http://stackoverflow.com/questions/12150957/pygame-action-when-mouse-click-on-rect
                self.mouse_pos = pygame.mouse.get_pos()
                if self.gameStarted:
                    pass
                    #self.queue.put("DATA DATA DATA")
                else:
                    # Check if any options have been selected in the menus
                    p = self.menu.clickHandler(self.mouse_pos)
                    print p
                    if p == "PLAY":
                        self.menu = Menu(self, "ship_menu.csv")
                        self.menu.tick()
                    elif p == "Blueship" or p == "Cruiser":
                        self.queue.put(p)
                        self.screen.fill(self.black)
                        self.myShip = Ship(self,p.lower(),str(self.player))
                        self.gameStarted = True
        
        # If game over, broadcast winner and show end screen
        if self.gameOver and not self.cease:
            self.queue.put("END " + str(self.gameOver))
            self.gameStarted = False
            self.cease = True
            self.screen.fill(self.black)
            myfont = pygame.font.SysFont("monospace",50)
            label = myfont.render("Player " + str(self.gameOver) + " WINS!", 1, (255,0,0))
            self.screen.blit(label, (650, 300))

        # should everything from here forward be unindented by one block? so multiple events can occur on one tick?
        if self.gameStarted:
            self.screen.fill(self.black)
            self.myShip.tick()
            if self.otherShip != None:
                self.otherShip.tick()

        pygame.display.flip()
        self.mouse_pos = (0,0)
开发者ID:atowneND,项目名称:Paradigms_Final_Project,代码行数:77,代码来源:gamespace.py


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