test_camera.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:sappho 作者: lily-mayfield 项目源码 文件源码
def test_scroll(self):
        # Create surface to render to
        output_surface = pygame.surface.Surface((1, 1))

        # Create fixtures
        red_surface = pygame.surface.Surface((1, 1))
        blue_surface = pygame.surface.Surface((1, 1))
        red_surface.fill((255, 0, 0))
        blue_surface.fill((0, 255, 0))

        # Create the camera and blit colors to it
        camera = Camera((2, 1), (1, 1), (1, 1))
        camera.source_surface.blit(red_surface, (0, 0))
        camera.source_surface.blit(blue_surface, (1, 0))
        camera.update_state("so many of these")

        # We should be at (0, 0) so blitting should get us a red pixel
        output_surface.blit(camera, (0, 0))
        assert(compare_surfaces(red_surface, output_surface))

        # Scroll one pixel to the left, and we should get a blue pixel
        # when blitting
        focal_rect = pygame.Rect((1, 0), (1, 1))
        camera.scroll_to(focal_rect)  # updates for us
        camera.update_state("just a lot")
        output_surface.blit(camera, (0, 0))
        assert(compare_surfaces(blue_surface, output_surface))

    # FIXME: This is messy!
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号