本文整理汇总了C++中Tilemap::getTile方法的典型用法代码示例。如果您正苦于以下问题:C++ Tilemap::getTile方法的具体用法?C++ Tilemap::getTile怎么用?C++ Tilemap::getTile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tilemap
的用法示例。
在下文中一共展示了Tilemap::getTile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: scanDistance
double Character::scanDistance(double edge, const Tilemap& map, Direction direction, intVector firstTile, intVector lastTile)
{
double distance;
//indices of tile to be checked
int xi;
int yi;
//to keep track of smallest value
int minDist = 1000000;
int distIndex;
//for each occupied tile, shoot a ray in desired direction
//insert smallest value in distance
for (int i = firstTile.y; i <= lastTile.y; i++)
{
for (int j = firstTile.x; j <= lastTile.x; j++)
{
yi = i;
xi = j;
distIndex = 0;
while (
distIndex < minDist
&& xi >= 0
&& yi >= 0
&& xi < map.horiTiles
&& yi < map.vertiTiles
&& map.getTile(xi, yi) != 1
)
{
switch (direction)
{
case LEFT: xi--; break;
case RIGHT: xi++; break;
case UP: yi--; break;
case DOWN: yi++; break;
}
distIndex++;
}
minDist = min(minDist, distIndex);
}
}
switch (direction)
{
case LEFT: distance = edge - (xi + 1)*map.tileRes; break;
case RIGHT: distance = xi*map.tileRes - edge; break;
case UP: distance = edge - (yi + 1)*map.tileRes; break;
case DOWN: distance = yi*map.tileRes - edge; break;
}
return signbit(distance) ? 0.0 : distance;
}
示例2: checkMapCollision
bool checkMapCollision(Character& scanner, const Tilemap& map)
{
int x1 = scanner.rect.x / map.tileRes;
int x2 = (scanner.rect.x + scanner.rect.w - 1) / map.tileRes;
int y1 = scanner.rect.y / map.tileRes;
int y2 = (scanner.rect.y + scanner.rect.h - 1) / map.tileRes;
for (int x = x1; x <= x2; x++)
{
for (int y = y1; y <= y2; y++)
{
if (x < 0 || x >= map.horiTiles || y < 0 || y >= map.vertiTiles) continue;
if (map.getTile(x, y) == 1) return true;
}
}
return false;
}