-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTilemap.cs
72 lines (60 loc) · 1.74 KB
/
Tilemap.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace BMP2Tile
{
internal class Tilemap : IEnumerable<Tilemap.Entry>
{
internal class Entry
{
public int TileIndex { get; set; }
public bool HFlip { get; set; }
public bool VFlip { get; set; }
public bool HighPriority { get; set; }
public bool UseSpritePalette { get; set; }
public int GetValue()
{
var result = TileIndex & 0b111111111;
if (HFlip)
{
result |= 1 << 9;
}
if (VFlip)
{
result |= 1 << 10;
}
if (UseSpritePalette)
{
result |= 1 << 11;
}
if (HighPriority)
{
result |= 1 << 12;
}
return result;
}
}
public int Width { get; }
public int Height { get; }
public Tilemap(int width, int height)
{
Width = width;
Height = height;
_tilemap = new Entry[width, height];
}
public Entry this[int x, int y]
{
get => _tilemap[x, y];
set => _tilemap[x, y] = value;
}
private readonly Entry[,] _tilemap;
public IEnumerator<Entry> GetEnumerator()
{
return _tilemap.Cast<Entry>().GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return _tilemap.GetEnumerator();
}
}
}