Ejemplo 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)
Ejemplo n.º 2
0
    def update_view(cls):
        # Load latest view
        cls.view = Window.get_view(ModeType.MAP)

        if cls.view.empty:
            cls.redraw_map()
        else:
            # Get MapModel update info
            updates = MapModel.get_updates()

            for coord in updates:
                # Passing que into this as so far MapView is just
                # functions, and unsure if que is something that needs
                # be saved between calls.
                MapView.redraw(coord)

        # TODO: Render sprite next using separate functions
        PlayerView.get_primary().draw(cls.view.surface)

        cls.section = Section(
            PlayerModel.get_player()._location.col
            // cls.section.res.blocks_across
            + 1
        )

        Window.update_view()
Ejemplo n.º 3
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()
Ejemplo n.º 4
0
    def update(cls):
        # Load latest view
        cls.view = Window.get_view(ModeType.PUZZLE)
        #cls.view.surface.fill(color.BLACK)
        #Window._draw_shadow()

        rendered_problem = cls.draw_puzzle()
        problem_display_area = rendered_problem.get_rect()
        cls.view.blit(rendered_problem, problem_display_area)
Ejemplo n.º 5
0
    def update_view(cls):
        cls.view = Window.get_view(ModeType.MENU)
        Window.add_shadow_under(ModeType.MENU)  # TEMPORARY ONLY!
        cls.view.surface.fill(Color.WOOD)

        cls.menu = MenuModel.get_menu()
        cls._draw_text(
            row=0,
            text=cls.menu.title.text,
            text_attributes=cls.menu.title.text_attributes,
        )
        for row, item in enumerate(cls.menu.items, start=1):
            if isinstance(item, diamondquest.model.menu.ButtonItem):
                cls._draw_item_background(row)

            cls._draw_text(row, item.text, item.text_attributes)

            if row == cls.menu.selected_item_idx + 1:
                cls._draw_highlight(row)
Ejemplo n.º 6
0
    def update(cls):
        # Load latest view
        cls.view = Window.get_view(ModeType.MAP)

        if cls.view.empty:
            cls.redraw_map()
        else:
            # Get MapModel update info
            updates = MapModel.get_updates()

            for coord in updates:
                # Passing que into this as so far MapView is just
                # functions, and unsure if que is something that needs
                # be saved between calls.
                MapView.redraw(coord)

        # TODO: Render sprite next using separate functions

        Window.update()
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
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
Ejemplo n.º 10
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()
Ejemplo n.º 11
0
 def update(cls):
     cls.view = Window.get_view(ModeType.JOURNAL)
     Window.add_shadow_under(ModeType.JOURNAL)  # TEMPORARY ONLY!
     cls.view.surface.fill(Color.WHITE)
Ejemplo n.º 12
0
 def update(cls):
     cls.view = Window.get_view(ModeType.MENU)
     Window.add_shadow_under(ModeType.MENU)  # TEMPORARY ONLY!
     cls.view.surface.fill(Color.WOOD)
Ejemplo n.º 13
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}"
                    )