From: Neil Date: Tue, 1 Mar 2016 09:33:50 +0000 (+0200) Subject: Add crude serializer to map generator X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=e18e3769c831f66ef86d48a9e5b4e9a4f08f8c52;p=koperkapel.git Add crude serializer to map generator --- diff --git a/koperkapel/generators/maps.py b/koperkapel/generators/maps.py index 6f62b0b..9426929 100644 --- a/koperkapel/generators/maps.py +++ b/koperkapel/generators/maps.py @@ -2,10 +2,22 @@ import random import math +import json +import os i = random.randint(0,100) +ATTRIBUTE_MAP = { + '#': {'base': 'cwall', + 'behaviour': [], + }, + ' ': {'base': 'floor', + 'behaviour': ['walk', 'fly'], + }, +} + + class LevelGenerator: width = 0 height = 0 @@ -124,9 +136,25 @@ class LevelGenerator: file.write(''.join(l)) file.write('\n') file.close() + self._to_json() for l in self.regions: print(l) + def _to_json(self): + level = {} + level['tiles'] = [] + for l in self.map: + row = [] + for t in l: + row.append(ATTRIBUTE_MAP[t]) + level['tiles'].append(row) + name = os.path.join(os.path.dirname(__file__), '..', 'levels', 'map.json') + # FIXME: Do a lot better here + # Crude hack so the level is written into the levels folder + f = open(name, 'w') + json.dump(level, f) + f.close() + if __name__ == '__main__': while True: