好吧,我正在制作一个小型的基于瓦片的挖掘游戏,现在我想要做碰撞。我会如何正确地做这件事?我知道如何检查玩家是否与瓦片发生碰撞,但是我不知道如何让玩家在碰到墙壁时停下来。平铺引擎碰撞
这是游戏,我得到了20×20瓦这里。
这是代码我使用ATM:
foreach (Tile tiles in allTiles)
{
if (ply.rect.Intersects(tiles.rect))
{
if (tiles.ID != -1 && tiles.ID != 1)
{
if (ply.X > tiles.X)
{
Console.WriteLine("Right part.");
ply.X = tiles.pos.X + 30;
}
if (ply.X <= tiles.X)
{
Console.WriteLine("Left part.");
ply.X = tiles.pos.X - 30;
}
if (ply.Y > tiles.Y)
{
Console.WriteLine("Bottom part.");
ply.Y = tiles.pos.Y + 30;
}
if (ply.Y <= tiles.Y)
{
Console.WriteLine("Upper part.");
ply.Y = tiles.pos.Y - 30;
}
}
}
}
您是否在制作['Terraria'](http://terraria.org/)? – Marty 2012-03-26 00:30:40
@Marty华莱士:嗯,我正在做一些克隆,是的。 – Stan 2012-03-26 05:36:02
啊,真棒^ _^ – Marty 2012-03-26 05:37:59