示例#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")