【发布时间】:2013-11-09 10:18:20
【问题描述】:
我的第一个等距游戏有问题。我不知道该怎么做才能让我的球员接近墙的边缘。此时玩家可能会在绿色区域内移动。
我的地图:
int[,] map = new int[,]
{
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1}
};
变量:
int TileWidth = 50;
int TileHeight = 50;
int posX = 2; // map X position
int posY = 2; // map Y position
float playerX = 2 * 50; // player X position
float playerY = 2 * 50; // player Y position
检测墙:
public bool detectSolidTile(int x, int y)
{
if (map[y, x] == 1) return true; else return false;
}
移动:
posX = (int)(Math.Floor((playerX) / 50));
posY = (int)(Math.Floor(playerY / 50));
(...)
if (slide == 1 && !detectSolidTile(posX + 1, posY))
{
playerX++;
}
if (slide == 2 && !detectSolidTile(posX - 1, posY))
{
playerX--;
}
图片 -> http://s16.postimg.org/cxkfomemd/tiles.jpg
我需要改进什么才能在墙之间移动?
最好的问候,克日谢克
【问题讨论】: