- Ja llig correctament el mapa en format text
This commit is contained in:
@@ -9,9 +9,20 @@ namespace textfile
|
|||||||
int fsize = 0;
|
int fsize = 0;
|
||||||
int p = 0;
|
int p = 0;
|
||||||
|
|
||||||
|
const int toInt(std::string token)
|
||||||
|
{
|
||||||
|
int value = 0;
|
||||||
|
for (std::size_t i=0; i<token.length(); ++i)
|
||||||
|
{
|
||||||
|
if (token[i]<48 || token[i]>57) return 0;
|
||||||
|
value = (value*10) + (token[i]-48);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
const bool open(std::string filename)
|
const bool open(std::string filename)
|
||||||
{
|
{
|
||||||
buffer = file::getFileBuffer(filename.c_str());
|
buffer = file::getFileBuffer(filename.c_str(), &fsize);
|
||||||
p = 0;
|
p = 0;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -52,6 +63,6 @@ namespace textfile
|
|||||||
|
|
||||||
const int getIntValue(std::string token)
|
const int getIntValue(std::string token)
|
||||||
{
|
{
|
||||||
return std::stoi(getStringValue(token));
|
return toInt(getStringValue(token));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
namespace textfile
|
namespace textfile
|
||||||
{
|
{
|
||||||
|
const int toInt(std::string token);
|
||||||
|
|
||||||
const bool open(std::string filename);
|
const bool open(std::string filename);
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace mapa
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
textfile::searchToken("LEVEL");
|
textfile::searchToken("LEVEL");
|
||||||
} while (std::stoi(textfile::getNextToken()) != game::getConfig("fase"));
|
} while (textfile::toInt(textfile::getNextToken()) != game::getConfig("fase"));
|
||||||
|
|
||||||
const int tileset = textfile::getIntValue("tileset");
|
const int tileset = textfile::getIntValue("tileset");
|
||||||
arounders::orientacio_inicial = textfile::getIntValue("orientacio");
|
arounders::orientacio_inicial = textfile::getIntValue("orientacio");
|
||||||
@@ -58,10 +58,10 @@ namespace mapa
|
|||||||
accions::corda = textfile::getIntValue("corda");
|
accions::corda = textfile::getIntValue("corda");
|
||||||
|
|
||||||
ini_x = textfile::getIntValue("inici");
|
ini_x = textfile::getIntValue("inici");
|
||||||
ini_y = std::stoi(textfile::getNextToken());
|
ini_y = textfile::toInt(textfile::getNextToken());
|
||||||
|
|
||||||
fin_x = textfile::getIntValue("final");
|
fin_x = textfile::getIntValue("final");
|
||||||
fin_y = std::stoi(textfile::getNextToken());
|
fin_y = textfile::toInt(textfile::getNextToken());
|
||||||
|
|
||||||
//int tilemap[200];
|
//int tilemap[200];
|
||||||
//for (int y=0; y<10; ++y) for (int x=0; x<10; ++x) fscanf(f, "%i", &tilemap[x+y*20]);
|
//for (int y=0; y<10; ++y) for (int x=0; x<10; ++x) fscanf(f, "%i", &tilemap[x+y*20]);
|
||||||
@@ -76,13 +76,13 @@ namespace mapa
|
|||||||
for (int y=0; y<10; ++y)
|
for (int y=0; y<10; ++y)
|
||||||
for (int x=0; x<10; ++x)
|
for (int x=0; x<10; ++x)
|
||||||
{
|
{
|
||||||
int tile; fscanf(f, "%i", &tile);
|
int tile = textfile::toInt(textfile::getNextToken());
|
||||||
if (tile > 0) draw::draw(x*16, y*16, 16, 16, (tile-1)*16, tileset*16);
|
if (tile > 0) draw::draw(x*16, y*16, 16, 16, (tile-1)*16, tileset*16);
|
||||||
}
|
}
|
||||||
|
|
||||||
draw::freeSurface(tiles);
|
draw::freeSurface(tiles);
|
||||||
|
|
||||||
textfile::fclose();
|
textfile::close();
|
||||||
|
|
||||||
draw::surface *marcador = draw::loadSurface("marcador.gif");
|
draw::surface *marcador = draw::loadSurface("marcador.gif");
|
||||||
draw::setSource(marcador);
|
draw::setSource(marcador);
|
||||||
|
|||||||
Reference in New Issue
Block a user