我正在开发一个地图编辑器来配合我一直在开发的游戏;但是,当我尝试将地图加载到游戏中时,所有内容都向右移动了两三个瓷砖。
我的一个朋友建议这可能是一个寻址错误,尽管我从未见过任何这样的证据。
这是加载函数(它在主循环之前被调用):
const int SAVEGAME_VERSION=0x1100;
void Engine::load(bool pause) {
TCODZip zip;
engine.gui->menu.clear();
engine.gui->menu.addItem(Menu::NEW_GAME,"New map");
if ( TCODSystem::fileExists("map.atm")) {
zip.loadFromFile("map.atm");
int version = zip.getInt();
if ( version == SAVEGAME_VERSION ) {
engine.gui->menu.addItem(Menu::CONTINUE,"Load");
}
}
engine.gui->menu.addItem(Menu::EXIT,"Exit");
Menu::MenuItemCode menuItem=engine.gui->menu.pick(
pause ? Menu::PAUSE : Menu::MAIN);
if ( menuItem == Menu::EXIT || menuItem == Menu::NONE ) {
// Exit or window closed
exit(0);
} else if ( menuItem == Menu::NEW_GAME ) {
// New game
engine.term();
engine.init();
} else {
// continue a saved game
engine.term();
// load the map
level=zip.getInt();
int width=zip.getInt();
int height=zip.getInt();
map = new Map(width,height);
map->load(zip);
// then the player
player=new Actor(0,0,0,NULL,TCODColor::white);
actors.push(player);
player->load(zip);
// then all other actors
int nbActors=zip.getInt();
while ( nbActors > 0 ) {
Actor *actor = new Actor(0,0,0,NULL,TCODColor::white);
actor->load(zip);
actors.push(actor);
nbActors--;
}
// finally the message log
gui->load(zip);
}
}
这是 map->init 函数(从 Engine::init 调用并为新游戏设置地图的尺寸):
void Map::init(bool withActors) {
TCODZip zip;
if ( TCODSystem::fileExists("map.atm")) {
zip.loadFromFile("map.atm");
//rng = new TCODRandom(seed, TCOD_RNG_CMWC);
tiles=new Tile[width*height];
map=new TCODMap(width,height);
for (int i=0; i < width*height; i++) {
tiles[i].canWalk=zip.getInt();
//TCODBsp bsp(0,0,width,height);
//bsp.splitRecursive(rng,8,ROOM_MAX_SIZE,ROOM_MAX_SIZE,1.5f,1.5f);
//BspListener listener(*this);
//bsp.traverseInvertedLevelOrder(&listener,(void *)withActors);
}
}
}