예제 #1
0
 def test_findStartTime(self):
     st = [0, 1000, 2000, 4000, 8000, 16000]
     self.assertEqual(pyganim.findStartTime(st, 0), 0)
     self.assertEqual(pyganim.findStartTime(st, 999), 0)
     self.assertEqual(pyganim.findStartTime(st, 1000), 1)
     self.assertEqual(pyganim.findStartTime(st, 1001), 1)
     self.assertEqual(pyganim.findStartTime(st, 1999), 1)
     self.assertEqual(pyganim.findStartTime(st, 2000), 2)
     self.assertEqual(pyganim.findStartTime(st, 2001), 2)
     self.assertEqual(pyganim.findStartTime(st, 3999), 2)
     self.assertEqual(pyganim.findStartTime(st, 4000), 3)
     self.assertEqual(pyganim.findStartTime(st, 9999999), 4)
예제 #2
0
 def test_findStartTime(self):
     st = [0, 1000, 2000, 4000, 8000, 16000]
     self.assertEqual(pyganim.findStartTime(st, 0), 0)
     self.assertEqual(pyganim.findStartTime(st, 999), 0)
     self.assertEqual(pyganim.findStartTime(st, 1000), 1)
     self.assertEqual(pyganim.findStartTime(st, 1001), 1)
     self.assertEqual(pyganim.findStartTime(st, 1999), 1)
     self.assertEqual(pyganim.findStartTime(st, 2000), 2)
     self.assertEqual(pyganim.findStartTime(st, 2001), 2)
     self.assertEqual(pyganim.findStartTime(st, 3999), 2)
     self.assertEqual(pyganim.findStartTime(st, 4000), 3)
     self.assertEqual(pyganim.findStartTime(st, 9999999), 4)
예제 #3
0
파일: animations.py 프로젝트: jwl/hypatia
    def blit(self, screen, offset):
        """Draw the appropriate/active animation to screen.

        Note:
            Should go to render module?

        Args:
          screen (pygame.Surface): the primary display/screen.
          offset (x, y tuple): the x, y coords of the absolute
              starting top left corner for the current screen/viewport
              position.

        """

        x, y = self.topleft_float
        x -= offset[0]
        y -= offset[1]
        position_on_screen = (x, y)

        pyganim_gif = self.current_animation()
        pyganim_gif.blit(screen, position_on_screen)

        # the rest of this is for children/anchors
        if self.animation_anchors is None:

            return None

        pyganim_frame_index = pyganim.findStartTime(pyganim_gif._startTimes,
                                                    pyganim_gif.elapsed)
        current_frame_surface = pyganim_gif.getFrame(pyganim_frame_index)

        # anchors are all completely wrong
        animation_anchors = self.animation_anchors[self.action][self.direction]
        frame_anchor = animation_anchors.get_anchor_point('head_anchor',
                                                          pyganim_frame_index)
        parent_anchor = AnchorPoint(position_on_screen[0] + frame_anchor.x,
                                    position_on_screen[1] + frame_anchor.y)

        for child_walkabout in self.child_walkabouts:
            # draw at position + difference in child anchor
            child_anim_anchor = (child_walkabout
                                 .animation_anchors[self.action]
                                 [self.direction])
            child_frame_anchor = (child_anim_anchor
                                  .get_anchor_point('head_anchor',
                                                    pyganim_frame_index))
            child_position = parent_anchor - child_frame_anchor
            child_anim = child_walkabout.current_animation()
            child_anim.blit(screen, child_position)
예제 #4
0
    def blit(self, screen, offset):
        """Draw the appropriate/active animation to screen.

        Note:
          Should go to render module?

        Args:
          screen (pygame.Surface): the primary display/screen.
          offset (x, y tuple): the x, y coords of the absolute
            starting top left corner for the current screen/viewport
            position.

        """

        x, y = self.topleft_float
        x -= offset[0]
        y -= offset[1]
        position_on_screen = (x, y)

        pyganim_gif = self.current_animation()
        pyganim_gif.blit(screen, position_on_screen)

        # the rest of this is for children/anchors
        if self.animation_anchors is None:

            return None

        pyganim_frame_index = pyganim.findStartTime(pyganim_gif._startTimes,
                                                    pyganim_gif.elapsed)
        current_frame_surface = pyganim_gif.getFrame(pyganim_frame_index)

        # anchors are all completely wrong
        animation_anchors = self.animation_anchors[self.action][self.direction]
        frame_anchor = animation_anchors.get_anchor_point('head_anchor',
                                                          pyganim_frame_index)
        parent_anchor = AnchorPoint(position_on_screen[0] + frame_anchor.x,
                                    position_on_screen[1] + frame_anchor.y)

        for child_walkabout in self.child_walkabouts:
            # draw at position + difference in child anchor
            child_anim_anchor = (child_walkabout
                                 .animation_anchors[self.action]
                                 [self.direction])
            child_frame_anchor = (child_anim_anchor
                                  .get_anchor_point('head_anchor',
                                                    pyganim_frame_index))
            child_position = parent_anchor - child_frame_anchor
            child_anim = child_walkabout.current_animation()
            child_anim.blit(screen, child_position)