示例#1
0
    def test_play_all(self):
        self.item = pgl_board_items.NPC(model="-o-", name="Dancer")
        self.animation = gfx_core.Animation(parent=self.item,
                                            refresh_screen=self.redraw,
                                            display_time=0.5)
        self.animation.add_frame("-o-")
        self.animation.add_frame("\\o-")
        self.animation.add_frame("\\o\\")
        self.animation.add_frame("|o|")
        self.assertTrue(self.animation.play_all())
        self.animation.pause()
        self.assertFalse(self.animation.play_all())
        self.animation.stop()
        self.assertFalse(self.animation.play_all())
        self.animation = gfx_core.Animation(parent="breaking",
                                            refresh_screen=self.redraw,
                                            display_time=0.5)
        with self.assertRaises(Exception) as context:
            self.animation.play_all()
        self.assertTrue(
            "needs to be a sub class of BoardItem" in str(context.exception))

        self.animation = gfx_core.Animation(parent=self.item,
                                            refresh_screen="breaking",
                                            display_time=0.5)
        with self.assertRaises(Exception) as context:
            self.animation.play_all()
        self.assertTrue("needs to be a callback function reference" in str(
            context.exception))
示例#2
0
 def test_create_animation(self):
     self.item = pgl_board_items.NPC(model="-o-", name="Dancer")
     self.animation = gfx_core.Animation(parent=self.item,
                                         refresh_screen=self.redraw,
                                         display_time=0.5)
     self.assertEqual(self.item.name, self.animation.parent.name)
     a = gfx_core.Animation(
         animated_object=self.item,
         refresh_screen=self.redraw,
         display_time=0.5,
         initial_index=2,
     )
     self.assertEqual(a._initial_index, 2)
     a.reset()
     self.assertEqual(a._initial_index, a._frame_index)
     col = gfx_core.SpriteCollection()
     col.add(gfx_core.Sprite(name="s1"))
     col.add(gfx_core.Sprite(name="s2"))
     i = pgl_board_items.ComplexNPC(sprite=col["s1"])
     a = gfx_core.Animation(frames=col, parent=i)
     i.animation = a
     self.assertIsInstance(a, gfx_core.Animation)
     self.assertEqual(len(a.frames), 2)
     # I shouldn't test that here but I'm tired of writting test!
     self.assertIsInstance(a.next_frame(), gfx_core.Sprite)
示例#3
0
    def test_projectile(self):
        with self.assertRaises(board_items.base.PglException) as e:
            board_items.Projectile(range=6, step=4)
        self.assertEqual(e.exception.error, "incorrect_range_step")
        p = board_items.Projectile()
        self.assertFalse(p.has_inventory())
        self.assertTrue(p.overlappable())
        self.assertTrue(p.restorable())
        # Directional animations
        p.add_directional_animation(constants.DOWN, gfx_core.Animation())
        with self.assertRaises(board_items.base.PglInvalidTypeException):
            p.add_directional_animation("crash", gfx_core.Animation())
        with self.assertRaises(board_items.base.PglInvalidTypeException):
            p.add_directional_animation(constants.DOWN, "crash")
        with self.assertRaises(board_items.base.PglInvalidTypeException):
            p.directional_animation("crash")
        self.assertIsInstance(
            p.directional_animation(constants.DOWN), gfx_core.Animation
        )
        self.assertIsNone(p.directional_animation(constants.UP))
        p.movement_animation = gfx_core.Animation()
        self.assertIsInstance(p.directional_animation(constants.UP), gfx_core.Animation)
        with self.assertRaises(board_items.base.PglInvalidTypeException):
            p.remove_directional_animation("crash")
        self.assertIsNone(p.remove_directional_animation(constants.DOWN))
        # Directional models
        p.add_directional_model(constants.DOWN, "|")
        with self.assertRaises(board_items.base.PglInvalidTypeException):
            p.add_directional_model("crash", "|")
        with self.assertRaises(board_items.base.PglInvalidTypeException):
            p.add_directional_model(constants.DOWN, 1)
        with self.assertRaises(board_items.base.PglInvalidTypeException):
            p.directional_model("crash")
        self.assertEqual(p.directional_model(constants.DOWN), "|")
        self.assertEqual(p.directional_model(constants.UP), "⌁")
        with self.assertRaises(board_items.base.PglInvalidTypeException):
            p.remove_directional_model("crash")
        self.assertIsNone(p.remove_directional_model(constants.DOWN))
        with self.assertRaises(board_items.base.PglInvalidTypeException):
            p.set_direction("crash")
        self.assertIsNone(p.set_direction(constants.DOWN))
        p.animation = gfx_core.Animation()
        p.hit_model = "*"
        self.assertIsNone(p.hit([board_items.BoardItemVoid]))

        def _r():
            pass

        p.hit_animation = gfx_core.Animation(refresh_screen=_r, parent=p)
        self.assertIsNone(p.hit([board_items.BoardItemVoid]))

        def _cb(p, o, params):
            return True

        p.hit_callback = _cb
        self.assertIsNone(p.hit([board_items.BoardItemVoid]))
示例#4
0
 def test_stop(self):
     self.item = pgl_board_items.NPC(model="-o-", name="Dancer")
     self.animation = gfx_core.Animation(parent=self.item,
                                         refresh_screen=self.redraw,
                                         display_time=0.5)
     self.animation.stop()
     self.assertEqual(self.animation.state, pgl_constants.STOPPED)
示例#5
0
 def test_next_frame(self):
     self.item = pgl_board_items.NPC(model="-o-", name="Dancer")
     self.animation = gfx_core.Animation(parent=self.item,
                                         refresh_screen=self.redraw,
                                         display_time=0.5)
     self.animation.add_frame("-o-")
     self.animation.add_frame("\\o-")
     self.animation.add_frame("\\o\\")
     self.animation.add_frame("|o|")
     self.assertEqual(self.animation.next_frame(), "\\o-")
     self.animation.pause()
     self.assertEqual(self.animation.next_frame(), "\\o-")
     self.animation.stop()
     self.assertIsNone(self.animation.next_frame())
     self.animation.start()
     self.animation.next_frame()
     self.animation.next_frame()
     self.animation.next_frame()
     self.animation.reset()
     self.animation.auto_replay = False
     self.animation.next_frame()
     self.animation.next_frame()
     self.animation.next_frame()
     self.animation.next_frame()
     self.animation.next_frame()
     self.assertEqual(self.animation._frame_index, 3)
     self.animation.parent = "This is going to break!"
     with self.assertRaises(Exception) as context:
         self.animation.next_frame()
     self.assertTrue(
         "needs to be a sub class of BoardItem" in str(context.exception))
示例#6
0
 def test_dtdisplay(self):
     a = gfx_core.Animation()
     a.dtanimate = 1.0
     self.assertEqual(a.dtanimate, 1.0)
     a.dtanimate = 1
     self.assertEqual(a.dtanimate, 1)
     with self.assertRaises(pgl_base.PglInvalidTypeException):
         a.dtanimate = "1.0"
示例#7
0
 def test_add_frame(self):
     self.item = pgl_board_items.NPC(model="-o-", name="Dancer")
     self.animation = gfx_core.Animation(parent=self.item,
                                         refresh_screen=self.redraw,
                                         display_time=0.5)
     self.animation.add_frame("\\o-")
     with self.assertRaises(Exception) as context:
         self.animation.add_frame(2)
     self.assertTrue("must be a string" in str(context.exception))
示例#8
0
 def test_current_frame(self):
     self.item = pgl_board_items.NPC(model="-o-", name="Dancer")
     self.animation = gfx_core.Animation(parent=self.item,
                                         refresh_screen=self.redraw,
                                         display_time=0.5)
     self.animation.add_frame("-o-")
     self.animation.add_frame("\\o-")
     self.animation.add_frame("\\o\\")
     self.animation.add_frame("|o|")
     self.assertEqual(self.animation.current_frame(), "-o-")
     self.animation.next_frame()
     self.assertEqual(self.animation.current_frame(), "\\o-")
示例#9
0
 def test_with_sprixel(self):
     i = pgl_board_items.NPC(sprixel=gfx_core.Sprixel())
     i.animation = gfx_core.Animation(parent=i)
     i.animation.add_frame(gfx_core.Sprixel("-"))
     i.animation.add_frame(gfx_core.Sprixel("+"))
     self.assertIsInstance(i.animation, gfx_core.Animation)
     self.assertEqual(len(i.animation.frames), 2)
     # I shouldn't test that here but I'm tired of writting test!
     self.assertIsInstance(i.animation.next_frame(), gfx_core.Sprixel)
     i.animation.frames[1] = pgl_base.Vector2D()
     with self.assertRaises(pgl_base.PglInvalidTypeException):
         i.animation.next_frame()
         i.animation.next_frame()
示例#10
0
 def test_remove_frame(self):
     self.item = pgl_board_items.NPC(model="-o-", name="Dancer")
     self.animation = gfx_core.Animation(parent=self.item,
                                         refresh_screen=self.redraw,
                                         display_time=0.5)
     self.animation.add_frame("-o-")
     self.animation.add_frame("\\o-")
     self.animation.add_frame("\\o\\")
     self.animation.add_frame("|o|")
     self.animation.add_frame("/o/")
     self.animation.add_frame("-o/")
     with self.assertRaises(Exception) as context:
         self.animation.remove_frame(999)
     self.assertTrue("out of range" in str(context.exception))
     self.assertEqual(self.animation.remove_frame(0), "-o-")
     self.animation.next_frame()
     self.animation.next_frame()
     self.assertEqual(self.animation.remove_frame(2), "|o|")
     self.assertEqual(self.animation.current_frame(), "\\o\\")
     self.assertEqual(self.animation.next_frame(), "/o/")
     with self.assertRaises(gfx_core.base.PglInvalidTypeException):
         self.animation.remove_frame("999")
示例#11
0
    elif key == "2":
        viewport = [15, 30]
        g.partial_display_viewport = viewport
    elif key == "3":
        viewport = [20, 20]
        g.partial_display_viewport = viewport
    if key == " ":
        if g.player.mp >= 4:
            fireball = board_items.Projectile(
                name="fireball",
                model=base.Text.red_bright(black_circle),
                hit_model=graphics.Models.COLLISION,
            )
            fireball.animation = core.Animation(
                auto_replay=True,
                animated_object=fireball,
                refresh_screen=None,
                display_time=0.5,
            )
            fireball.animation.add_frame(base.Text.red_bright(black_circle))
            fireball.animation.add_frame(base.Text.red_bright(circle_jot))
            fireball.range = 7
            fireball.set_direction(constants.RIGHT)
            g.add_projectile(1, fireball, g.player.pos[0], g.player.pos[1] + 1)
            g.player.mp -= 4

    elif key == engine.key.UP:
        g.move_player(constants.UP, 1)
    elif key == engine.key.DOWN:
        g.move_player(constants.DOWN, 1)
    elif key == engine.key.LEFT:
        g.move_player(constants.LEFT, 1)