moar randomness
authoradrianna <adrianna.pinska@gmail.com>
Wed, 2 Mar 2016 22:21:12 +0000 (00:21 +0200)
committeradrianna <adrianna.pinska@gmail.com>
Wed, 2 Mar 2016 22:21:12 +0000 (00:21 +0200)
koperkapel/loaders/levelloader.py

index 640d9b168ada4e59073559058cb8654d72492fb5..ff18fc7b8e0548678dc172dd65db893fe33853fc 100644 (file)
@@ -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"