From 815ef3fcfed6bb2e23d5d61c02542535f2d3c303 Mon Sep 17 00:00:00 2001 From: adrianna Date: Thu, 3 Mar 2016 00:21:12 +0200 Subject: [PATCH] moar randomness --- koperkapel/loaders/levelloader.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/koperkapel/loaders/levelloader.py b/koperkapel/loaders/levelloader.py index 640d9b1..ff18fc7 100644 --- a/koperkapel/loaders/levelloader.py +++ b/koperkapel/loaders/levelloader.py @@ -5,6 +5,7 @@ import json from pgzero.loaders import images, ResourceLoader import os import random +from pygame.transform import rotate class Tile: IMG = None @@ -18,6 +19,7 @@ class Tile: class RandomizedTile(Tile): IMGDIR = None + ROTATE = True @classmethod def image(cls): @@ -25,9 +27,13 @@ class RandomizedTile(Tile): 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)) - return images.load(os.path.join(cls.IMGDIR, img)) + if cls.ROTATE: + img = rotate(img, 90 * random.randint(0, 3)) + + return img class Floor(RandomizedTile): IMGDIR = "floor" -- 2.34.1