Siemka! Pisze z zapytaniem o tile mapy. Sądzę, że mój kod lekko mówiąc jest troszeczkę prymitywny. Dokładnie chciałbym się dowiedzieć co mógłbym zmienić, jak mógłbym zmienić i mniej więcej jak mógłbym zmienić.
void Game::Init(SDL_Renderer *renderer)
{
LoadGameDate(renderer);
Load("tileMap");
}
void Game::Draw(SDL_Renderer *renderer)
{
for (int y = 0; y < tileMap.size(); y++)
for (int x = tileMap[y].size(); x++)
if (tileMap[y][x] != '0')
{
SDL_Rect destination;
SDL_Rect source;
source.w = 40;
source.h = 40;
source.x = blockChar * srcRect.w;
source.y = 0;
destination.x = x * 40;
destination.y = y * 40;
destination.w = 40;
destination.h = 40;
tile.Render(source, destination, renderer);
}
}
void Game::Load(std::string fileName)
{
fileName = "Files/" + fileName + ".map";
std::ifstream openFile(fileName);
tileMap.clear();
if (openFile.is_open())
{
while (!openFile.eof())
{
std::string line;
std::getline(openFile, line);
std::vector<char> tempVector;
if (line.find("[map]") != std::string::npos)
{
state = MAP;
tempVector.clear();
continue;
}
std::stringstream str(line);
while (str)
{
std::getline(str, line, ' ');
if (line != "")
if (state == MAP)
{
tempVector.push_back(line);
}
}
if (state == MAP)
{
tileMap.push_back(tempVector);
}
}
}
openFile.clear();
openFile.close();
}
void LoadGameDate(SDL_Renderer *renderer)
{
tile.LoadFromFile("TileMap.png", renderer);
}
Jak widać, to tylko klika krótkich metod.