commit
2c8af8b868
4 changed files with 83 additions and 5 deletions
|
@ -11,6 +11,7 @@ namespace ZoFo.GameCore.GameManagers.MapManager.MapElements
|
||||||
public bool Infinite { get; set; }
|
public bool Infinite { get; set; }
|
||||||
public int TileHeight { get; set; }
|
public int TileHeight { get; set; }
|
||||||
public int TileWidth { get; set; }
|
public int TileWidth { get; set; }
|
||||||
public List<TileSet> TileSets { get; set; }
|
public List<TileSetInfo> TileSets { get; set; }
|
||||||
|
public List<Layer> Layers { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -8,5 +9,16 @@ namespace ZoFo.GameCore.GameManagers.MapManager.MapElements
|
||||||
{
|
{
|
||||||
public class TileSet
|
public class TileSet
|
||||||
{
|
{
|
||||||
|
public string Image { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int ImageHeight { get; set; }
|
||||||
|
public int ImageWidth { get; set; }
|
||||||
|
public int Margin { get; set; }
|
||||||
|
public int Spacing { get; set; }
|
||||||
|
public int TileCount { get; set; }
|
||||||
|
public int TileHeight { get; set; }
|
||||||
|
public int TileWidth { get; set; }
|
||||||
|
public int Columns { get; set; }
|
||||||
|
public int FirstGid { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.MapManager.MapElements
|
||||||
|
{
|
||||||
|
public class TileSetInfo
|
||||||
|
{
|
||||||
|
public int FirstGid { get; set; }
|
||||||
|
public string Source { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,20 +1,71 @@
|
||||||
using System;
|
using Microsoft.Xna.Framework;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using ZoFo.GameCore.GameManagers.MapManager.MapElements;
|
||||||
|
|
||||||
namespace ZoFo.GameCore.GameManagers.MapManager
|
namespace ZoFo.GameCore.GameManagers.MapManager
|
||||||
{
|
{
|
||||||
public class MapManager
|
public class MapManager
|
||||||
{
|
{
|
||||||
public void LoadMap()
|
private static readonly string _path = "/{0}.tmj";
|
||||||
|
private List<TileSet> _tileSets = new List<TileSet>();
|
||||||
|
|
||||||
|
public void LoadMap(string mapName = "main")
|
||||||
{
|
{
|
||||||
|
TileMap tileMap;
|
||||||
}
|
using (StreamReader reader = new StreamReader(string.Format(_path, mapName)))
|
||||||
private void LoadTileSet()
|
|
||||||
{
|
{
|
||||||
|
string data = reader.ReadToEnd();
|
||||||
|
tileMap = JsonSerializer.Deserialize<TileMap>(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<TileSet> tileSets = new List<TileSet>();
|
||||||
|
foreach (TileSetInfo tileSetInfo in tileMap.TileSets)
|
||||||
|
{
|
||||||
|
TileSet tileSet = LoadTileSet(tileSetInfo.Source);
|
||||||
|
tileSet.FirstGid = tileSetInfo.FirstGid;
|
||||||
|
tileSets.Add(tileSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var chunk in tileMap.Layers[0].Chunks)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
foreach (var id in chunk.Data)
|
||||||
|
{
|
||||||
|
foreach (var tileSet in tileSets)
|
||||||
|
{
|
||||||
|
if (tileSet.FirstGid - id < 0)
|
||||||
|
{
|
||||||
|
int number = id - tileSet.FirstGid;
|
||||||
|
|
||||||
|
int relativeColumn = number % tileSet.Columns * tileSet.TileWidth;
|
||||||
|
int relativeRow = number / tileSet.Columns * tileSet.TileHeight;
|
||||||
|
|
||||||
|
Rectangle sourceRectangle = new Rectangle(relativeColumn * tileSet.TileWidth, relativeRow * tileSet.TileHeight,
|
||||||
|
relativeColumn * tileSet.TileWidth + tileSet.TileWidth, relativeRow * tileSet.TileHeight + tileSet.TileHeight);
|
||||||
|
|
||||||
|
Vector2 position = new Vector2(i % chunk.Width, i / chunk.Height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private TileSet LoadTileSet(string path)
|
||||||
|
{
|
||||||
|
using (StreamReader reader = new StreamReader(path))
|
||||||
|
{
|
||||||
|
string data = reader.ReadToEnd();
|
||||||
|
return JsonSerializer.Deserialize<TileSet>(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue