c++ - Tiles shifting to the right -
i'm working on map editor accompany game i've been working on time; when effort load map game, however, shifted 2 or 3 tiles right.
a friend of mine suggested might addressing error, though i've never seen evidence of such.
here's loading function (it's called before main loop):
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 { // go on saved game engine.term(); // load map level=zip.getint(); int width=zip.getint(); int height=zip.getint(); map = new map(width,height); map->load(zip); // player player=new actor(0,0,0,null,tcodcolor::white); actors.push(player); player->load(zip); // 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--; } // message log gui->load(zip); } }
and map->init function (which called engine::init , sets map's dimensions new game):
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); (int i=0; < 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); } } }
c++ loading tiling
No comments:
Post a Comment