"""Loader a level, using the pygame-zero ResourceLoader infrastructure"""
+import os
import json
from pgzero.loaders import images, ResourceLoader
import os
import random
+from pygame.transform import rotate
class Tile:
IMG = None
class RandomizedTile(Tile):
IMGDIR = None
+ ROTATE = True
@classmethod
def image(cls):
raise NotImplementedError()
imgdir = os.path.join(os.path.dirname(__file__), '..', 'images', cls.IMGDIR)
- img = os.path.splitext(random.choice(os.listdir(imgdir)))[0]
+ imgpath = os.path.splitext(random.choice(os.listdir(imgdir)))[0]
+ img = images.load(os.path.join(cls.IMGDIR, imgpath))
+
+ if cls.ROTATE:
+ img = rotate(img, 90 * random.randint(0, 3))
- return images.load(os.path.join(cls.IMGDIR, img))
+ return img
class Floor(RandomizedTile):
IMGDIR = "floor"
self._height = len(level_data['tiles'])
self._width = len(level_data['tiles'][0])
self._tiles = level_data['tiles']
+ self._tileset = level_data['tileset']
# Consistency check, so we can assume things are correct
# in the level renderer
for row, row_data in enumerate(self._tiles):