Files
Terekhov_TASK1/fill_level.py
T
2025-05-06 14:10:14 +03:00

110 lines
3.3 KiB
Python

import json
class filler():
def __init__(self, name = "None", floor_code = []):
self.name = name
self.floor_code = floor_code if floor_code else self.get_default_floor_code()
def export2json(self):
filename = f"DATA/Levels/{self.name}/data.json"
with open(filename, 'w') as f:
json.dump(self.level_data, f)
def fill_level(self, floor_code, name = "Default"):
self.level_data = {
"name": name,
"start_point": {
"x": 4,
"y": 8,
},
"enemy_types": [
[
{
"type": "little_spider",
"sprite": "DATA/Sprites/Enemies/Tier 1/little-spider.png",
}
],
[
{
"type": "wolf",
"sprite": "DATA/Sprites/Enemies/Tier 2/wolf.png",
}
],
],
"enemy_spawns": [[
{ "x" : 1, "y" : 3, "tier": 1, "sleep": 600, "delay": 600},
{ "x" : 12, "y" : 7,"tier": 1, "sleep": 9000, "delay": 9000 },
{ "x" : 1, "y" : 4, "tier": 1,"sleep": 800, "delay": 800 },
{ "x" : 10, "y" : 0,"tier": 1, "sleep": 600, "delay": 600 }
]],
"size" : [],
"floor": []
}
# Загрузка пола
# floor_code - закодированная информация об уровне, представляет собой ас массив последовательностей 2х чисел:
# начало пола, конец пола
# Ключами являются координаты по y
sprite = "DATA/Sprites/Floor/floor_grey.png"
y = 0
x_max = 1
y_max = 1
while y < 15:
if y in floor_code:
for x_len in floor_code[y]:
x = x_len["s"]
while x <= x_len["e"]:
if x > x_max: x_max = x
self.level_data["floor"].append({"sprite": sprite, "x": x, "y": y})
x = x+1
if y > y_max: y_max = y
y = y + 1
else:
break
self.level_data["size"] = [x_max, y_max]
def get_default_floor_code(self):
return {
0: [
{ "s" : 5, "e" : 6 },
{ "s" : 10, "e" : 12 },
],
1:[
{ "s" : 5, "e" : 13 },
],
2:[
{ "s" : 4, "e" : 13 },
],
3:[
{ "s" : 1, "e" : 13 },
],
4:[
{ "s" : 1, "e" : 13 },
],
5:[
{ "s" : 1, "e" : 13 },
],
6:[
{ "s" : 0, "e" : 12 },
],
7:[
{ "s" : 0, "e" : 12 },
],
8:[
{ "s" : 1, "e" : 12 },
],
9:[
{ "s" : 3, "e" : 11 },
],
10:[
{ "s" : 6, "e" : 8 },
]
}