-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTileset.cs
49 lines (45 loc) · 1.53 KB
/
Tileset.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PandoraTest1
{
public class Tileset
{
//private bool _initialized = false;
public string name;
public Texture2D texture;
public string texturePath;
public int tileSize;
public int tilesWide { get { return texture.Width / tileSize; } }
public int tilesHigh { get { return texture.Height / tileSize; } }
public List<TilesetTile> tiles = new List<TilesetTile>();
public void Initialize(Texture2D _texture)
{
texture = _texture;
for (int ih = 0; ih < tilesHigh; ih++)
{
for (int iw = 0; iw < tilesWide; iw++)
{
int tilePos = iw + (ih * tilesWide);
TilesetTile t = new TilesetTile(tilePos);
tiles.Add(t);
}
}
}
public TilesetTile GetTilesetTile(int tileId)
{
return tiles.FirstOrDefault(t => t.tileId == tileId);
}
public Rectangle GetTileRect(int tileId)
{
int x = (tileId % tilesWide);
int y = (tileId / tilesWide);
// tileID 15 - 6 tiles wide / 012345 678901 234567 - row 3 tile 4 / row 2 tile 3
// 15 % 6 is 3, 15 / 6 is 2... truncated to 2
return new Rectangle(x * tileSize, y * tileSize, tileSize, tileSize);
}
}
}