Set floor width/height on start

This commit is contained in:
oc 2019-03-10 15:29:14 +08:00
parent 622f5eb8be
commit c1b0aedd16
6 changed files with 52 additions and 35 deletions

View File

@ -1028,7 +1028,7 @@ actions.prototype._clickViewMaps = function (x,y) {
var now = core.floorIds.indexOf(core.status.floorId);
var index = core.status.event.data.index;
var cx = core.status.event.data.x, cy = core.status.event.data.y;
var floorId = core.floorIds[index], mw = core.floors[floorId].width||13, mh = core.floors[floorId].height||13;
var floorId = core.floorIds[index], mw = core.floors[floorId].width, mh = core.floors[floorId].height;
if (x==0 && y==0) {
core.status.event.data.damage = !core.status.event.data.damage;
@ -1087,7 +1087,7 @@ actions.prototype._clickViewMaps = function (x,y) {
actions.prototype._keyDownViewMaps = function (keycode) {
if (!core.isset(core.status.event.data)) return;
var floorId = core.floorIds[core.status.event.data.index], mh = core.floors[floorId].height||13;
var floorId = core.floorIds[core.status.event.data.index], mh = core.floors[floorId].height;
if (keycode==38||keycode==33) this._clickViewMaps(6, 3);
if (keycode==40||keycode==34) this._clickViewMaps(6, 9);

View File

@ -1503,8 +1503,8 @@ control.prototype.updateDamage = function (floorId, canvas) {
if (floorId != core.status.floorId) {
tempCheckBlock = core.clone(core.status.checkBlock);
core.status.thisMap = core.status.maps[floorId];
core.bigmap.width = core.floors[floorId].width || 13;
core.bigmap.height = core.floors[floorId].height || 13;
core.bigmap.width = core.floors[floorId].width;
core.bigmap.height = core.floors[floorId].height;
core.updateCheckBlock();
}
@ -1526,8 +1526,8 @@ control.prototype.updateDamage = function (floorId, canvas) {
if (floorId!=core.status.floorId) {
core.status.thisMap = core.status.maps[core.status.floorId];
core.status.checkBlock = tempCheckBlock;
core.bigmap.width = core.floors[core.status.floorId].width || 13;
core.bigmap.height = core.floors[core.status.floorId].height || 13;
core.bigmap.width = core.floors[core.status.floorId].width;
core.bigmap.height = core.floors[core.status.floorId].height;
}
}
}

View File

@ -232,6 +232,8 @@ core.prototype.init = function (coreData, callback) {
})
}
core.maps._setFloorSize();
core.dom.versionLabel.innerHTML = core.firstData.version;
core.dom.logoLabel.innerHTML = core.firstData.title;
document.title = core.firstData.title + " - HTML5魔塔";

View File

@ -2,6 +2,10 @@
function maps() {
this._init();
this.DEFAULT_WIDTH = 13;
this.DEFAULT_HEIGHT = 13;
this.DEFAULT_PIXEL_WIDTH = this.DEFAULT_WIDTH * 32;
this.DEFAULT_PIXEL_HEIGHT = this.DEFAULT_HEIGHT * 32;
}
maps.prototype._init = function() {
@ -9,6 +13,17 @@ maps.prototype._init = function() {
//delete(maps_90f36752_8815_4be8_b32b_d7fad1d0542e);
}
maps.prototype._setFloorSize = function (floorId) {
if (!core.isset(floorId)) {
core.floorIds.forEach(function (floorId) {
core.maps._setFloorSize(floorId);
});
return;
}
core.floors[floorId].width = core.floors[floorId].width || this.DEFAULT_WIDTH;
core.floors[floorId].height = core.floors[floorId].height || this.DEFAULT_HEIGHT;
}
////// 加载某个楼层(从剧本或存档中) //////
maps.prototype.loadFloor = function (floorId, map) {
var floor = core.floors[floorId];
@ -26,8 +41,8 @@ maps.prototype.loadFloor = function (floorId, map) {
map=this.decompressMap(map.map, floorId);
var mapIntoBlocks = function(map,maps,floor,floorId){
var blocks = [];
var mw = core.floors[floorId].width || 13;
var mh = core.floors[floorId].height || 13;
var mw = core.floors[floorId].width;
var mh = core.floors[floorId].height;
for (var i = 0; i < mh; i++) {
for (var j = 0; j < mw; j++) {
var block = maps.initBlock(j, i, (map[i]||[])[j]||0);
@ -189,8 +204,8 @@ maps.prototype.initMaps = function (floorIds) {
maps.prototype.__initFloorMap = function (floorId) {
var map = core.clone(core.floors[floorId].map);
var mw = core.floors[floorId].width || 13;
var mh = core.floors[floorId].height || 13;
var mw = core.floors[floorId].width;
var mh = core.floors[floorId].height;
for (var x=0;x<mh;x++) {
if (!core.isset(map[x])) map[x] = [];
@ -212,8 +227,8 @@ maps.prototype.compressMap = function (mapArr, floorId) {
var floorMap = this.__initFloorMap(floorId);
if (core.utils.same(mapArr, floorMap)) return null;
var mw = core.floors[floorId].width || 13;
var mh = core.floors[floorId].height || 13;
var mw = core.floors[floorId].width;
var mh = core.floors[floorId].height;
for (var x=0;x<mh;x++) {
if (core.utils.same(mapArr[x], floorMap[x])) {
// 没有改变的行直接删掉记成0
@ -236,8 +251,8 @@ maps.prototype.decompressMap = function (mapArr, floorId) {
var floorMap = this.__initFloorMap(floorId);
if (!core.isset(mapArr)) return floorMap;
var mw = core.floors[floorId].width || 13;
var mh = core.floors[floorId].height || 13;
var mw = core.floors[floorId].width;
var mh = core.floors[floorId].height;
for (var x=0;x<mh;x++) {
if (mapArr[x] === 0) {
mapArr[x] = floorMap[x];
@ -262,8 +277,8 @@ maps.prototype.saveMap = function(maps, floorId) {
}
return map;
}
var mw = core.floors[floorId].width || 13;
var mh = core.floors[floorId].height || 13;
var mw = core.floors[floorId].width;
var mh = core.floors[floorId].height;
var blocks = [];
for (var x=0;x<mh;x++) {
@ -299,8 +314,8 @@ maps.prototype.saveMap = function(maps, floorId) {
maps.prototype.resizeMap = function(floorId) {
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
core.bigmap.width = core.floors[floorId].width || 13;
core.bigmap.height = core.floors[floorId].height || 13;
core.bigmap.width = core.floors[floorId].width;
core.bigmap.height = core.floors[floorId].height;
var cwidth = core.bigmap.width * 32;
var cheight = core.bigmap.height * 32;
core.bigmap.canvas.forEach(function(cn){
@ -330,8 +345,8 @@ maps.prototype.loadMap = function (data, floorId) {
////// 将当前地图重新变成二维数组形式 //////
maps.prototype.getMapArray = function (blockArray,width,height){
width=width||13;
height=height||13;
width=width||this.DEFAULT_WIDTH;
height=height||this.DEFAULT_HEIGHT;
var blocks = [];
for (var x=0;x<height;x++) {
@ -488,8 +503,8 @@ maps.prototype.drawBlock = function (block, animate, dx, dy) {
maps.prototype.getBgFgMapArray = function (floorId, name) {
floorId = floorId||core.status.floorId;
if (!core.isset(floorId)) return [];
var width = core.floors[floorId].width || 13;
var height = core.floors[floorId].height || 13;
var width = core.floors[floorId].width;
var height = core.floors[floorId].height;
if (main.mode!='editor' && core.isset(core.status[name+"maps"][floorId]))
return core.status[name+"maps"][floorId];
@ -512,8 +527,8 @@ maps.prototype.getBgFgMapArray = function (floorId, name) {
maps.prototype.drawBgFgMap = function (floorId, canvas, name, animate) {
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
var width = core.floors[floorId].width || 13;
var height = core.floors[floorId].height || 13;
var width = core.floors[floorId].width;
var height = core.floors[floorId].height;
if (!core.isset(core.status[name+"maps"]))
core.status[name+"maps"] = {};
@ -638,8 +653,8 @@ maps.prototype.drawMap = function (floorId, callback) {
this.generateGroundPattern(floorId);
var drawBg = function(){
var width = core.floors[floorId].width || 13;
var height = core.floors[floorId].height || 13;
var width = core.floors[floorId].width;
var height = core.floors[floorId].height;
for (var x = 0; x < width; x++) {
for (var y = 0; y < height; y++) {
@ -1399,7 +1414,7 @@ maps.prototype.setBlock = function (number, x, y, floorId) {
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
if (!core.isset(number) || !core.isset(x) || !core.isset(y)) return;
if (x<0 || x>=(core.floors[floorId].width||13) || y<0 || y>=(core.floors[floorId].height||13)) return;
if (x<0 || x>=core.floors[floorId].width || y<0 || y>=core.floors[floorId].height) return;
var originBlock=core.getBlock(x,y,floorId,true);
var block = core.maps.initBlock(x,y,number);
@ -1437,7 +1452,7 @@ maps.prototype.setBgFgBlock = function (name, number, x, y, floorId) {
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
if (!core.isset(number) || !core.isset(x) || !core.isset(y)) return;
if (x<0 || x>=(core.floors[floorId].width||13) || y<0 || y>=(core.floors[floorId].height||13)) return;
if (x<0 || x>=core.floors[floorId].width || y<0 || y>=core.floors[floorId].height) return;
if (name!='bg' && name!='fg') return;
core.setFlag(name+"v_"+floorId+"_"+x+"_"+y, number);

View File

@ -1669,7 +1669,7 @@ ui.prototype.drawMaps = function (index, x, y) {
if (index<0) index=0;
if (index>=core.floorIds.length) index=core.floorIds.length-1;
var floorId = core.floorIds[index], mw = core.floors[floorId].width||13, mh = core.floors[floorId].height||13;
var floorId = core.floorIds[index], mw = core.floors[floorId].width, mh = core.floors[floorId].height;
if (!core.isset(x)) x = parseInt(mw/2);
if (!core.isset(y)) y = parseInt(mh/2);
if (x<6) x=6;
@ -2161,8 +2161,8 @@ ui.prototype.drawSLPanel = function(index, refresh) {
////// 绘制一个缩略图 //////
ui.prototype.drawThumbnail = function(floorId, canvas, blocks, x, y, size, centerX, centerY, heroLoc, heroIcon) {
var mw = core.floors[floorId].width || 13;
var mh = core.floors[floorId].height || 13;
var mw = core.floors[floorId].width;
var mh = core.floors[floorId].height;
// 绘制到tempCanvas上面
var tempCanvas = core.bigmap.tempCanvas;
var tempWidth = mw*32, tempHeight = mh*32;

View File

@ -368,7 +368,7 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a =
"bigKey": "core.removeBlockByIds(core.status.floorId, core.status.event.ui);\ncore.drawMap(core.status.floorId, function () {\n\tcore.drawTip(core.material.items[itemId].name + '使用成功');\n});",
"bomb": "core.playSound('bomb.mp3');\ncore.removeBlockByIds(core.status.floorId, core.status.event.ui);\ncore.drawMap(core.status.floorId, function () {\n\tcore.drawTip(core.material.items[itemId].name + '使用成功');\n\tcore.events.afterUseBomb();\n});",
"hammer": "core.playSound('bomb.mp3');\ncore.removeBlockByIds(core.status.floorId, core.status.event.ui);\ncore.drawMap(core.status.floorId, function () {\n\tcore.drawTip(core.material.items[itemId].name + '使用成功');\n\tcore.events.afterUseBomb();\n});",
"centerFly": "core.playSound('centerFly.mp3');\ncore.clearMap('hero');\ncore.setHeroLoc('x', (core.bigmap.width||13)-1-core.getHeroLoc('x'));\ncore.setHeroLoc('y', (core.bigmap.height||13)-1-core.getHeroLoc('y'));\ncore.drawHero();\ncore.drawTip(core.material.items[itemId].name + '使用成功');",
"centerFly": "core.playSound('centerFly.mp3');\ncore.clearMap('hero');\ncore.setHeroLoc('x', core.bigmap.width-1-core.getHeroLoc('x'));\ncore.setHeroLoc('y', core.bigmap.height-1-core.getHeroLoc('y'));\ncore.drawHero();\ncore.drawTip(core.material.items[itemId].name + '使用成功');",
"upFly": "var loc = {'direction': core.status.hero.loc.direction, 'x': core.status.event.ui.x, 'y': core.status.event.ui.y};\nif (core.status.event.id == 'action') {\n\tcore.insertAction([\n\t\t{\"type\": \"changeFloor\", \"loc\": [loc.x, loc.y], \"direction\": loc.direction, \"floorId\": core.status.event.ui.id},\n\t\t{\"type\": \"tip\", \"text\": core.material.items[itemId].name + '使用成功'}\n\t]);\n}\nelse {\n\tcore.changeFloor(core.status.event.ui.id, null, loc, null, function (){\n\tcore.drawTip(core.material.items[itemId].name + '使用成功');\n\t\tcore.replay();\n\t});\n}",
"downFly": "var loc = {'direction': core.status.hero.loc.direction, 'x': core.status.event.ui.x, 'y': core.status.event.ui.y};\nif (core.status.event.id == 'action') {\n\tcore.insertAction([\n\t\t{\"type\": \"changeFloor\", \"loc\": [loc.x, loc.y], \"direction\": loc.direction, \"floorId\": core.status.event.ui.id},\n\t\t{\"type\": \"tip\", \"text\": core.material.items[itemId].name + '使用成功'}\n\t]);\n}\nelse {\n\tcore.changeFloor(core.status.event.ui.id, null, loc, null, function (){\n\tcore.drawTip(core.material.items[itemId].name + '使用成功');\n\t\tcore.replay();\n\t});\n}\n",
"poisonWine": "core.removeFlag('poison');",
@ -395,9 +395,9 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a =
"bomb": "(function () {\n\tvar ids = [], id2s = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (core.isset(block.event) && !block.disable && block.event.cls.indexOf('enemy')==0 && core.nearHero(block.x, block.y)) {\n\t\t\tvar enemy = core.material.enemys[block.event.id];\n\t\t\tif (core.isset(enemy) && enemy.notBomb) continue;\n\t\t\tif (core.flags.bombFourDirections || (block.x==core.nextX() && block.y==core.nextY()))\n\t\t\t\tids.push(i);\n\t\t\telse\n\t\t\t\tid2s.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\treturn true;\n\t}\n\tif (id2s.length==1) {\n\t\tcore.status.event.ui = id2s;\n\t\treturn true;\n\t}\n\treturn false;\n})();",
"hammer": "(function() {\n\tvar ids = [], id2s = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (core.isset(block.event) && !block.disable && block.event.cls.indexOf('enemy')==0 && core.nearHero(block.x, block.y)) {\n\t\t\tvar enemy = core.material.enemys[block.event.id];\n\t\t\tif (core.isset(enemy) && enemy.notBomb) continue;\n\t\t\tif (block.x==core.nextX() && block.y==core.nextY())\n\t\t\t\tids.push(i);\n\t\t\telse\n\t\t\t\tid2s.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\treturn true;\n\t}\n\telse if (id2s.length==1) {\n\t\tcore.status.event.ui = id2s;\n\t\treturn true;\n\t}\n\treturn false;\n})();",
"earthquake": "(function () {\n\tvar able=false;\n\tvar ids = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (core.isset(block.event) && !block.disable &&\n\t\t\t(block.event.canBreak || block.event.id == 'yellowWall' || block.event.id == 'blueWall' || block.event.id == 'whiteWall')) { // 能炸的墙壁\n\t\t\tids.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\table=true;\n\t}\n\treturn able;\n})();",
"centerFly": "(function () {\n\tvar toX = (core.bigmap.width||13)-1-core.getHeroLoc('x'), toY = (core.bigmap.height||13)-1-core.getHeroLoc('y');\n\tvar id = core.getBlockId(toX, toY);\n\treturn id == null;\n})();",
"upFly": "(function() {\n\tvar floorId = core.status.floorId, index = core.floorIds.indexOf(floorId);\n\tif (index<core.floorIds.length-1) {\n\t\tvar toId = core.floorIds[index+1], toX = core.getHeroLoc('x'), toY = core.getHeroLoc('y');\n\t\tvar mw = core.floors[toId].width||13, mh = core.floors[toId].height||13;\n\t\tif (toX>=0 && toX<mw && toY>=0 && toY<mh && core.getBlock(toX, toY, toId)==null) {\n\t\t\tcore.status.event.ui = {'id': toId, 'x': toX, 'y': toY};\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n})();",
"downFly": "(function() {\n\tvar floorId = core.status.floorId, index = core.floorIds.indexOf(floorId);\n\tif (index>0) {\n\t\tvar toId = core.floorIds[index-1], toX = core.getHeroLoc('x'), toY = core.getHeroLoc('y');\n\t\tvar mw = core.floors[toId].width||13, mh = core.floors[toId].height||13;\n\t\tif (toX>=0 && toX<mw && toY>=0 && toY<mh && core.getBlock(toX, toY, toId)==null) {\n\t\t\tcore.status.event.ui = {'id': toId, 'x': toX, 'y': toY};\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n})();",
"centerFly": "(function () {\n\tvar toX = core.bigmap.width-1-core.getHeroLoc('x'), toY = core.bigmap.height-1-core.getHeroLoc('y');\n\tvar id = core.getBlockId(toX, toY);\n\treturn id == null;\n})();",
"upFly": "(function() {\n\tvar floorId = core.status.floorId, index = core.floorIds.indexOf(floorId);\n\tif (index<core.floorIds.length-1) {\n\t\tvar toId = core.floorIds[index+1], toX = core.getHeroLoc('x'), toY = core.getHeroLoc('y');\n\t\tvar mw = core.floors[toId].width, mh = core.floors[toId].height;\n\t\tif (toX>=0 && toX<mw && toY>=0 && toY<mh && core.getBlock(toX, toY, toId)==null) {\n\t\t\tcore.status.event.ui = {'id': toId, 'x': toX, 'y': toY};\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n})();",
"downFly": "(function() {\n\tvar floorId = core.status.floorId, index = core.floorIds.indexOf(floorId);\n\tif (index>0) {\n\t\tvar toId = core.floorIds[index-1], toX = core.getHeroLoc('x'), toY = core.getHeroLoc('y');\n\t\tvar mw = core.floors[toId].width, mh = core.floors[toId].height;\n\t\tif (toX>=0 && toX<mw && toY>=0 && toY<mh && core.getBlock(toX, toY, toId)==null) {\n\t\t\tcore.status.event.ui = {'id': toId, 'x': toX, 'y': toY};\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n})();",
"snow": "(function () {\n\tvar ids = [], id2s = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (core.isset(block.event) && !block.disable && block.event.id == 'lava' && core.nearHero(block.x, block.y)) {\n\t\t\tif (core.flags.snowFourDirections || (block.x == core.nextX() && block.y == core.nextY()))\n\t\t\t\tids.push(i);\n\t\t\telse id2s.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\treturn true;\n\t}\n\tif (id2s.length==1) {\n\t\tcore.status.event.ui = id2s;\n\t\treturn true;\n\t}\n\treturn false;\n})();",
"bigKey": "(function() {\n\tvar able=false, ids = [];\n\tfor (var i in core.status.thisMap.blocks) {\n\t\tvar block = core.status.thisMap.blocks[i];\n\t\tif (core.isset(block.event) && !block.disable && block.event.id == 'yellowDoor') {\n\t\t\tids.push(i);\n\t\t}\n\t}\n\tif (ids.length>0) {\n\t\tcore.status.event.ui = ids;\n\t\table=true;\n\t}\n\treturn able;\n})();",
"poisonWine": "core.hasFlag('poison');",