예제 #1
0
    def HandlePlayerInput(self):
        # Check for player quitting
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.quitFlag = 1
            else:
                if event.type == pygame.MOUSEBUTTONDOWN:
                    self.HandleMouseClick(event)
                if event.type == pygame.MOUSEMOTION:
                    self.HandleMouseMovement(event)

        self.keyInfo = pygame.key.get_pressed()

        try:
            if (self.keyInfo[pygame.K_ESCAPE]):
                #self.quitFlag = 1
                if (self.escapeDebounceFlag == 0):
                    if (Menu.MasterMenu.GetMenuCount() > 0):
                        Menu.MasterMenu.DropMenu()
                    else:
                        if (self.Player.PC.GetCurrentHitPoints() < 1):
                            deathComments = [
                                "You are now an ex-adventurer. Deceased. Ceased to Be.",
                                "Pushing up daisies. Kaput. Finished. There's not much else",
                                "to do except to quit the game or restart.",
                                "YOUR FINAL SCORE IS: %d" %
                                (self.Player.PC.GetMoney() +
                                 self.Player.PC.GetExperience())
                            ]
                            Menu.CreateMainMenu(self.display, deathComments)
                        else:
                            Menu.CreateMainMenu(self.display)

                    self.escapeDebounceFlag = 1
            else:
                self.escapeDebounceFlag = 0

        finally:
            pass
예제 #2
0
    def HandleMenuEvent(self, menu, menuSelection):
        if (menuSelection == "CANCEL"):
            Menu.MasterMenu.DropMenu()
            return

        if (menu.Title.lower() == "main menu"):
            if (menuSelection.lower() == "exit"):
                self.quitFlag = 1
            return

        if (menu.type == "item"):
            desiredMoveTo = (menu.object.position.X -
                             self.Player.PC.position.X,
                             menu.object.position.Y -
                             self.Player.PC.position.Y)
            self.SetPlayerAction(1, menu.menuID, menuSelection, desiredMoveTo,
                                 menu.object)
            Menu.MasterMenu.DropMenu()
            return

        if (menu.type == "monster"):
            desiredMoveTo = (menu.object.position.X -
                             self.Player.PC.position.X,
                             menu.object.position.Y -
                             self.Player.PC.position.Y)
            prox = 1
            if (menuSelection == "Negotiate") or (menuSelection
                                                  == "Cast Spell"):
                prox = 3

            if not (menu.menuID == 0):
                prox = 3
            self.SetPlayerAction(prox, menu.menuID, menuSelection,
                                 desiredMoveTo, menu.object)
            Menu.MasterMenu.DropMenu()
            return

        if (menu.type == "player"):
            menuID = menu.menuID
            menuObject = menu.object
            Menu.MasterMenu.DropMenu()
            if (menuID == 0) and (menuSelection.lower() == "main menu"):
                Menu.CreateMainMenu(self.display)
                return
            self.SetPlayerAction(3, menu.menuID, menuSelection, (0, 0),
                                 menuObject)
            #menuObject.RespondToMenu(menuID,self.Player,menuSelection)
            return
예제 #3
0
    def HandleMouseClick(self, event):
        # Read location and which buttons are down...
        buttonPressed = event.dict["button"]
        posX = event.dict["pos"][0]
        posY = event.dict["pos"][1]

        # First: Check Menus. Menus trump all.
        if (Menu.MasterMenu.GetMenuCount() > 0):
            menuResult = Menu.MasterMenu.CheckUserInteraction(
                buttonPressed, posX, posY)
            if not (menuResult[1] == None):
                self.HandleMenuEvent(menuResult[0], menuResult[1])
            return

        # Next: Check Objects
        if (self.CheckClickOnItems(posX, posY) > 0):
            return

        # Next: Check Monsters
        for monster in self.ActiveAI:
            if (monster.isVisible) and (monster.MouseOnMe(
                    self.display, posX, posY) > 0):
                menu = monster.MakeMenu(0)
                Menu.MasterMenu.AddMenu(menu)
                return

        # Next: Check clicking on self
        if self.Player.MouseOnMe(self.display, posX, posY):
            if (self.Player.PC.GetCurrentHitPoints() < 1):
                deathComments = [
                    "You are now an ex-adventurer. Deceased. Ceased to Be.",
                    "Pushing up daisies. Kaput. Finished. There's not much else",
                    "to do except to quit the game or restart.",
                    "YOUR FINAL SCORE IS: %d" %
                    (self.Player.PC.GetMoney() +
                     self.Player.PC.GetExperience())
                ]
                Menu.CreateMainMenu(self.display, deathComments)
            else:
                menu = self.Player.MakeMenu(0)
                Menu.MasterMenu.AddMenu(menu)
            return

        # Finally: Check Locations
        pos = self.GetMouseToRoomPosition(posX, posY)
        self.SetPlayerAction(0, 0, "move", pos, None)