Ejemplo n.º 1
0
void Map::UpdateTile(const Tile& tile)
{
	//tile Range Check
	if (tile.GetX() < 0 || tile.GetX() >= MAP_ROW) return;
	if (tile.GetY() < 0 || tile.GetY() >= MAP_COL) return;

	int row = Utility::Instance().RowOfPoint(tile);
	int col = Utility::Instance().ColOfPoint(tile);
	m_Tiles[row][col].SetTileState(tile.GetTileState());
}
Ejemplo n.º 2
0
void Map::SetTile(const Tile& tile)
{
	//tile Range Check
	if (tile.GetX() < 0 || tile.GetX() >= MAP_ROW) return;
	if (tile.GetY() < 0 || tile.GetY() >= MAP_COL) return;

	int row = Utility::Instance().RowOfPoint(tile);
	int col = Utility::Instance().ColOfPoint(tile);
	m_Tiles[row][col] = tile;
	//printf("(%d,%d)\n", Utility::Instance().RowOfPoint(tile), Utility::Instance().ColOfPoint(tile));
}
Ejemplo n.º 3
0
bool World::CalculatePath(Vector &start, Vector &finish, std::vector<Vector> &path)
{
    Tile *start_tile = GetTile(start);

    if(!start_tile)
    {
        return false;
    }

    Tile *finish_tile = GetTile(finish);

    if(!finish_tile)
    {
        return false;
    }

    bool result = TileMap::CalculatePath(start_tile, finish_tile);

    if(result)
    {
        for(Tile *tile = GetTile(finish); tile; tile = tile->GetParent())
        {
            path.emplace(path.begin(),
                (TileW * tile->GetX()) + (TileW / 2),
                (TileH * tile->GetY()) + (TileH / 2)
            );
        }

    }

    return result;
}
Ejemplo n.º 4
0
Tile::Tile(const Tile & src)
{
	m_ShipType = src.m_ShipType;
	m_ShipId = src.m_ShipId;
	m_TileState = src.m_TileState;
	SetX(src.GetX());
	SetY(src.GetY());
}
Ejemplo n.º 5
0
 void Generator::PostProcessTile(Map& map, Tile& tile, std::map<std::pair<unsigned int, unsigned int>, unsigned int>& tiles, unsigned int id)
 {
     unsigned int x = tile.GetX();
     unsigned int y = tile.GetY();
     Tile* tile2 = map.GetTile(x - 1, y);
     if (tile2 && !tile2->IsBlocked())
     {
         std::map<std::pair<unsigned int, unsigned int>, unsigned int>::iterator itr = tiles.find(std::make_pair(tile2->GetX(), tile2->GetY()));
         if (itr == tiles.end())
         {
             tiles.insert(std::make_pair(std::make_pair(tile2->GetX(), tile2->GetY()), id));
             PostProcessTile(map, *tile2, tiles, id);
         }
     }
     tile2 = map.GetTile(x + 1, y);
     if (tile2 && !tile2->IsBlocked())
     {
         std::map<std::pair<unsigned int, unsigned int>, unsigned int>::iterator itr = tiles.find(std::make_pair(tile2->GetX(), tile2->GetY()));
         if (itr == tiles.end())
         {
             tiles.insert(std::make_pair(std::make_pair(tile2->GetX(), tile2->GetY()), id));
             PostProcessTile(map, *tile2, tiles, id);
         }
     }
     tile2 = map.GetTile(x, y - 1);
     if (tile2 && !tile2->IsBlocked())
     {
         std::map<std::pair<unsigned int, unsigned int>, unsigned int>::iterator itr = tiles.find(std::make_pair(tile2->GetX(), tile2->GetY()));
         if (itr == tiles.end())
         {
             tiles.insert(std::make_pair(std::make_pair(tile2->GetX(), tile2->GetY()), id));
             PostProcessTile(map, *tile2, tiles, id);
         }
     }
     tile2 = map.GetTile(x, y + 1);
     if (tile2 && !tile2->IsBlocked())
     {
         std::map<std::pair<unsigned int, unsigned int>, unsigned int>::iterator itr = tiles.find(std::make_pair(tile2->GetX(), tile2->GetY()));
         if (itr == tiles.end())
         {
             tiles.insert(std::make_pair(std::make_pair(tile2->GetX(), tile2->GetY()), id));
             PostProcessTile(map, *tile2, tiles, id);
         }
     }
 }