from pyglet.graphics import TextureGroup
from pyglet import image
class Block(object):
    def __init__(self, top, bottom, side, size, texturePath):
        self.coordinates = self._tex_coords(top, bottom, side, size)
        self.texture = TextureGroup(image.load(texturePath).get_texture())

    def _tex_coords(self, top, bottom, side, size):
        """ Return a list of the texture squares for the top, bottom and side.
        """
        top = self._tex_coord(*top,n = size)
        bottom = self._tex_coord(*bottom, n = size)
        side = self._tex_coord(*side, n = size)
        result = []
        result.extend(top)
        result.extend(bottom)
        result.extend(side * 4)
        return result

    def _tex_coord(self, x, y, n):
        """ Return the bounding vertices of the texture square.
        """
        m = 1.0 / n
        dx = x * m
        dy = y * m
        return dx, dy, dx + m, dy, dx + m, dy + m, dx, dy + m