How to use the pyscroll.data.PyscrollDataAdapter function in pyscroll

To help you get started, we’ve selected a few pyscroll examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitcraft / pyscroll / tests / pyscroll / test_pyscroll.py View on Github external
import mock
import unittest
import pygame
from pyscroll.orthographic import BufferedRenderer
from pyscroll.data import PyscrollDataAdapter


class DummyDataAdapter(PyscrollDataAdapter):
    tile_size = 32, 32
    map_size = 32, 32
    visible_tile_layers = [1]

    def get_animations(self):
        return list()

    def get_tile_image(self, position):
        return position[0] * position[1]


class DummyBufferer:
    _tile_view = pygame.Rect(2, 2, 2, 2)
    _clear_color = None
    _buffer = mock.Mock()
    data = DummyDataAdapter()
github bitcraft / pyscroll / pyscroll / data.py View on Github external
Not like python 'Range': should include the end index!

        :param rect: a rect-like object that defines tiles to draw
        :return: generator
        """
        x1, y1, x2, y2 = rect_to_bb(rect)
        for layer in self.visible_tile_layers:
            for y, x in product(range(y1, y2 + 1),
                                range(x1, x2 + 1)):
                tile = self.get_tile_image(x, y, layer)
                if tile:
                    yield x, y, layer, tile


class TiledMapData(PyscrollDataAdapter):
    """ For data loaded from pytmx

    Use of this class requires a recent version of pytmx.
    """

    def __init__(self, tmx):
        super(TiledMapData, self).__init__()
        self.tmx = tmx
        self.reload_animations()

    def get_animations(self):
        for gid, d in self.tmx.tile_properties.items():
            try:
                frames = d['frames']
            except KeyError:
                continue