Esempio n. 1
0
    def process_action():
        if GameModel.mode == ModeType.MENU:
            if KeyboardController.pending():
                action = KeyboardController.grab()

                # Resume Game
                if action == KEYS.K_1 or action == KEYS.K_ESCAPE:
                    GameModel.mode = ModeType.MAP
                    Window.hide_view(ModeType.MENU)
                # Handling arrows here
                # They are put back in front in case arrows are held down
                elif action == KEYS.K_UP:
                    MenuModel.select_prev_item()
                    # KeyboardController.restore(action)
                elif action == KEYS.K_DOWN:
                    MenuModel.select_next_item()
                    # KeyboardController.restore(action)
                elif action == KEYS.K_LEFT:
                    pass
                    # TODO journal menu
                elif action == KEYS.K_RIGHT:
                    pass
                    # TODO journal menu
                # Handling other keys

                selected_item = MenuModel.get_selected_item()
                if selected_item is not None:
                    selected_item.handle_key_press(action)
Esempio n. 2
0
def main():
    clock = pygame.time.Clock()

    # model = GameModel()
    window = Window()
    window.draw()

    GameModel.on_start()
    MapView.update()
    window.show_view(ModeType.MAP)
    window.show_view(ModeType.MENU)

    print("1 to hide initial menu")
    print("Esc to toggle menu")
    print("J to toggle Journal")

    running = True
    while running:
        # Keep the loop running at roughly 16 FPS.
        # TODO: Is there a better way to handle this?
        clock.tick(FPS)

        # Controller Tick - Handle Input
        running = KeyboardController.handle_input()

        if running:
            # System Tick - Update Model
            update_controllers()
            # View Tick - Update View
            update_views()
Esempio n. 3
0
    def process_action():
        if GameModel.mode == ModeType.MENU:
            if KeyboardController.pending():
                action = KeyboardController.grab()

                # Resume Game
                if action == KEYS.K_1 or action == KEYS.K_ESCAPE:
                    GameModel.mode = ModeType.MAP
                    Window.hide_view(ModeType.MENU)

                # Handling arrows here
                # They are put back in front in case arrows are held down
                elif action == KEYS.K_UP:
                    KeyboardController.restore(action)
                elif action == KEYS.K_DOWN:
                    KeyboardController.restore(action)
                elif action == KEYS.K_LEFT:
                    KeyboardController.restore(action)
                elif action == KEYS.K_RIGHT:
                    KeyboardController.restore(action)
Esempio n. 4
0
    def process_action():
        if GameModel.mode == ModeType.MAP:
            if KeyboardController.pending():
                action = KeyboardController.grab()
                
                player = PlayerModel.get_player()
                # Open Menu
                if action == KEYS.K_ESCAPE:
                    GameModel.mode = ModeType.MENU
                    Window.show_view(ModeType.MENU)

                # Open Journal
                elif action == KEYS.K_j:
                    GameModel.mode = ModeType.JOURNAL
                    Window.show_view(ModeType.JOURNAL)

                # Handling arrows here
                # They are put back in front in case arrows are held down
                elif action == KEYS.K_UP:
                    print("PlayerController: process_action - Trying to move up")
                    print("Can I move up? - ", player.move(Direction.ABOVE))
                    print("New coords: col, row - ", player._location.col, player._location.row)
                    KeyboardController.restore(action)
                elif action == KEYS.K_DOWN:
                    print("PlayerController: process_action - Trying to move down")
                    print("Can I move down? - ",player.move(Direction.BELOW))
                    print("New coords: col, row - ", player._location.col, player._location.row)
                    KeyboardController.restore(action)
                elif action == KEYS.K_LEFT:
                    print("PlayerController: process_action - Trying to move left")
                    print("Can I move left? - ",player.move(Direction.LEFT))
                    print("New coords: col, row - ", player._location.col, player._location.row)
                    KeyboardController.restore(action)
                elif action == KEYS.K_RIGHT:
                    print("PlayerController: process_action - Trying to move right")
                    print("Can I move right? - ",player.move(Direction.RIGHT))
                    print("New coords: col, row - ", player._location.col, player._location.row)
                    KeyboardController.restore(action)
Esempio n. 5
0
    def process_action():
        if GameModel.mode == ModeType.JOURNAL:
            if KeyboardController.pending():
                action = KeyboardController.grab()

                # Resume Game
                if action == KEYS.K_j:
                    GameModel.mode = ModeType.MAP
                    Window.hide_view(ModeType.JOURNAL)

                # Handling arrows here
                # They are put back in front in case arrows are held down
                elif action == KEYS.K_UP:
                    pass
                    # TODO journal menu
                elif action == KEYS.K_DOWN:
                    pass
                    # TODO journal menu
                elif action == KEYS.K_LEFT:
                    pass
                    # TODO journal menu
                elif action == KEYS.K_RIGHT:
                    pass
Esempio n. 6
0
def main():
    clock = pygame.time.Clock()

    # model = GameModel()
    window = Window()
    window.draw(fullscreen=False)

    GameModel.on_start()
    MenuModel.initialize()
    MapView.update_view()
    window.show_view(ModeType.MAP)
    window.show_view(ModeType.MENU)

    player = PlayerModel.get_player()

    print("1 to hide initial menu")
    print("Esc to toggle menu")
    print("J to toggle Journal")

    logger.info("Entering event loop")
    while GameModel.running:
        if not options.noclip:
            player.move(Direction.BELOW)
            player.reorient()

        # Keep the loop running at roughly 16 FPS.
        # TODO: Is there a better way to handle this?
        clock.tick(FPS)

        # Controller Tick - Handle Input
        GameModel.running = KeyboardController.handle_input()

        if GameModel.running:
            if not options.noclip:
                player.move(Direction.BELOW)
                player.reorient()
            # System Tick - Update Model
            update_controllers()
            # View Tick - Update View
            update_views()
Esempio n. 7
0
    def process_action():
        if GameModel.mode == ModeType.MAP:
            if KeyboardController.pending():
                action = KeyboardController.grab()

                player = PlayerModel.get_player()
                # Open Menu
                if action == KEYS.K_ESCAPE:
                    GameModel.mode = ModeType.MENU
                    Window.show_view(ModeType.MENU)

                # Open Journal
                elif action == KEYS.K_j:
                    GameModel.mode = ModeType.JOURNAL
                    Window.show_view(ModeType.JOURNAL)

				# Select Tools (Hand, Pickaxe, Pickaxe, Drill, TNT)
				elif action == KEYS.K_SPACE:
					logger.debug(
                        "PlayerController: process_action - Switch tool to hand"
                    )
					player.select_tool(ToolType.HAND)
				
				elif action == KEYS.K_p:
					logger.debug(
                        "PlayerController: process_action - Switch tool to Pickaxe"
                    )
					player.select_tool(ToolType.PICKAXE)
				
				elif action == KEYS.K_a:
					logger.debug(
                        "PlayerController: process_action - Switch tool to Pickaxe"
                    )
					player.select_tool(ToolType.PICKAXE)

				elif action == KEYS.K_d:
					logger.debug(
                        "PlayerController: process_action - Switch tool to drill"
                    )
					player.select_tool(ToolType.DRILL)
				
				elif action == KEYS.K_t:
					logger.debug(
                        "PlayerController: process_action - Switch tool to TNT"
                    )
					player.select_tool(ToolType.TNT)

                # Handling arrows here
                # They are put back in front in case arrows are held down
                elif action == KEYS.K_UP:
                    logger.debug(
                        "PlayerController: process_action - Trying to move up"
                    )
                    logger.debug(f"Can I move up? - {player.move(Direction.ABOVE)}")
                    logger.debug(
                        "New coords: col, row - "
                        f"{player._location.col}"
                        f"{player._location.row}"
                    )
                elif action == KEYS.K_DOWN:
                    logger.debug(
                        "PlayerController: process_action - Trying to move down"
                    )
                    logger.debug(f"Can I move down? - {player.move(Direction.BELOW)}")
                    logger.debug(
                        "New coords: col, row - "
                        f"{player._location.col}"
                        f"{player._location.row}"
                    )
                elif action == KEYS.K_LEFT:
                    logger.debug(
                        "PlayerController: process_action - Trying to move left"
                    )
                    logger.debug(f"Can I move left? - {player.move(Direction.LEFT)}")
                    logger.debug(
                        "New coords: col, row - "
                        f"{player._location.col}"
                        f"{player._location.row}"
                    )
                elif action == KEYS.K_RIGHT:
                    logger.debug(
                        "PlayerController: process_action - Trying to move right"
                    )
                    logger.debug(f"Can I move right? - {player.move(Direction.RIGHT)}")
                    logger.debug(
                        "New coords: col, row - "
                        f"{player._location.col}"
                        f"{player._location.row}"
                    )