I mostly used tonypa’s excellent guide to create tile-based map-editing code for an RPG. However, I’m having great difficulty with changing maps…
Here’s the bits of code that I think are relevant;
map1 = [[0,0,0,0,0,0],
[0,1,2,1,2,0],
[4,3,4,3,4,101],
[0,1,2,1,2,0],
[0,0,0,0,0,0]];
map2 = [[0,0,4,3,0,0],
[0,1,2,1,2,0],
[202,3,0,0,4,0],
[0,1,2,1,2,0],
[0,0,0,0,0,0]];
game.Doors = function (newMap, newherox, newheroy, enterx, entery) {
this.enterx=enterx;
this.entery=entery;
if (enterx == -1 || 1) {
if (enterx == 1) {
if (dirx == 1) {
this.newMap=newMap;
this.newherox=newherox;
this.newheroy=newheroy;
}
} else {
if (dirx == -1) {
this.newMap=newMap;
this.newherox=newherox;
this.newheroy=newheroy;
}
}
}
if (entery == -1 || 1) {
if (entery == 1) {
if (diry == 1) {
this.newMap=newMap;
this.newherox=newherox;
this.newheroy=newheroy;
}
} else {
if (diry == -1) {
this.newMap=newMap;
this.newherox=newherox;
this.newheroy=newheroy;
}
}
}
};
game.Doors.prototype.nobarrier=true;
game.Doors.prototype.door=true;
game.Tile101 = function () { };
game.Tile101.prototype = new game.Doors(2, 0, 2, 1, 0);
game.Tile101.prototype.frame = 4;
game.Tile202 = function () { };
game.Tile202.prototype = new game.Doors(1, 6, 2, -1, 0);
game.Tile202.prototype.frame = 5;
function moveHero(ob, dirx, diry) {
getMyCorners (ob.x, ob.y+ob.speed*diry, ob);
if (diry == -1) {
if (ob.upleft && ob.upright) {
ob.y += ob.speed*diry;
} else {
ob.y = ob.ytile*game.tileH+ob.height+1;
ob.clip.hero.gotoAndStop(1);
}
}
if (diry == 1) {
if (ob.downleft && ob.downright) {
ob.y += ob.speed*diry;
} else {
ob.y = (ob.ytile+1)*game.tileH-ob.height;
ob.clip.hero.gotoAndStop(1);
}
}
getMyCorners (ob.x+ob.speed*dirx, ob.y, ob);
if (dirx == 1) {
if (ob.upright && ob.downright) {
ob.x += ob.speed*dirx;
} else {
ob.x = (ob.xtile+1)*game.tileW-ob.width;
ob.clip.hero.gotoAndStop(1);
}
}
if (dirx == -1) {
if (ob.upleft && ob.downleft) {
ob.x += ob.speed*dirx;
} else {
ob.x = ob.xtile*game.tileW+ob.width;
ob.clip.hero.gotoAndStop(1);
}
}
if(game["t_"+ob.ytile+"_"+ob.xtile].door && ob == _root.hero)
{
changeMap(ob);
}
ob.clip.gotoAndStop(dirx+diry*2+3);
ob.clip._x = ob.x;
ob.clip._y = ob.y;
ob.xtile = Math.floor(ob.x/game.tileW);
ob.ytile = Math.floor(ob.y/game.tileH);
return(true);
}
function changeMap(ob) {
var name = "t_"+ob.ytile+"_"+ob.xtile;
game.currentMap = game[name].newMap;
ob.ytile = game[name].newheroy;
ob.xtile = game[name].newherox;
ob.frame = ob.clip._currentframe;
buildMap(_root["map"+game.currentMap]);
}
I’m happy to provide more bits of code if needed, but I think the problem is somewhere in here. dirx and diry have values of either “1” or “-1”, and refer of course to which key is down.
The problem I’m GETTING is, where buildMap function should be getting the second of the map arrays I built and, well, building it, it just creates a blank screen…not sure why.