| 赞 | 0 |
| VIP | |
| 好人卡 | |
| 积分 | 2 |
| 经验 | |
| 最后登录 | 2022-12-28 |
| 在线时间 | 39 小时 |
- 梦石
- 0
- 星屑
- 162
- 在线时间
- 39 小时
- 注册时间
- 2022-3-14
- 回帖
- 15
|
悬赏20星屑已解决
这几天一直在研究随机迷宫,已经能够做出随机迷宫了(虽然迷宫的顶还不够完善),但现在一个最大的问题:
使用插件命令,生成迷宫后,打开各种菜单返回后,直接就会变成未生成随机迷宫的地图。。。
脚本小白一个,实在是找不到原因了,求大神解答下:
使用了 $dataMap.data[posi] =X; 去改变图块,用refresh()可以刷新出随机迷宫 ,但 $dataMap.data的值还是原json里的data值。。。所以一旦打开菜单、商店再返回地图时,就会回到原先的样子
感觉就像是没写入(确实也不知道怎么写入)
mapnow=SceneManager._scene._spriteset._tilemap;
mapnow.refresh(); 可以让迷宫正常显示
是不是这句话有问题
点击展开/收起//=============================================================================
// Laoyao_RandomMap.js
//=============================================================================
/*:
* PLUGIN COMMAND
*
* 迷宫刷新
*
*/
//=============================================================================
// ** PLUGIN PARAMETERS
//=============================================================================
//=============================================================================
// ** PLUGIN PARAMETERS
//=============================================================================
var Imported = Imported || {};
Imported.Laoyao_RandomMap = true;
var Laoyao = Laoyao || {};
Laoyao.parameters = PluginManager.parameters('Laoyao_RandomMap');
Laoyao.randomMapvisible = String(Moghunter.parameters['Initial Visible'] || "true");
//=============================================================================
// ** Game_System
//=============================================================================
//==============================
// * Initialize
//==============================
var Laoyao_RandomMap_sys_initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
Laoyao_RandomMap_sys_initialize.call(this);
this._RandomMap_visible = String(Laoyao.randomMapvisible) === "true" ? true : false;
};
//=============================================================================
// ** Game_Interpreter
//=============================================================================
//==============================
// * PluginCommand
//==============================
var Laoyao_RandomMap_pluginCommand = Game_Interpreter.prototype.pluginCommand
Game_Interpreter.prototype.pluginCommand = function(command, args) {
Laoyao_RandomMap_pluginCommand.call(this,command, args)
if (command === "迷宫刷新"){
//先随便找个房间作为起点
HouseX=prnd(1,6);
HouseY=prnd(1,4);
YuanX=HouseX;
YuanY=HouseY;
YuanX=1;
YuanY=1;
HouseNo=YuanY*10+YuanX;
//当前最高层数设置为10
//FloorMax=$gameVariables(1001);
for(j=1;j<=2;j++){
HouseX=YuanX;
HouseY=YuanY;
FloorMax=10;
FloorNow=2;
LineA="01-02-03-04-05-06-10-20-30-40-51-52-53-54-55-56-17-27-37-47-"+HouseNo+"-";
for (i=1;i<=999999999;i++){
//随机选个方向
NewHouseY=HouseY;
NewHouseX=HouseX;
arrows=prnd(1,4);
if (arrows===1 && HouseY>1){
NewHouseY=HouseY-1;
NewHouseX=HouseX;
};
if (arrows===2 && HouseY<4){
NewHouseY=HouseY+1;
NewHouseX=HouseX;
};
if (arrows===3 && HouseX>1){
NewHouseX=HouseX-1;
NewHouseY=HouseY;
};
if (arrows===4 && HouseX<6){
NewHouseX=HouseX+1;
NewHouseY=HouseY;
};
NewHouse=NewHouseY*10+NewHouseX;
NewHouseStr=NewHouse+"-";
if(LineA.indexOf(NewHouseStr)===-1){//不包括就可以走
LineA=LineA+NewHouseStr;
HouseX=NewHouseX;
HouseY=NewHouseY;
FloorNow=FloorNow+1;
if(FloorNow>FloorMax){
break;
};
if(LineA.indexOf(repts((HouseY-1)*10+HouseX,2)+"-")!=-1 && LineA.indexOf((HouseY+1)*10+HouseX+"-")!=-1 && LineA.indexOf(HouseY*10+HouseX+1+"-")!=-1 && LineA.indexOf(HouseY*10+HouseX-1+"-")!=-1){
break;
};
};
};
$gameVariables.setValue(1000+j,LineA.substring(60));
};
$gameVariables.setValue(1003,"AA-"+$gameVariables.value(1001)+"BB-"+$gameVariables.value(1002));
};
if (command === "迷宫读取"){
LineS=$gameVariables.value(1003);
Fenge=LineS.indexOf("BB-");
LineG=[LineS.substring(3,Fenge),LineS.substring(Fenge+3)];
//读取设置的默认图块
tile_wall=$gameMap.layeredTiles(0, 0);
tile_road=$gameMap.layeredTiles(1, 0);
alert(tile_wall);
mapx=81;//当前地图列数
mapy=67;//当前地图行数
cellx=9;//每一小区域的列数
celly=9;//每一小区域的行数
firstx=11;//开始列
firsty=13;//开始行
migongx=6;//迷宫格数
migongy=4;
mapnow=SceneManager._scene._spriteset._tilemap;
//计算每个地图的中间通道的位置XY
//先算横的
roadx="0,0,0,0,0,0,0,0,0,0,";
roady="0,0,0,0,0,0,0,0,0,0,";
for(ia=1;ia<=migongy;ia++){
for(j1=1;j1<=migongx-1;j1++){
lsx=firstx+(cellx+1)*j1-1;
roadx=roadx+String(lsx)+",";
lsy=firsty+Math.trunc(celly/2)-1+(celly+2)*(ia-1);
roady=roady+String(lsy)+",";
};
roadx=roadx+repeat("0,",10-migongx+1);
roady=roady+repeat("0,",10-migongx+1);
};
roadx=roadx+repeat("0,",100-migongy*10);
roady=roady+repeat("0,",100-migongy*10);
//再算竖的
for(ic=1;ic<=migongy-1;ic++){
for(jb=1;jb<=migongx;jb++){
lsx=firstx+Math.trunc(cellx/2)+(cellx+1)*(jb-1);
roadx=roadx+String(lsx)+",";
lsy=firsty+(celly+2)*ic-2;
roady=roady+String(lsy)+",";
};
roadx=roadx+repeat("0,",10-migongx);
roady=roady+repeat("0,",10-migongx);
};
roadxx=roadx.split(",");
roadyy=roady.split(",");
//alert(roadx);
//alert(roady);
//根据走势图判断迷宫的哪些开关打开
for(ii=0;ii<=1;ii++){
for(jj=1;jj<=LineG[ii].length/3-1;jj++){
lsstr1=LineG[ii].substr((jj-1)*3,6);
lsstra=lsstr1.substr(0,2)*1;
lsstrb=lsstr1.substr(3,2)*1;
if(lsstra>lsstrb){
baba=lsstra;
lsstra=lsstrb;
lsstrb=baba;
}
if(lsstrb-lsstra===1){
posi_tt1=(mapy +Number(roadyy[lsstra-1]))*mapx+Number(roadxx[lsstra-1]);
posi_tt2=(mapy +Number(roadyy[lsstra-1])+1)*mapx+Number(roadxx[lsstra-1]);
posi_tt3=(mapy +Number(roadyy[lsstra-1])+1)*mapx+Number(roadxx[lsstra-1])+1;
posi_tt4=(mapy +Number(roadyy[lsstra-1])+1)*mapx+Number(roadxx[lsstra-1])-1;
$dataMap.data[posi_tt1] =tile_wall[3];
$dataMap.data[posi_tt2] =tile_road[3]-11;
$dataMap.data[posi_tt3] =tile_road[3]-35;
$dataMap.data[posi_tt4] =tile_road[3]-38;
}else if(lsstrb-lsstra===10){
posi_tt1=(mapy +Number(roadyy[lsstra+100-1]))*mapx+Number(roadxx[lsstra+100-1]);
posi_tt2=(mapy +Number(roadyy[lsstra+100-1])+1)*mapx+Number(roadxx[lsstra+100-1]);
posi_tt3=(mapy +Number(roadyy[lsstra+100-1])-1)*mapx+Number(roadxx[lsstra+100-1]);
posi_tt4=(mapy +Number(roadyy[lsstra+100-1])+2)*mapx+Number(roadxx[lsstra+100-1]);
$dataMap.data[posi_tt1] =tile_road[3]-12;
$dataMap.data[posi_tt2] =tile_road[3]-12;
$dataMap.data[posi_tt3] =tile_road[3]-32;
$dataMap.data[posi_tt4] =tile_road[3]-41;
};
};
};
mapnow.refresh();
$gameVariables.setValue(1001,LineG[0].length/3-1);
};
if (command === "迷宫随机"){
//先随便找个房间作为起点
mapx=$gameMap.width();
mapy=$gameMap.height();
YuanX=1;//最左上角的点
YuanY=10;
Yuan_Wid=mapx-2;//迷宫宽
Yuan_Hei=mapy-12;//迷宫高
HouseX=prnd(YuanX,Yuan_Wid+YuanX-1);
HouseY=prnd(YuanY,Yuan_Hei+YuanY-1);
StartX=HouseX; //出发点
StartY=HouseY;
StartX=6; //出发点
StartY=15;
HouseNo=repts(StartX,2)+repts(StartY,2)+"-";
//当前最高层数设置为10
//FloorMax=$gameVariables(1001);
for(j=1;j<=1;j++){
HouseX=StartX;
HouseY=StartY;
FloorMax=400;
FloorNow=2;
LineAA="";
for(k=YuanX;k<=Yuan_Wid+YuanX-1;k++){
LineAA=LineAA+repts(k,2)+repts(YuanY-1,2)+"-";
LineAA=LineAA+repts(k,2)+repts(Yuan_Hei+YuanY,2)+"-";
};
for(k=YuanY;k<=Yuan_Hei+YuanY-1;k++){
LineAA=LineAA+repts(YuanX-1,2)+repts(k,2)+"-";
LineAA=LineAA+repts(Yuan_Wid+YuanX,2)+repts(k,2)+"-";
};
LineA=LineAA+HouseNo;
ceshi=0;
for (i=1;i<=999999999;i++){
if(LineA.indexOf(repts(HouseX-1,2)+repts(HouseY,2)+"-")!=-1 && LineA.indexOf(repts(HouseX+1,2)+repts(HouseY,2)+"-")!=-1 && LineA.indexOf(repts(HouseX-0,2)+repts(HouseY+1,2)+"-")!=-1 && LineA.indexOf(repts(HouseX-0,2)+repts(HouseY-1,2)+"-")!=-1){
lsstre=LineA.substring(5*Yuan_Wid*2+5*Yuan_Hei*2);
lsstrc=prnd(1,lsstre.length/5);
lsstrd=lsstre.substr(lsstrc*5-5,5);
HouseX=Number(lsstrd.substr(0,2));
HouseY=Number(lsstrd.substr(2,2));
}else{
//随机选个方向
NewHouseY=HouseY;
NewHouseX=HouseX;
arrows=prnd(1,4);
if (arrows===1 && HouseY>YuanY){
NewHouseY=HouseY-1;
NewHouseX=HouseX;
};
if (arrows===2 && HouseY<mapy+YuanY){
NewHouseY=HouseY+1;
NewHouseX=HouseX;
};
if (arrows===3 && HouseX>=YuanX){
NewHouseX=HouseX-1;
NewHouseY=HouseY;
};
if (arrows===4 && HouseX<mapx+YuanX){
NewHouseX=HouseX+1;
NewHouseY=HouseY;
};
NewHouse=repts(NewHouseX,2)+repts(NewHouseY,2);
NewHouseStr=NewHouse+"-";
if(LineA.indexOf(NewHouseStr)===-1){//不包括就可以走
LineA=LineA+NewHouseStr;
HouseX=NewHouseX;
HouseY=NewHouseY;
FloorNow=FloorNow+1;
if(FloorNow>FloorMax){
break;
};
};
};
};
$gameVariables.setValue(1000+j,LineA.substring(5*Yuan_Wid*2+5*Yuan_Hei*2));
};
$gameVariables.setValue(1003,"AA-"+$gameVariables.value(1001)+"BB-"+$gameVariables.value(1002));
//alert($gameVariables.value(1003));
};
if (command === "随机迷宫读取"){
Laoyao_drawMap();
};
return true;
};
var Check_dingtile =function(x,y){
a1=$gameMap.layeredTiles(x, y-1);
a2=$gameMap.layeredTiles(x, y+1);
a3=$gameMap.layeredTiles(x-1, y);
a4=$gameMap.layeredTiles(x+1, y);
tile_now_all=[a1[2],a2[2],a3[2],a4[2]];
checkstr="";
for(mm=0;mm<4;mm++){
if(tile_dings.indexOf(tile_now_all[mm])==-1){
checkstr=checkstr+"0";
}else{
checkstr=checkstr+"1";
};
};
checkstr2=["1000","0010","0000","0001","0100","1001","1010","0110","0101","0011","1100","1011","1110","0111","1101","1111"];
if(checkstr2.indexOf(checkstr)!=-1){
return tile_dings[checkstr2.indexOf(checkstr)];
}else{
return 0;
};
};
var Laoyao_drawMap = function(){
alert($gameVariables.value(1003));
if(String($gameVariables.value(1003)).substr(0,2)!="AA"){
return;
};
LineS=$gameVariables.value(1003);
Fenge=LineS.indexOf("BB-");
LineG=[LineS.substr(3,Fenge-3),LineS.substring(Fenge+3)];
//先清空所有地图块
tile_wall=$gameMap.layeredTiles(1, 0);
tile_road=$gameMap.layeredTiles(0, 0);
tile_ding=$gameMap.layeredTiles(2, 0);
tile_kong=$gameMap.layeredTiles(3, 0); //最下层的底色
tile_lake=$gameMap.layeredTiles(4,0);//湖
tile_cx=$gameMap.layeredTiles(5,0); //可穿行之物
tile_bcx=$gameMap.layeredTiles(6,0); //不能穿行之物
tile_lakes=[tile_lake[3]+2,tile_lake[3]-1,tile_lake[3]+1,tile_lake[3]-11];
tile_walls=[tile_wall[3]-1,tile_wall[3]-2,tile_wall[3]-4,tile_wall[3]-5];
ls=tile_ding[3];
tile_dings=[ls,ls+1,ls+2,ls-1,ls-2,ls-4,ls-6,ls-8,ls-10,ls-11,ls-12,ls-16,ls-20,ls-24,ls-28,ls-44];
//alert(tile_lakes);
for(kk=YuanX;kk<=Yuan_Wid+YuanX;kk++){
for(ll=YuanY-2;ll<=Yuan_Hei+YuanY-1;ll++){
for(mm=0;mm<=4;mm++){
posi_tt1=(mm*mapy +Number(ll))*mapx+Number(kk);
$dataMap.data[posi_tt1] =0;
};
mm=0;
posi_tt1=(mm*mapy +Number(ll))*mapx+Number(kk);
$dataMap.data[posi_tt1] =tile_kong[3];
mm=1;
posi_tt1=(mm*mapy +Number(ll))*mapx+Number(kk);
$dataMap.data[posi_tt1] =tile_ding[3];
};
};
//读取设置的默认图块
mapnow=SceneManager._scene._spriteset._tilemap;
alert(mapnow);
//计算每个地图的中间通道的位置XY
//roadx=LineG[0].split("-");
//roady=LineG[1].split("-");
//alert(roadx);
//alert(roady);
//根据走势图判断迷宫的哪些开关打开
for(j=0;j<=0;j++){
for(k=1;k<=LineG[j].length/5;k++){
lsstr1=LineG[j].substr(k*5-5,4);
lsstra=lsstr1.substr(0,2)*1;
lsstrb=lsstr1.substr(2,2)*1;
posi_tt1=(1*mapy +Number(lsstrb))*mapx+Number(lsstra);
$dataMap.data[posi_tt1] =tile_road[3];
};
};
for(j=0;j<=0;j++){
for(k=1;k<=LineG[j].length/5;k++){
lsstr1=LineG[j].substr(k*5-5,4);
lsstra=lsstr1.substr(0,2)*1;
lsstrb=lsstr1.substr(2,2)*1;
up_tile1=$gameMap.layeredTiles(lsstra, lsstrb-1);
up_tile2=$gameMap.layeredTiles(lsstra, lsstrb-2);
if(up_tile1[2]===tile_ding[3] && up_tile2[2]===tile_ding[3]){
posi_tt2=(1*mapy +Number(lsstrb-1))*mapx+Number(lsstra);
$dataMap.data[posi_tt2] =tile_wall[3]-5;
}else if(up_tile1[2]===tile_ding[3] && up_tile2[2]===tile_road[3]){
posi_tt2=(1*mapy +Number(lsstrb-1))*mapx+Number(lsstra);
$dataMap.data[posi_tt2] =tile_lake[3]+2;
};
};
};
//美化墙壁
for(j=YuanX;j<YuanX+Yuan_Wid;j++){
for(k=YuanY;k<YuanY+Yuan_Hei;k++){
$gameVariables.setValue(1004,1);
tile_now_m=$gameMap.layeredTiles(j, k);
tile_now_l=$gameMap.layeredTiles(j-1, k);
tile_now_r=$gameMap.layeredTiles(j+1, k);
$gameVariables.setValue(1004,tile_wall);
posi_tt2=(1*mapy +Number(k))*mapx+Number(j);
if(tile_now_m[2]==tile_wall[3]-5){
if(tile_walls.indexOf(tile_now_l[2])==-1 && tile_walls.indexOf(tile_now_r[2])==-1){
$dataMap.data[posi_tt2] =tile_wall[3]-2;
}else if(tile_walls.indexOf(tile_now_l[2])!=-1 && tile_walls.indexOf(tile_now_r[2])!=-1){
$dataMap.data[posi_tt2] =tile_wall[3]-5;
}else{
if(tile_walls.indexOf(tile_now_l[2])==-1){
$dataMap.data[posi_tt2] =tile_wall[3]-4;
}else if(tile_walls.indexOf(tile_now_r[2])==-1){
$dataMap.data[posi_tt2] =tile_wall[3]-1;
};
};
};
//美化湖
if(tile_now_m[2]==tile_lake[3]+2){
if(tile_lakes.indexOf(tile_now_l[2])!=-1 && tile_lakes.indexOf(tile_now_r[2])!=-1){
$dataMap.data[posi_tt2] =tile_lake[3]-11;
}else{
if(tile_lakes.indexOf(tile_now_l[2])==-1 && tile_lakes.indexOf(tile_now_r[2])!=-1){
$dataMap.data[posi_tt2] =tile_lake[3]-1;
}else if(tile_lakes.indexOf(tile_now_r[2])==-1 && tile_lakes.indexOf(tile_now_l[2])!=-1){
$dataMap.data[posi_tt2] =tile_lake[3]+1;
};
};
};
};
};
//画可穿行物
cxno=1;
cxmax=20;
for(j=cxno;j<=cxmax;j++){
lsstra=prnd(1,LineG[0].length/5);
lsstrb=LineG[0].substr(lsstra*5-5,4);
lsstrc=lsstrb.substr(0,2);
lsstrd=lsstrb.substr(2,2);
posi_tt1=(2*mapy +Number(lsstrd))*mapx+Number(lsstrc);
$dataMap.data[posi_tt1] =tile_cx[0];
};
//画不可穿行物
cxno=1;
cxmax=10;
for(j=cxno;j<=cxmax;j++){
lsstra=prnd(1,LineG[0].length/5);
lsstrb=LineG[0].substr(lsstra*5-5,4);
lsstrc=lsstrb.substr(0,2);
lsstrd=lsstrb.substr(2,2);
posi_tt1=(2*mapy +Number(lsstrd))*mapx+Number(lsstrc);
$dataMap.data[posi_tt1] =tile_bcx[0];
};
nn=1;
for(k=YuanY-2;k<=YuanY+Yuan_Hei;k++){
for(j=0;j<YuanX;j++){
posi_tt1=(nn*mapy +Number(k))*mapx+Number(j);
$dataMap.data[posi_tt1] =tile_ding[3];
};
for(j=YuanX+Yuan_Wid;j<mapx;j++){
posi_tt1=(nn*mapy +Number(k))*mapx+Number(j);
$dataMap.data[posi_tt1] =tile_ding[3];
};
};
for(k=0;k<=mapx-1;k++){
for(j=0;j<YuanY-2;j++){
posi_tt1=(nn*mapy +Number(j))*mapx+Number(k);
$dataMap.data[posi_tt1] =tile_ding[3];
};
for(j=YuanY+Yuan_Hei;j<mapy-1;j++){
posi_tt1=(nn*mapy +Number(j))*mapx+Number(k);
$dataMap.data[posi_tt1] =tile_ding[3];
};
posi_tt1=(nn*mapy +Number(mapy-1))*mapx+Number(k);
$dataMap.data[posi_tt1] =tile_wall[3];
};
//再美化顶
for(j=1;j<mapx-1;j++){
for(k=1;k<=mapy-2;k++){
tile_now_m=$gameMap.layeredTiles(j, k);
if(tile_dings.indexOf(tile_now_m[2])!=-1){
aaaa=1;
//posi_tt1=(1*mapy +Number(j))*mapx+Number(k);
//$dataMap.data[posi_tt1] =Check_dingtile(j,k);
};
};
};
//alert(aaaa);
alert($dataMap.data);
mapnow.refresh();
};
var prnd = function(aa, bb){
var a=Math.random();
a=a*(bb-aa+1);
a=Math.trunc(a)+aa;
return a;
};
var repeat = function(aa,bb){
cc=""
for(i=1;i<=bb;i++){
cc=cc+aa;
};
return cc;
};
var repts = function(aa,bb){
a=String(aa).length;
aa=aa.toString();
b="";
for(i=1;i<=bb-a;i++){
b=String(b)+"0";
};
return b+aa;
};
Laoyao_RandomMap.first.init = Game_Map.prototype.initialize;
Game_Map.prototype.initialize = function() {
Laoyao_RandomMap.first.init.call(this);
Laoyao_drawMap();
};
Laoyao_RandomMap_data = Game_Map.prototype.data
Game_Map.prototype.data = function() {
Laoyao_RandomMap_data.call(this);
alert(1);
Laoyao_drawMap();
//DataManager.onLoad(window.$dataMap);
}
|
最佳答案
查看完整内容
MV中菜单取消触发→ Scene_Base.prototype.popScene 调用→ SceneManager.pop() 返回上一级场景 触发 → SceneManager.goto 联动 → SceneManager.updateMain 下的 → SceneManager.changeScene 重新触发 该转换场景的 create 。
而 Scene_Map 下的 create 调用了 → DataManager.loadMapData(mapId) 读入相应文件,更新(覆盖)了 $dataMap。到此,$dataMap.data 便还原了。
数据还原后,MV在画图前会检查一遍数据是否已准备就 ...
|