aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAstatin <[email protected]>2025-06-03 14:51:59 +0200
committerAstatin <[email protected]>2025-06-03 14:51:59 +0200
commiteca91612b60b5379f9e8d6ce6f51366db54aacc3 (patch)
treec5fad4dc000a5430958fa8b354f69b3ba6628fe6 /scripts
parentf3a70613f78023c25d9a075231cb55639a75ee99 (diff)
Add loading from pregenerated collision map
Diffstat (limited to 'scripts')
-rw-r--r--scripts/parse-ldtkmap.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/parse-ldtkmap.py b/scripts/parse-ldtkmap.py
new file mode 100644
index 0000000..5071515
--- /dev/null
+++ b/scripts/parse-ldtkmap.py
@@ -0,0 +1,33 @@
+import json
+import sys
+import os
+
+filename = sys.argv[1]
+
+label = "_map_" + os.path.basename(filename)[:-5].replace(".", " ").title().replace(" ", "_")
+
+print(label+":")
+file = open(filename, "r")
+
+ldtk = json.loads(file.read())
+
+intgridLayer = [i for i in ldtk['levels'][0]['layerInstances'] if i['__type'] == 'IntGrid'][0]['intGridCsv']
+autoLayer = [i for i in ldtk['levels'][0]['layerInstances'] if i['__type'] == 'AutoLayer'][0]['autoLayerTiles']
+
+collision_map = []
+for y in range(0, 32):
+ for x in range(0,4):
+ collision_u8 = 0
+ for i in range(0,8):
+ if intgridLayer[y*32+(31-(x*8+i))] == 2:
+ collision_u8 |= 1 << (7-i)
+ collision_map.append(collision_u8 ^ 0xff)
+
+for i in range(0, int(len(collision_map) / 16)):
+ print("\t.DB ", end="")
+ for j in range(0, 15):
+ print("${:02x}, ".format(collision_map[i*16+j]), end="")
+ print("${:02x}".format(collision_map[i*16+15]))
+
+# print("============================")
+# print(autoLayer)