Пример #1
0
void gaussianBlur(
    const TileHeat* const tileHeatsIn,
    const float blurFactor,
    TileHeat* const tileHeatsOut
)
{
    for(int tileIndex = 0; tileIndex < eTile_Count; ++tileIndex)
    {
        const Tile currentTile = static_cast<Tile>(tileIndex);
        TileHeat runningTileHeat(tileHeatsIn[tileIndex]);
        float contribution = 1.0f;

        for(int neighbourIndex = 0; neighbourIndex < eTile_Count; ++neighbourIndex)
        {
            const Tile neighbourDirection = static_cast<Tile>(neighbourIndex);
            const Tile neighbour = calculateTile(currentTile, neighbourDirection);

            if (neighbour == eTile_Count)
            {
                continue;
            }

            const TileHeat& neighbourTile = tileHeatsIn[neighbour];
            contribution += blurFactor;

            runningTileHeat.danger += neighbourTile.danger * blurFactor;
            runningTileHeat.desire += neighbourTile.desire * blurFactor;
        }

        runningTileHeat.danger /= contribution;
        runningTileHeat.desire /= contribution;

        tileHeatsOut[tileIndex] = runningTileHeat;
    }
}
Пример #2
0
void ObstacleMapper::mapObstacles()
{
	const int tilesWide = img->w / 16;
	const int tilesHigh = img->h / 16;

	int currentTile;
	TileKeeper* myTiles = new TileKeeper();

	bool isObstacle;
	ofstream obstacles;
	obstacles.open("hannah.txt", ios::app);

	/* iterates through all the image's 16x16 tiles and feeds their boolean value (isObstacle == 1 or isObstacle == 0)
	 to a txt file for processing */
	for (int y = 0; y < tilesHigh; y++)
	{
		for (int x = 0; x < tilesWide; x++)
		{
			isObstacle = calculateTile(x, y);

			// records the map tile in TileKeeper's map and the obstacles.txt file
			myTiles->recordTile(Tile(isObstacle, x, y), std::pair<int, int>(x, y));
			obstacles << isObstacle;

			if (x == tilesWide - 1)
			{
				obstacles << "\n";
			}
		}
	}

	// clean up
	delete myTiles;
	obstacles.close();
}