所以我正在制作一个基于瓷砖的游戏,我想在瓷砖上添加一些假阴影。这有点难以解释,所以我会用图片来做:
假设这是我的瓷砖世界:
我希望它有这样的阴影:
因为世界是基于瓦片的,所以我可以将所有阴影部分拆分为单独的图像:
但现在我不知道如何将它带到代码中。好吧,实际上我确实有一些想法,但它们非常乏味,而且它们不能以最佳方式工作。
我尝试了一个巨大的if语句......
bool ul = adjacentBlocks[0, 0] == Block.Type.Rock; //Upper Left
bool um = adjacentBlocks[1, 0] == Block.Type.Rock; //Upper Middle
bool ur = adjacentBlocks[2, 0] == Block.Type.Rock; //Upper Right
bool ml = adjacentBlocks[0, 1] == Block.Type.Rock; //Center Left
//bool cm = adjacentBlocks[1, 1] == Block.Type.Rock; //CURRENT BLOCK - NOT NEEDED
bool mr = adjacentBlocks[2, 1] == Block.Type.Rock; //Center Right
bool ll = adjacentBlocks[0, 2] == Block.Type.Rock; //Lower Left
bool lm = adjacentBlocks[1, 2] == Block.Type.Rock; //Lower Middle
bool lr = adjacentBlocks[2, 2] == Block.Type.Rock; //Lower Right
if (ml) { texture = "Horizontal"; flipX = false; flipY = false; }
if (mr) { texture = "Horizontal"; flipX = true; flipY = false; }
if (um) { texture = "Vertical"; flipX = false; flipY = false; }
if (lm) { texture = "Vertical"; flipX = false; flipY = true; }
if (ml && ul && um) texture = "HorizontalVertical";
//More if statements I can't be bothered to write
if (ul && um && ur && ml && mr && ll && lm & lr) texture = "Full";
还有一个庞大的查找表...
var table = new List<TextureBlockLayout>
{
new TextureBlockLayout("Horizontal", false, false, new[,]
{
{ true, true, false },
{ true, true, false },
{ true, true, false }
}),
new TextureBlockLayout("Horizontal", true, false, new[,]
{
{ false, true, true },
{ false, true, true },
{ false, true, true }
}),
new TextureBlockLayout("Full", false, false, new[,]
{
{ true, true, true },
{ true, true, true },
{ true, true, true }
})
};
但要么我做错了什么,要么他们根本拒绝工作。有任何想法吗?