Добавил создание обьектов из карты
This commit is contained in:
parent
2ec1b3b268
commit
651b43b8d1
6 changed files with 202 additions and 34 deletions
|
@ -13,5 +13,6 @@ namespace ZoFo.GameCore.GameManagers.MapManager.MapElements
|
||||||
public int Width { get; set; }
|
public int Width { get; set; }
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public bool Visibility { get; set; }
|
public bool Visibility { get; set; }
|
||||||
|
public string Class { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,17 @@ using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ZoFo.GameCore.GameManagers.MapManager.MapElements;
|
using ZoFo.GameCore.GameManagers.MapManager.MapElements;
|
||||||
|
using ZoFo.GameCore.GameObjects.MapObjects;
|
||||||
|
using ZoFo.GameCore.GameObjects.MapObjects.StopObjects;
|
||||||
|
using ZoFo.GameCore.GameObjects.MapObjects.Tiles;
|
||||||
|
|
||||||
namespace ZoFo.GameCore.GameManagers.MapManager
|
namespace ZoFo.GameCore.GameManagers.MapManager
|
||||||
{
|
{
|
||||||
public class MapManager
|
public class MapManager
|
||||||
{
|
{
|
||||||
private static readonly string _path = "TileMaps/{0}.tmj";
|
|
||||||
|
private static readonly string _templatePath = "TileMaps/{0}.tmj";
|
||||||
|
private static readonly float _scale = 1.0f;
|
||||||
private List<TileSet> _tileSets = new List<TileSet>();
|
private List<TileSet> _tileSets = new List<TileSet>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -23,12 +28,7 @@ namespace ZoFo.GameCore.GameManagers.MapManager
|
||||||
public void LoadMap(string mapName = "main")
|
public void LoadMap(string mapName = "main")
|
||||||
{
|
{
|
||||||
// Загрузка TileMap
|
// Загрузка TileMap
|
||||||
TileMap tileMap;
|
TileMap tileMap = JsonSerializer.Deserialize<TileMap>(File.ReadAllText(string.Format(_templatePath, mapName)));
|
||||||
using (StreamReader reader = new StreamReader(string.Format(_path, mapName)))
|
|
||||||
{
|
|
||||||
string data = reader.ReadToEnd();
|
|
||||||
tileMap = JsonSerializer.Deserialize<TileMap>(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Загрузка TileSet-ов по TileSetInfo
|
// Загрузка TileSet-ов по TileSetInfo
|
||||||
List<TileSet> tileSets = new List<TileSet>();
|
List<TileSet> tileSets = new List<TileSet>();
|
||||||
|
@ -39,23 +39,39 @@ namespace ZoFo.GameCore.GameManagers.MapManager
|
||||||
tileSets.Add(tileSet);
|
tileSets.Add(tileSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var chunk in tileMap.Layers[0].Chunks)
|
foreach (var layer in tileMap.Layers)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < chunk.Data.Length; i++)
|
foreach (var chunk in layer.Chunks)
|
||||||
{
|
{
|
||||||
foreach (var tileSet in tileSets)
|
for (int i = 0; i < chunk.Data.Length; i++)
|
||||||
{
|
{
|
||||||
if (tileSet.FirstGid - chunk.Data[i] < 0)
|
foreach (var tileSet in tileSets)
|
||||||
{
|
{
|
||||||
int number = chunk.Data[i] - tileSet.FirstGid;
|
if (tileSet.FirstGid - chunk.Data[i] < 0)
|
||||||
|
{
|
||||||
|
int number = chunk.Data[i] - tileSet.FirstGid;
|
||||||
|
|
||||||
int relativeColumn = number % tileSet.Columns * tileSet.TileWidth;
|
int relativeColumn = number % tileSet.Columns * tileSet.TileWidth;
|
||||||
int relativeRow = number / tileSet.Columns * tileSet.TileHeight;
|
int relativeRow = number / tileSet.Columns * tileSet.TileHeight;
|
||||||
|
|
||||||
Rectangle sourceRectangle = new Rectangle(relativeColumn * tileSet.TileWidth, relativeRow * tileSet.TileHeight,
|
Rectangle sourceRectangle = new Rectangle(relativeColumn * tileSet.TileWidth, relativeRow * tileSet.TileHeight,
|
||||||
relativeColumn * tileSet.TileWidth + tileSet.TileWidth, relativeRow * tileSet.TileHeight + tileSet.TileHeight);
|
relativeColumn * tileSet.TileWidth + tileSet.TileWidth, relativeRow * tileSet.TileHeight + tileSet.TileHeight);
|
||||||
|
|
||||||
Vector2 position = new Vector2(i % chunk.Width, i / chunk.Height);
|
Vector2 position = new Vector2(i % chunk.Width, i / chunk.Height);
|
||||||
|
|
||||||
|
switch (layer.Class)
|
||||||
|
{
|
||||||
|
case "Tile":
|
||||||
|
new MapObject(position, new Vector2(tileSet.TileWidth * _scale, tileSet.TileHeight * _scale), sourceRectangle, tileSet.Name);
|
||||||
|
break;
|
||||||
|
case "StopObject":
|
||||||
|
new StopObject(position, new Vector2(tileSet.TileWidth * _scale, tileSet.TileHeight * _scale), sourceRectangle, tileSet.Name);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
},
|
},
|
||||||
"last.imagePath": "D:/C#/Я смотрел ваши ХАКАТОНЫ/ZoFo/ZoFo/Content/Textures/Background",
|
"last.imagePath": "D:/C#/Я смотрел ваши ХАКАТОНЫ/ZoFo/ZoFo/Content/Textures/Background",
|
||||||
"map.fixedSize": false,
|
"map.fixedSize": false,
|
||||||
"map.lastUsedFormat": "tmx",
|
"map.lastUsedFormat": "json",
|
||||||
"map.tileHeight": 16,
|
"map.tileHeight": 16,
|
||||||
"map.tileWidth": 16,
|
"map.tileWidth": 16,
|
||||||
"openFiles": [
|
"openFiles": [
|
||||||
|
|
167
ZoFo/GameCore/GameManagers/MapManager/TileMaps/main.tmj
Normal file
167
ZoFo/GameCore/GameManagers/MapManager/TileMaps/main.tmj
Normal file
|
@ -0,0 +1,167 @@
|
||||||
|
{ "compressionlevel":-1,
|
||||||
|
"height":20,
|
||||||
|
"infinite":true,
|
||||||
|
"layers":[
|
||||||
|
{
|
||||||
|
"chunks":[
|
||||||
|
{
|
||||||
|
"data":[24, 24, 24, 28, 29, 24, 24, 24, 28, 46, 29, 24, 25, 115, 45, 46,
|
||||||
|
24, 24, 24, 25, 23, 24, 24, 24, 50, 2, 51, 24, 50, 2, 2, 2,
|
||||||
|
24, 24, 24, 50, 32, 29, 24, 24, 24, 24, 24, 24, 24, 24, 24, 28,
|
||||||
|
28, 29, 24, 28, 10, 32, 29, 24, 24, 28, 46, 29, 24, 24, 24, 50,
|
||||||
|
47, 23, 24, 50, 32, 10, 32, 46, 29, 50, 2, 51, 24, 24, 24, 24,
|
||||||
|
1, 32, 29, 90, 25, 23, 50, 2, 32, 29, 24, 90, 28, 29, 24, 24,
|
||||||
|
51, 50, 32, 29, 50, 51, 90, 24, 25, 45, 46, 29, 25, 23, 24, 90,
|
||||||
|
24, 24, 50, 32, 46, 29, 24, 28, 10, 2, 2, 51, 50, 51, 24, 90,
|
||||||
|
24, 24, 24, 50, 2, 32, 46, 10, 32, 29, 24, 90, 24, 24, 24, 90,
|
||||||
|
29, 24, 89, 24, 24, 50, 3, 23, 50, 32, 46, 46, 46, 46, 29, 24,
|
||||||
|
51, 24, 24, 28, 29, 24, 25, 23, 24, 25, 1, 2, 3, 111, 45, 29,
|
||||||
|
24, 90, 24, 50, 51, 24, 25, 23, 28, 47, 23, 89, 50, 3, 115, 23,
|
||||||
|
24, 24, 24, 24, 24, 89, 50, 32, 47, 1, 51, 24, 24, 50, 2, 51,
|
||||||
|
28, 29, 24, 24, 24, 24, 28, 10, 2, 51, 24, 24, 24, 24, 24, 28,
|
||||||
|
10, 32, 29, 24, 24, 24, 25, 23, 28, 29, 90, 24, 24, 90, 24, 50,
|
||||||
|
32, 10, 51, 24, 24, 24, 50, 32, 10, 32, 29, 24, 90, 28, 29, 24],
|
||||||
|
"height":16,
|
||||||
|
"width":16,
|
||||||
|
"x":-16,
|
||||||
|
"y":-16
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data":[10, 51, 24, 90, 24, 25, 23, 28, 29, 24, 24, 24, 24, 24, 24, 24,
|
||||||
|
51, 24, 28, 29, 24, 50, 32, 10, 51, 24, 24, 24, 24, 24, 24, 24,
|
||||||
|
29, 28, 10, 32, 46, 29, 50, 32, 29, 24, 24, 24, 24, 24, 24, 24,
|
||||||
|
51, 25, 23, 50, 2, 32, 29, 25, 23, 24, 24, 28, 29, 24, 90, 24,
|
||||||
|
24, 25, 23, 24, 24, 25, 23, 50, 51, 24, 24, 50, 32, 29, 24, 90,
|
||||||
|
24, 50, 32, 29, 90, 25, 45, 29, 24, 24, 24, 24, 50, 51, 24, 89,
|
||||||
|
24, 89, 50, 51, 24, 25, 114, 23, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||||
|
24, 24, 28, 29, 24, 50, 2, 51, 24, 24, 90, 28, 29, 24, 24, 28,
|
||||||
|
24, 24, 25, 23, 89, 24, 24, 24, 28, 46, 29, 25, 23, 24, 24, 50,
|
||||||
|
28, 46, 10, 51, 24, 28, 46, 29, 25, 111, 45, 10, 51, 28, 29, 24,
|
||||||
|
50, 2, 51, 24, 24, 25, 115, 45, 10, 3, 1, 51, 24, 25, 23, 24,
|
||||||
|
24, 24, 24, 24, 24, 50, 2, 2, 32, 10, 51, 24, 90, 25, 23, 24,
|
||||||
|
24, 24, 24, 24, 24, 24, 24, 24, 50, 51, 24, 24, 24, 25, 23, 24,
|
||||||
|
46, 29, 24, 24, 24, 24, 24, 89, 24, 24, 24, 28, 46, 47, 23, 90,
|
||||||
|
2, 32, 29, 24, 24, 28, 46, 46, 29, 24, 24, 25, 1, 3, 23, 89,
|
||||||
|
24, 50, 32, 29, 24, 25, 1, 3, 23, 24, 89, 50, 32, 10, 51, 24],
|
||||||
|
"height":16,
|
||||||
|
"width":16,
|
||||||
|
"x":0,
|
||||||
|
"y":-16
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data":[24, 24, 24, 24, 90, 24, 89, 24, 89, 24, 50, 51, 89, 24, 24, 24,
|
||||||
|
24, 28, 29, 28, 29, 24, 24, 24, 24, 28, 29, 24, 24, 24, 28, 29,
|
||||||
|
24, 25, 23, 50, 51, 24, 24, 28, 29, 50, 51, 24, 24, 24, 25, 45,
|
||||||
|
90, 50, 51, 28, 29, 24, 24, 25, 23, 24, 24, 28, 29, 24, 50, 3,
|
||||||
|
24, 24, 28, 10, 51, 90, 90, 50, 51, 24, 24, 50, 51, 24, 24, 50,
|
||||||
|
24, 24, 25, 45, 29, 24, 28, 29, 24, 24, 24, 24, 24, 28, 29, 24,
|
||||||
|
90, 24, 50, 2, 51, 28, 10, 51, 90, 24, 28, 29, 24, 25, 45, 46,
|
||||||
|
29, 90, 24, 24, 24, 50, 51, 24, 24, 28, 10, 32, 46, 10, 3, 1,
|
||||||
|
32, 29, 24, 90, 24, 24, 24, 24, 28, 47, 23, 50, 2, 51, 50, 51,
|
||||||
|
25, 23, 24, 24, 28, 46, 46, 46, 47, 114, 45, 29, 24, 24, 24, 24,
|
||||||
|
50, 32, 29, 24, 50, 3, 111, 111, 115, 111, 1, 32, 29, 24, 24, 24,
|
||||||
|
24, 50, 51, 24, 28, 10, 2, 2, 2, 2, 32, 10, 51, 24, 24, 89,
|
||||||
|
24, 24, 89, 90, 25, 23, 24, 24, 24, 24, 50, 32, 46, 46, 29, 89,
|
||||||
|
24, 24, 24, 90, 25, 23, 89, 24, 28, 29, 90, 50, 2, 2, 51, 24,
|
||||||
|
24, 24, 24, 28, 10, 51, 24, 28, 47, 45, 29, 24, 24, 24, 24, 24,
|
||||||
|
24, 24, 24, 25, 23, 24, 90, 50, 2, 2, 32, 46, 46, 46, 46, 46],
|
||||||
|
"height":16,
|
||||||
|
"width":16,
|
||||||
|
"x":16,
|
||||||
|
"y":-16
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data":[10, 32, 46, 29, 24, 24, 24, 25, 23, 50, 32, 29, 24, 50, 32, 46,
|
||||||
|
51, 50, 2, 32, 29, 24, 24, 25, 45, 29, 25, 23, 24, 24, 25, 1,
|
||||||
|
24, 24, 24, 25, 23, 28, 46, 10, 2, 51, 50, 51, 24, 24, 50, 51,
|
||||||
|
90, 89, 90, 50, 51, 50, 2, 51, 24, 24, 28, 29, 90, 24, 24, 24,
|
||||||
|
90, 28, 46, 29, 90, 24, 24, 24, 90, 24, 50, 51, 90, 24, 90, 28,
|
||||||
|
29, 50, 2, 51, 24, 24, 24, 89, 24, 24, 24, 24, 24, 89, 24, 50,
|
||||||
|
23, 24, 24, 28, 46, 29, 90, 90, 24, 89, 24, 28, 29, 24, 24, 24,
|
||||||
|
32, 46, 29, 25, 115, 45, 29, 24, 90, 24, 24, 25, 23, 24, 24, 28,
|
||||||
|
10, 2, 32, 47, 115, 1, 51, 24, 24, 24, 24, 25, 23, 24, 28, 10,
|
||||||
|
32, 29, 50, 2, 2, 51, 24, 24, 24, 24, 24, 25, 23, 28, 10, 51,
|
||||||
|
50, 51, 89, 24, 24, 89, 24, 28, 29, 24, 24, 50, 32, 10, 32, 46,
|
||||||
|
24, 24, 90, 90, 28, 46, 29, 50, 51, 24, 24, 24, 25, 23, 25, 115,
|
||||||
|
24, 90, 24, 24, 50, 2, 32, 29, 24, 24, 90, 24, 25, 45, 10, 2,
|
||||||
|
24, 24, 24, 24, 24, 24, 50, 32, 29, 24, 24, 28, 10, 3, 23, 24,
|
||||||
|
90, 24, 24, 24, 24, 89, 90, 50, 32, 29, 90, 50, 51, 50, 32, 46,
|
||||||
|
46, 29, 24, 90, 24, 24, 24, 24, 50, 51, 28, 29, 24, 24, 50, 2],
|
||||||
|
"height":16,
|
||||||
|
"width":16,
|
||||||
|
"x":-16,
|
||||||
|
"y":0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data":[46, 46, 10, 32, 46, 47, 23, 25, 23, 89, 24, 24, 25, 23, 90, 24,
|
||||||
|
2, 2, 32, 47, 1, 2, 51, 25, 23, 24, 28, 29, 50, 32, 29, 24,
|
||||||
|
24, 90, 50, 3, 23, 24, 28, 10, 51, 28, 47, 45, 29, 25, 23, 28,
|
||||||
|
24, 24, 24, 50, 51, 28, 47, 23, 24, 50, 3, 114, 45, 10, 51, 50,
|
||||||
|
29, 24, 24, 89, 24, 25, 114, 45, 46, 46, 10, 2, 2, 32, 29, 89,
|
||||||
|
51, 24, 24, 24, 24, 50, 3, 111, 115, 115, 23, 24, 24, 50, 32, 29,
|
||||||
|
24, 28, 29, 24, 24, 24, 25, 1, 2, 2, 51, 90, 24, 90, 50, 51,
|
||||||
|
29, 50, 32, 29, 28, 29, 25, 23, 24, 24, 89, 28, 29, 24, 24, 24,
|
||||||
|
51, 24, 50, 51, 50, 32, 10, 32, 46, 29, 24, 50, 51, 24, 90, 24,
|
||||||
|
24, 24, 24, 24, 89, 50, 32, 10, 2, 32, 46, 29, 89, 28, 29, 24,
|
||||||
|
29, 90, 24, 24, 24, 24, 50, 51, 28, 10, 3, 23, 28, 10, 51, 24,
|
||||||
|
23, 89, 24, 24, 90, 24, 24, 24, 50, 32, 10, 51, 50, 51, 24, 24,
|
||||||
|
51, 24, 24, 24, 24, 24, 24, 24, 24, 50, 32, 46, 46, 29, 28, 46,
|
||||||
|
24, 24, 24, 90, 24, 24, 24, 24, 24, 24, 50, 3, 1, 32, 47, 115,
|
||||||
|
46, 29, 24, 89, 24, 24, 24, 89, 24, 24, 24, 25, 45, 10, 3, 111,
|
||||||
|
2, 51, 28, 29, 28, 29, 24, 28, 46, 46, 46, 10, 2, 51, 50, 2],
|
||||||
|
"height":16,
|
||||||
|
"width":16,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data":[28, 29, 28, 10, 32, 46, 29, 24, 24, 28, 10, 2, 2, 2, 2, 2,
|
||||||
|
50, 51, 50, 51, 25, 115, 45, 46, 29, 50, 51, 24, 24, 24, 24, 24,
|
||||||
|
29, 24, 89, 24, 50, 3, 115, 114, 23, 24, 24, 24, 24, 24, 24, 24,
|
||||||
|
51, 90, 24, 89, 24, 50, 2, 2, 51, 24, 89, 24, 24, 28, 46, 29,
|
||||||
|
24, 90, 24, 24, 89, 24, 90, 28, 29, 24, 24, 24, 28, 10, 2, 51,
|
||||||
|
24, 24, 24, 24, 28, 29, 90, 50, 51, 28, 29, 24, 25, 23, 24, 24,
|
||||||
|
28, 29, 24, 24, 50, 32, 29, 28, 29, 50, 51, 89, 50, 32, 29, 24,
|
||||||
|
50, 51, 24, 24, 24, 50, 32, 10, 51, 24, 89, 24, 24, 25, 23, 24,
|
||||||
|
24, 24, 24, 24, 24, 24, 50, 32, 29, 24, 24, 24, 24, 50, 51, 24,
|
||||||
|
90, 24, 24, 24, 24, 24, 24, 25, 45, 29, 24, 24, 24, 89, 28, 29,
|
||||||
|
24, 24, 24, 24, 28, 29, 24, 25, 1, 51, 24, 24, 24, 24, 50, 32,
|
||||||
|
28, 29, 28, 29, 50, 32, 46, 10, 51, 28, 29, 24, 24, 24, 24, 50,
|
||||||
|
47, 45, 10, 51, 24, 50, 2, 32, 46, 47, 23, 24, 89, 90, 24, 24,
|
||||||
|
111, 115, 23, 24, 24, 90, 24, 50, 2, 2, 32, 29, 24, 89, 28, 46,
|
||||||
|
1, 2, 51, 28, 46, 46, 29, 24, 28, 29, 50, 32, 29, 28, 47, 111,
|
||||||
|
51, 24, 24, 50, 3, 114, 23, 24, 50, 32, 46, 47, 23, 25, 111, 111],
|
||||||
|
"height":16,
|
||||||
|
"width":16,
|
||||||
|
"x":16,
|
||||||
|
"y":0
|
||||||
|
}],
|
||||||
|
"class":"Tile",
|
||||||
|
"height":48,
|
||||||
|
"id":1,
|
||||||
|
"name":"\u0421\u043b\u043e\u0439 \u0442\u0430\u0439\u043b\u043e\u0432 1",
|
||||||
|
"opacity":1,
|
||||||
|
"startx":-16,
|
||||||
|
"starty":-32,
|
||||||
|
"type":"tilelayer",
|
||||||
|
"visible":true,
|
||||||
|
"width":48,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
}],
|
||||||
|
"nextlayerid":2,
|
||||||
|
"nextobjectid":1,
|
||||||
|
"orientation":"orthogonal",
|
||||||
|
"renderorder":"right-down",
|
||||||
|
"tiledversion":"1.10.2",
|
||||||
|
"tileheight":16,
|
||||||
|
"tilesets":[
|
||||||
|
{
|
||||||
|
"firstgid":1,
|
||||||
|
"source":"..\/TileSets\/TileSet 1.tsj"
|
||||||
|
}],
|
||||||
|
"tilewidth":16,
|
||||||
|
"type":"map",
|
||||||
|
"version":"1.10",
|
||||||
|
"width":30
|
||||||
|
}
|
|
@ -1,8 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace ZoFo.GameCore.GameObjects.StopObjects;
|
|
||||||
|
|
||||||
public class StopObject
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace ZoFo.GameCore.GameObjects;
|
|
||||||
|
|
||||||
public class Tile
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue