diff --git a/libs/actions.js b/libs/actions.js index 06740662..87bedddf 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -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); diff --git a/libs/control.js b/libs/control.js index e30dfe85..c3430543 100644 --- a/libs/control.js +++ b/libs/control.js @@ -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; } } } diff --git a/libs/core.js b/libs/core.js index c2cd4342..c35abc7f 100644 --- a/libs/core.js +++ b/libs/core.js @@ -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魔塔"; diff --git a/libs/maps.js b/libs/maps.js index 70179b5a..55edebc3 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -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=(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); diff --git a/libs/ui.js b/libs/ui.js index a89adab7..13e77724 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -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; diff --git a/project/items.js b/project/items.js index 23ba3cfd..793296cb 100644 --- a/project/items.js +++ b/project/items.js @@ -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=0 && toX=0 && toY0) {\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=0 && toY=0 && toX=0 && toY0) {\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=0 && toY0) {\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');",