Пример #1
0
    def test_scene_with_menu(self):
        game = Game("Test",
                    "1.0",
                    "1.0",
                    "testpyvida",
                    fps=16,
                    afps=16,
                    resolution=(1680, 1050))
        game.autoscale = False
        game.working_directory = "/home/luke/Projects/pyvida/test_data"
        mx, my = game.resolution[0] / 2 - 100, 140  # game.resolution[1]-50
        game.add(MenuFactory("menu", (mx, my)))

        game.immediate_menu_from_factory("menu", [
            ("menu_new", MagicMock()),
            ("menu_old", MagicMock()),
        ])

        game.init()
        game.smart()
        game.queue_load_state("title", "initial")
        game.camera.scene("title")
        game.set_menu(*["menu_new", "menu_old"], clear=True)
        game.menu.show()

        game.update()  # run events

        assert game.w == 1680
        assert not game.autoscale
        assert game.scene == game.scenes["title"]
        assert game.scene.layers[0] == "title_background"
        assert game.scene.get_object("logo")
Пример #2
0
class TestEvents:
    def set_up(self):
        self.game = Game("Unit Tests", fps=60, afps=16, resolution=RESOLUTION)
        self.game.settings = Settings()
        self.actor = Actor("_test_actor").smart(self.game)
        self.msgbox = Item("msgbox").smart(self.game,
                                           using="data/items/_test_item")
        self.ok = Item("ok").smart(self.game, using="data/items/_test_item")
        self.scene = Scene("_test_scene")
        self.item = Item("test_item")
        self.game.add(
            [self.scene, self.actor, self.msgbox, self.ok, self.item])
        self.scene.immediate_add(self.actor)
        self.game.scene = self.scene

    def test_relocate(self):
        # setup
        self.set_up()
        self.actor.relocate(self.scene)
        event = self.game.events[0]
        assert len(self.game.events) == 1
        assert event[0].__name__ == "relocate"
        assert event[1] == self.actor
        assert event[2][0] == self.scene