shroud tidy up

This commit is contained in:
Chris Forbes
2010-01-08 19:48:29 +13:00
parent dfd9742c04
commit 431036c2f2

View File

@@ -27,20 +27,29 @@ namespace OpenRa.Game
dirty = true; dirty = true;
} }
static readonly byte[] ShroudTiles =
{
0xf,0xf,0xf,0xf,
0xf,0xf,0xf,0xf,
0xf,0xf,0xf,0xf,
0xf,0xf,0xf,0xf,
0,7,13,0,
14,6,12,4,
11,3,9,1,
0,2,8,0,
};
static readonly byte[] ExtraShroudTiles =
{
46, 41, 42, 38,
43, 45, 39, 35,
40, 37, 44, 34,
36, 33, 32, 47,
};
Sprite ChooseShroud(int i, int j) Sprite ChooseShroud(int i, int j)
{ {
// bits are for exploredness: left, right, up, down, self // bits are for exploredness: left, right, up, down, self
var n = new[] {
0xf,0xf,0xf,0xf,
0xf,0x0f,0x0f,0xf,
0xf,0x0f,0x0f,0xf,
0xf,0xf,0xf,0xf,
0,7,13,0,
14,6,12,4,
11,3,9,1,
0,2,8,0,
};
var v = 0; var v = 0;
if (explored[i - 1, j]) v |= 1; if (explored[i - 1, j]) v |= 1;
if (explored[i + 1, j]) v |= 2; if (explored[i + 1, j]) v |= 2;
@@ -48,27 +57,17 @@ namespace OpenRa.Game
if (explored[i, j + 1]) v |= 8; if (explored[i, j + 1]) v |= 8;
if (explored[i, j]) v |= 16; if (explored[i, j]) v |= 16;
var x = n[v]; var x = ShroudTiles[v];
if (x != 0)
return shadowBits[x];
if (x == 0) // bits are for exploredness: TL, TR, BR, BL
{ var u = 0;
// bits are for exploredness: TL, TR, BR, BL if (explored[i - 1, j - 1]) u |= 1;
var m = new[] { if (explored[i + 1, j - 1]) u |= 2;
46, 41, 42, 38, if (explored[i + 1, j + 1]) u |= 4;
43, 45, 39, 35, if (explored[i - 1, j + 1]) u |= 8;
40, 37, 44, 34, return shadowBits[ExtraShroudTiles[u]];
36, 33, 32, 47,
};
var u = 0;
if (explored[i - 1, j - 1]) u |= 1;
if (explored[i + 1, j - 1]) u |= 2;
if (explored[i + 1, j + 1]) u |= 4;
if (explored[i - 1, j + 1]) u |= 8;
return shadowBits[m[u]];
}
return shadowBits[x];
} }
public void Draw(SpriteRenderer r) public void Draw(SpriteRenderer r)