コード例 #1
0
    def test_reset(self):
        animation = Animation(ClockDummy(1), ["img1", "img2"], [1, 1])

        animation.reset()
        self.assertEqual(animation.getSprite(), "img1")
        animation.update()
        animation.reset()
        self.assertEqual(animation.getSprite(), "img1")
コード例 #2
0
    def test_callEndAction(self):
        animation = Animation(ClockDummy(1), ["img1", "img2", "img3"], [1, 1, 1])

        animation.callEndAction()
        self.assertIsNone(animation.getEndAction())
        animation.setEndAction(lambda: None)
        animation.callEndAction()
        self.assertIsNone(animation.getEndAction())
コード例 #3
0
 def spin_up(self, num) -> None:
     self.spin_animations.empty()
     speeds = {3: 10, 4: 5, 5: 2, 6: 1, 7: 1, 8: 1}
     spin_up = Animation(spin_speed=speeds[num],
                         duration=350,
                         round_values=True)
     spin_up.callback = self.spin_down
     spin_up.start(self)
     self.spin_animations.add(spin_up)
コード例 #4
0
 def send_flower(self, new_cell, animations) -> None:
     dist = new_cell.rect.top - self.rect.top
     a = Animation(top=new_cell.rect.top,
                   left=new_cell.rect.left,
                   duration=int(dist * Animation.ANIM_SPEED),
                   round_values=True)
     a.start(self.flower.rect)
     animations.add(a)
     new_cell.flower = self.flower
     self.flower = None
コード例 #5
0
    def test_copy(self):
        clock = ClockDummy(1)
        images = ['img1', 'img2']
        lifeSpans = [1, 1]

        copy = Animation(clock, images, lifeSpans).copy()

        self.assertIs(copy.getClock(), clock)
        self.assertIs(copy.getImages(), images)
        self.assertIs(copy.getLifeSpans(), lifeSpans)
コード例 #6
0
    def test_update_basic(self):
        animation = Animation(ClockDummy(1), ["img1", "img2", "img3"], [1, 1, 1])

        self.assertEqual(animation.getSprite(), "img1")
        animation.update()
        self.assertEqual(animation.getSprite(), "img2")
        animation.update()
        self.assertEqual(animation.getSprite(), "img3")
コード例 #7
0
    def test_update_endAction(self):
        animation = Animation(ClockDummy(1), ["img1", "img2", "img3"], [1, 1, 1])
        callFunctionsVerifier = CallFunctionsVerifier()

        animation.setEndAction(callFunctionsVerifier.function1)

        animation.update()
        self.assertFalse(callFunctionsVerifier.called1)
        animation.update()
        self.assertFalse(callFunctionsVerifier.called1)
        animation.update()
        self.assertTrue(callFunctionsVerifier.called1)
コード例 #8
0
    def test_isCurrentAnimationName(self):
        obj = AnimatedGameObject([0, 0])

        anim1 = Animation(ClockDummy(1), ["img1", "img2"], [1, 1])
        anim2 = Animation(ClockDummy(1), ["img3", "img4"], [1, 1])

        obj.addAnimation(anim1, "anim1")
        obj.addAnimation(anim2, "anim2")

        obj.setAnimation("anim1")

        self.assertTrue(obj.isCurrentAnimationName("anim1"))
        self.assertFalse(obj.isCurrentAnimationName("anim2"))
コード例 #9
0
 def fill_flowers(self) -> None:
     for cell in self.rows[0]:
         if not cell.flower:
             topleft = cell.rect.left, cell.rect.top - cell.rect.height
             color = choice(self.flower_combos)
             cell.flower = Flower(position=topleft, color=color)
             dist = cell.rect.top - cell.flower.rect.top
             a = Animation(top=cell.rect.top,
                           duration=int(dist),
                           round_values=True)
             a.start(cell.flower.rect)
             self.animations.add(a)
     self.recheck = True
コード例 #10
0
    def reseat_flower(self, cell) -> None:
        flower = cell.flower
        if not flower:
            return

        dist = get_distance(flower.rect.topleft, cell.rect.topleft)
        if dist > 0:
            a = Animation(top=cell.rect.top,
                          left=cell.rect.left,
                          duration=int(dist * 3),
                          round_values=True,
                          transition="out_bounce")
            a.start(flower.rect)
            self.animations.add(a)
コード例 #11
0
    def test_setAnimation_nextAnimationName(self):
        obj = AnimatedGameObject([0, 0])
        anim1 = Animation(ClockDummy(1), ["img1", "img2"], [1, 1])
        anim2 = Animation(ClockDummy(1), ["img3", "img4"], [1, 1])

        obj.addAnimation(anim1, "anim1")
        obj.addAnimation(anim2, "anim2")

        obj.setAnimation("anim1", nextAnimationName="anim2")

        obj.update()
        self.assertEqual(obj.getCurrentAnimation(), anim1)
        obj.update()
        self.assertEqual(obj.getCurrentAnimation(), anim2)
コード例 #12
0
    def test_setEndAction(self):
        animation = Animation(ClockDummy(1), ["img1", "img2", "img3"], [1, 1, 1])

        self.assertIsNone(animation.getEndAction())
        action = lambda: None
        animation.setEndAction(action)
        self.assertEqual(animation.getEndAction(), action)
コード例 #13
0
 def swap_tiles(self, grabbed_tile, dest_tile) -> None:
     gf = grabbed_tile.flower
     df = dest_tile.flower
     speed = 3.5
     dist = get_distance(gf.rect.topleft, dest_tile.rect.topleft)
     if dist != 0:
         duration = int(speed * dist)
         a1 = Animation(left=dest_tile.rect.left,
                        top=dest_tile.rect.top,
                        duration=duration,
                        round_values=True)
         a1.start(gf.rect)
         a2 = Animation(left=grabbed_tile.rect.left,
                        top=grabbed_tile.rect.top,
                        duration=duration,
                        round_values=True)
         a2.start(df.rect)
         self.grid.animations.add(a1, a2)
     dest_tile.flower = gf
     grabbed_tile.flower = df
     self.grid.recheck = True
コード例 #14
0
 def spin_down(self) -> None:
     spin = Animation(spin_speed=100, duration=3500, round_values=True)
     spin.start(self)
     self.spin_animations.add(spin)
コード例 #15
0
 def test_incrementSpriteIndex(self):
     animation = Animation(ClockDummy(1), ["img1", "img2", "img3"], [1, 1, 1])
     self.assertEqual(animation.getSprite(), "img1")
     animation.incrementSpriteIndex()
     self.assertEqual(animation.getSprite(), "img2")
     animation.incrementSpriteIndex()
     self.assertEqual(animation.getSprite(), "img3")
     animation.incrementSpriteIndex()
     self.assertEqual(animation.getSprite(), "img1")
コード例 #16
0
    def test_update_noLifeSpans(self):
        animation = Animation(ClockDummy(1), ["img1"], [])

        with self.assertRaises(IndexError):
            animation.update()
コード例 #17
0
    def test_update_advanced(self):
        animation = Animation(ClockDummy(3), ["img1", "img2", "img3"], [2, 1, 5])

        self.assertEqual(animation.getSprite(), "img1")
        animation.update()
        self.assertEqual(animation.getSprite(), "img3")
        animation.update()
        self.assertEqual(animation.getSprite(), "img3")
        animation.update()
        self.assertEqual(animation.getSprite(), "img1")
        animation.update()
        self.assertEqual(animation.getSprite(), "img3")