diff --git a/_server/functions.comment.js b/_server/functions.comment.js index 9b8c79dd..fc21ae17 100644 --- a/_server/functions.comment.js +++ b/_server/functions.comment.js @@ -31,11 +31,17 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_lint": true, "_data": "游戏失败事件" }, + "changingFloor": { + "_leaf": true, + "_type": "textarea", + "_lint": true, + "_data": "正在切换楼层过程中的操作\n此函数的执行时间是在切换楼层过程中屏幕完全变黑的一刻" + }, "afterChangeFloor": { "_leaf": true, "_type": "textarea", "_lint": true, - "_data": "转换楼层结束的事件" + "_data": "转换楼层结束的事件\n此函数会在整个楼层切换完全结束后执行" }, "addPoint": { "_leaf": true, diff --git a/docs/api.md b/docs/api.md index 15477fdd..e908bcbd 100644 --- a/docs/api.md +++ b/docs/api.md @@ -474,7 +474,7 @@ core.ui.getContextByName(name) core.clearMap(name) 清空某个画布图层。 name为画布名,可以是系统画布之一,也可以是任意自定义动态创建的画布名。 -如果name也可以是'all',若为all则为清空除色调层外的所有系统画布。 +如果name也可以是'all',若为all则为清空所有系统画布。 core.ui.fillText(name, text, x, y, style, font) diff --git a/docs/event.md b/docs/event.md index a17fcc93..438ee9e7 100644 --- a/docs/event.md +++ b/docs/event.md @@ -2198,8 +2198,7 @@ if (core.getFlag("door",0)==2) { var replaying = core.status.replay.replaying; core.stopReplay(); core.waitHeroToStop(function() { - core.removeGlobalAnimate(0,0,true); - core.clearMap('all'); core.clearMap('curtain'); // 清空全地图 + core.clearMap('all'); // 清空全地图 core.deleteAllCanvas(); core.drawText([ "\t[恭喜通关]你的分数是${status:hp}。" diff --git a/docs/personalization.md b/docs/personalization.md index 59afe874..ac67729c 100644 --- a/docs/personalization.md +++ b/docs/personalization.md @@ -8,7 +8,7 @@ HTML5魔塔是使用画布(canvas)来绘制,存在若干个图层,它们之间有一个覆盖关系,后面的图层将覆盖前面的图层。 -所有图层从低往高依次如下:(加[B]的代表该层是大地图,z-index代表该层的纵向高度) +所有图层从低往高依次如下:(加[B]的代表该层是大地图,[D]代表由系统按需动态创建,z-index代表该层的纵向高度) - bg**[B]**:背景层;绘制背景图层素材bgmap,和背景贴图 (z-index: 10) - event**[B]**:事件层;所有事件(道具、墙壁、NPC、怪物等)都绘制在这一层进行处理 (z-index: 30) @@ -17,8 +17,9 @@ HTML5魔塔是使用画布(canvas)来绘制,存在若干个图层,它们 - fg**[B]**:前景层;绘制前景图层素材fgmap,和前景贴图 (z-index: 60) - damage**[B]**:显伤层;主要用来绘制怪物显伤和领域显伤 (z-index: 65) - animate:动画层;主要用来绘制动画。 (z-index: 70) -- weather:天气层;主要用来绘制天气(雨/雪/雾) (z-index: 80) -- route**[B]**:路线层;主要用来绘制勇士的行走路线图。 (z-index: 95) +- weather**[D]**:天气层;主要用来绘制天气(雨/雪/雾) (z-index: 80) +- route**[D]**:路线层;主要用来绘制勇士的行走路线图。 (z-index: 95) +- paint**[D]**:绘图层;主要用来进行绘图模式。(z-index: 95) - curtain:色调层;用来控制当前楼层的画面色调 (z-index: 100) - ui:UI层;用来绘制一切UI窗口,如剧情文本、怪物手册、楼传器、系统菜单等等 (z-index: 160) - data:数据层;用来绘制一些顶层的或更新比较快的数据,如左上角的提示,战斗界面中数据的变化等等。 (z-index: 170) diff --git a/editor-mobile.html b/editor-mobile.html index 1026c9dc..36dfd637 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -440,8 +440,6 @@ - - 此浏览器不支持HTML5 diff --git a/editor.html b/editor.html index 7f865e9b..bd022f4f 100644 --- a/editor.html +++ b/editor.html @@ -425,8 +425,6 @@ - - 此浏览器不支持HTML5 diff --git a/index.html b/index.html index 028c5a6a..fcf9b278 100644 --- a/index.html +++ b/index.html @@ -140,8 +140,6 @@ - - 此浏览器不支持HTML5 diff --git a/libs/actions.js b/libs/actions.js index f41f52dc..ab8abb3a 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -341,7 +341,7 @@ actions.prototype.ondown = function (loc) { } core.status.downTime = new Date(); - core.clearMap('route'); + core.deleteCanvas('route'); var pos={'x':x,'y':y} core.status.stepPostfix=[]; core.status.stepPostfix.push(pos); @@ -409,8 +409,7 @@ actions.prototype.onup = function () { var posy=core.status.stepPostfix[0].y; core.status.stepPostfix=[]; if (!core.status.lockControl) { - core.clearMap('route'); - core.canvas.route.restore(); + core.clearMap('ui'); } // 长按 @@ -2612,8 +2611,8 @@ actions.prototype.ondownPaint = function (x, y) { x+=core.bigmap.offsetX; y+=core.bigmap.offsetY; if (!core.status.event.data.erase) { - core.canvas.route.beginPath(); - core.canvas.route.moveTo(x, y); + core.dymCanvas.paint.beginPath(); + core.dymCanvas.paint.moveTo(x, y); } core.status.event.data.x = x; core.status.event.data.y = y; @@ -2624,12 +2623,12 @@ actions.prototype.onmovePaint = function (x, y) { x+=core.bigmap.offsetX; y+=core.bigmap.offsetY; if (core.status.event.data.erase) { - core.clearMap('route', x-10, y-10, 20, 20); + core.clearMap('paint', x-10, y-10, 20, 20); return; } var midx = (core.status.event.data.x+x)/2, midy = (core.status.event.data.y+y)/2; - core.canvas.route.quadraticCurveTo(midx, midy, x, y); - core.canvas.route.stroke(); + core.dymCanvas.paint.quadraticCurveTo(midx, midy, x, y); + core.dymCanvas.paint.stroke(); core.status.event.data.x = x; core.status.event.data.y = y; } @@ -2638,7 +2637,7 @@ actions.prototype.onupPaint = function () { core.status.event.data.x = null; core.status.event.data.y = null; // 保存 - core.paint[core.status.floorId] = LZString.compress(core.utils.encodeCanvas(core.canvas.route).join(",")); + core.paint[core.status.floorId] = LZString.compress(core.utils.encodeCanvas(core.dymCanvas.paint).join(",")); } actions.prototype.setPaintMode = function (mode) { @@ -2650,8 +2649,8 @@ actions.prototype.setPaintMode = function (mode) { } actions.prototype.clearPaint = function () { - core.clearMap('route'); - core.paint[core.status.floorId] = null; + core.clearMap('paint'); + delete core.paint[core.status.floorId]; core.drawTip("已清空绘图内容"); } @@ -2683,18 +2682,18 @@ actions.prototype.loadPaint = function () { core.paint[floorId] = LZString.compress(obj.paint[floorId]); } - core.clearMap('route'); + core.clearMap('paint'); var value = core.paint[core.status.floorId]; if (core.isset(value)) value = LZString.decompress(value).split(","); core.utils.decodeCanvas(value, 32*core.bigmap.width, 32*core.bigmap.height); - core.canvas.route.drawImage(core.bigmap.tempCanvas.canvas, 0, 0); + core.canvas.paint.drawImage(core.bigmap.tempCanvas.canvas, 0, 0); core.drawTip("读取绘图文件成功"); }) } actions.prototype.exitPaint = function () { - core.clearMap('route'); + core.deleteCanvas('paint'); core.ui.closePanel(); core.statusBar.image.shop.style.opacity = 1; core.updateStatusBar(); diff --git a/libs/control.js b/libs/control.js index d671933c..54bbfcd7 100644 --- a/libs/control.js +++ b/libs/control.js @@ -46,13 +46,6 @@ control.prototype.setRequestAnimationFrame = function () { core.animateFrame.speed = core.values.animateSpeed; - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; - var draw = function(timestamp) { core.animateFrame.globalTime = core.animateFrame.globalTime||timestamp; @@ -127,12 +120,27 @@ control.prototype.setRequestAnimationFrame = function () { // Animate if (timestamp-core.animateFrame.animateTime>50 && core.isset(core.status.animateObjs) && core.status.animateObjs.length>0) { core.clearMap('animate'); - core.status.animateObjs = core.status.animateObjs.filter(function (obj) { - return obj.index < obj.animate.frames.length; - }); - core.status.animateObjs.forEach(function (obj) { - core.maps.drawAnimateFrame(obj.animate, obj.centerX, obj.centerY, obj.index++); - }); + // 更新帧 + var animateObjs = []; + for (var i=0;i30) { + if (core.isPlaying() && timestamp-core.animateFrame.weather.time>30 && core.isset(core.dymCanvas.weather)) { + var ctx = core.dymCanvas.weather; var ox = core.bigmap.offsetX, oy = core.bigmap.offsetY; if (core.animateFrame.weather.type == 'rain' && core.animateFrame.weather.level > 0) { core.clearMap('weather'); - core.canvas.weather.strokeStyle = 'rgba(174,194,224,0.8)'; - core.canvas.weather.lineWidth = 1; - core.canvas.weather.lineCap = 'round'; + ctx.strokeStyle = 'rgba(174,194,224,0.8)'; + ctx.lineWidth = 1; + ctx.lineCap = 'round'; core.animateFrame.weather.nodes.forEach(function (p) { - core.canvas.weather.beginPath(); - core.canvas.weather.moveTo(p.x-ox, p.y-oy); - core.canvas.weather.lineTo(p.x + p.l * p.xs - ox, p.y + p.l * p.ys - oy); - core.canvas.weather.stroke(); + ctx.beginPath(); + ctx.moveTo(p.x-ox, p.y-oy); + ctx.lineTo(p.x + p.l * p.xs - ox, p.y + p.l * p.ys - oy); + ctx.stroke(); p.x += p.xs; p.y += p.ys; @@ -182,15 +191,14 @@ control.prototype.setRequestAnimationFrame = function () { }) - core.canvas.weather.fill(); + ctx.fill(); } else if (core.animateFrame.weather.type == 'snow' && core.animateFrame.weather.level > 0) { core.clearMap('weather'); - - core.canvas.weather.fillStyle = "rgba(255, 255, 255, 0.8)"; - core.canvas.weather.beginPath(); + ctx.fillStyle = "rgba(255, 255, 255, 0.8)"; + ctx.beginPath(); if (!core.isset(core.animateFrame.weather.data)) core.animateFrame.weather.data = 0; @@ -198,8 +206,8 @@ control.prototype.setRequestAnimationFrame = function () { var angle = core.animateFrame.weather.data; core.animateFrame.weather.nodes.forEach(function (p) { - core.canvas.weather.moveTo(p.x - ox, p.y - oy); - core.canvas.weather.arc(p.x - ox, p.y - oy, p.r, 0, Math.PI * 2, true); + ctx.moveTo(p.x - ox, p.y - oy); + ctx.arc(p.x - ox, p.y - oy, p.r, 0, Math.PI * 2, true); // update p.x += Math.sin(angle) * 2; @@ -224,7 +232,7 @@ control.prototype.setRequestAnimationFrame = function () { }) - core.canvas.weather.fill(); + ctx.fill(); } else if (core.animateFrame.weather.type == 'fog' && core.animateFrame.weather.level > 0) { @@ -233,7 +241,7 @@ control.prototype.setRequestAnimationFrame = function () { var w = 416, h = 416; core.setAlpha('weather', 0.5); core.animateFrame.weather.nodes.forEach(function (p) { - core.canvas.weather.drawImage(core.animateFrame.weather.fog, p.x - ox, p.y - oy, w, h); + ctx.drawImage(core.animateFrame.weather.fog, p.x - ox, p.y - oy, w, h); p.x += p.xs; p.y += p.ys; @@ -287,7 +295,6 @@ control.prototype.showStartAnimate = function (noAnimate, callback) { core.status.played = false; core.clearStatus(); core.clearMap('all'); - core.clearMap('curtain'); core.deleteAllCanvas(); // 重置音量 @@ -433,7 +440,7 @@ control.prototype.restart = function(noAnimate) { ////// 清除自动寻路路线 ////// control.prototype.clearAutomaticRouteNode = function (x, y) { if (core.status.event.id==null) - core.canvas.route.clearRect(x * 32 + 5, y * 32 + 5, 27, 27); + core.clearMap('route', x * 32 + 5 - core.status.automaticRoute.offsetX, y * 32 + 5 - core.status.automaticRoute.offsetY, 27, 27); } ////// 停止自动寻路操作 ////// @@ -451,7 +458,7 @@ control.prototype.stopAutomaticRoute = function () { core.status.automaticRoute.lastDirection = null; core.stopHero(); if (core.status.automaticRoute.moveStepBeforeStop.length==0) - core.clearMap('route'); + core.deleteCanvas('route'); } ////// 继续剩下的自动寻路操作 ////// @@ -469,7 +476,7 @@ control.prototype.continueAutomaticRoute = function () { ////// 清空剩下的自动寻路列表 ////// control.prototype.clearContinueAutomaticRoute = function () { - core.clearMap('route'); + core.deleteCanvas('route'); core.status.automaticRoute.moveStepBeforeStop=[]; } @@ -553,93 +560,59 @@ control.prototype.setAutomaticRoute = function (destX, destY, stepPostfix) { return; } - var step = 0; - var tempStep = null; - var moveStep; - if (!(moveStep = core.automaticRoute(destX, destY))) { - if (destX == core.status.hero.loc.x && destY == core.status.hero.loc.y){ - moveStep=[]; - } else { - core.clearMap('route'); - return; - } + var moveStep = core.automaticRoute(destX, destY).concat(stepPostfix); + if (moveStep.length == 0) { + core.deleteCanvas('route'); + return; } - moveStep=moveStep.concat(stepPostfix); + core.status.automaticRoute.destX=destX; core.status.automaticRoute.destY=destY; - core.canvas.route.save(); - core.clearMap('route'); - core.canvas.route.fillStyle = '#bfbfbf'; - core.canvas.route.strokeStyle = '#bfbfbf'; - core.canvas.route.lineWidth = 8; + + // 计算绘制区域的宽高 + var sx = core.bigmap.width * 32, sy = core.bigmap.height * 32, dx = 0, dy = 0; + moveStep.forEach(function (t) { + sx = Math.min(sx, t.x * 32); dx = Math.max(dx, t.x * 32); + sy = Math.min(sy, t.y * 32); dy = Math.max(dy, t.y * 32); + }); + core.createCanvas('route', sx-core.bigmap.offsetX, sy-core.bigmap.offsetY, dx-sx+32, dy-sy+32, 95); + core.status.automaticRoute.offsetX = sx; + core.status.automaticRoute.offsetY = sy; + var ctx = core.dymCanvas['route']; + ctx.fillStyle = '#bfbfbf'; + ctx.strokeStyle = '#bfbfbf'; + ctx.lineWidth = 8; for (var m = 0; m < moveStep.length; m++) { - if (tempStep == null) { - step++; - tempStep = moveStep[m].direction; - } - else if (tempStep == moveStep[m].direction) { - step++; - } - else { - //core.status.automaticRoutingTemp.moveStep.push({'direction': tempStep, 'step': step}); - core.status.automaticRoute.autoStepRoutes.push({'direction': tempStep, 'step': step}); - step = 1; - tempStep = moveStep[m].direction; - } if (m == moveStep.length - 1) { - // core.status.automaticRoutingTemp.moveStep.push({'direction': tempStep, 'step': step}); - core.status.automaticRoute.autoStepRoutes.push({'direction': tempStep, 'step': step}); - core.canvas.route.fillRect(moveStep[m].x * 32 + 10, moveStep[m].y * 32 + 10, 12, 12); + ctx.fillRect(moveStep[m].x * 32 + 10 - sx, moveStep[m].y * 32 + 10 - sy, 12, 12); } else { - core.canvas.route.beginPath(); - if (core.isset(moveStep[m + 1]) && tempStep != moveStep[m + 1].direction) { - if (tempStep == 'up' && moveStep[m + 1].direction == 'left' || tempStep == 'right' && moveStep[m + 1].direction == 'down') { - core.canvas.route.moveTo(moveStep[m].x * 32 + 5, moveStep[m].y * 32 + 16); - core.canvas.route.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); - core.canvas.route.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 27); - } - else if (tempStep == 'up' && moveStep[m + 1].direction == 'right' || tempStep == 'left' && moveStep[m + 1].direction == 'down') { - core.canvas.route.moveTo(moveStep[m].x * 32 + 27, moveStep[m].y * 32 + 16); - core.canvas.route.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); - core.canvas.route.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 27); - } - else if (tempStep == 'left' && moveStep[m + 1].direction == 'up' || tempStep == 'down' && moveStep[m + 1].direction == 'right') { - core.canvas.route.moveTo(moveStep[m].x * 32 + 27, moveStep[m].y * 32 + 16); - core.canvas.route.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); - core.canvas.route.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 5); - } - else if (tempStep == 'right' && moveStep[m + 1].direction == 'up' || tempStep == 'down' && moveStep[m + 1].direction == 'left') { - core.canvas.route.moveTo(moveStep[m].x * 32 + 5, moveStep[m].y * 32 + 16); - core.canvas.route.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 16); - core.canvas.route.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 5); - } - core.canvas.route.stroke(); - continue; - } - switch (tempStep) { - case 'up': - case 'down': - core.canvas.route.beginPath(); - core.canvas.route.moveTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 5); - core.canvas.route.lineTo(moveStep[m].x * 32 + 16, moveStep[m].y * 32 + 27); - core.canvas.route.stroke(); - break; - case 'left': - case 'right': - core.canvas.route.beginPath(); - core.canvas.route.moveTo(moveStep[m].x * 32 + 5, moveStep[m].y * 32 + 16); - core.canvas.route.lineTo(moveStep[m].x * 32 + 27, moveStep[m].y * 32 + 16); - core.canvas.route.stroke(); - break; - } + ctx.beginPath(); + var cx = moveStep[m].x*32 +16 - sx, cy = moveStep[m].y*32+16 - sy; + var currDir = moveStep[m].direction, nextDir = moveStep[m+1].direction; + ctx.moveTo(cx-core.utils.scan[currDir].x*11, cy-core.utils.scan[currDir].y*11); + ctx.lineTo(cx, cy); + ctx.lineTo(cx+core.utils.scan[nextDir].x*11, cy+core.utils.scan[nextDir].y*11); + ctx.stroke(); } } - core.canvas.route.restore(); + + // 路线转autoStepRoutes + var step = 0, currStep = null; + moveStep.forEach(function (t) { + var dir = t.direction; + if (currStep == null || currStep == dir) { + step++; currStep = dir; + } + else { + core.status.automaticRoute.autoStepRoutes.push({'direction': currStep, 'step': step}); + step = 1; currStep = dir; + } + }); + core.status.automaticRoute.autoStepRoutes.push({'direction': currStep, 'step': step}); // 立刻移动 core.setAutoHeroMove(); - } ////// 自动寻路算法,找寻最优路径 ////// @@ -647,13 +620,7 @@ control.prototype.automaticRoute = function (destX, destY) { var fw = core.bigmap.width, fh = core.bigmap.height; var startX = core.getHeroLoc('x'); var startY = core.getHeroLoc('y'); - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; - if (destX == startX && destY == startY) return false; + if (destX == startX && destY == startY) return []; var route = []; var queue = new PriorityQueue({comparator: function (a,b) { @@ -667,12 +634,12 @@ control.prototype.automaticRoute = function (destX, destY) { var curr = queue.dequeue(); var deep = curr.depth, nowX = curr.x, nowY = curr.y; - for (var direction in scan) { + for (var direction in core.utils.scan) { if (!core.canMoveHero(nowX, nowY, direction)) continue; - var nx = nowX + scan[direction].x; - var ny = nowY + scan[direction].y; + var nx = nowX + core.utils.scan[direction].x; + var ny = nowY + core.utils.scan[direction].y; if (nx<0 || nx>=fw || ny<0 || ny>=fh) continue; var nid = nx + fw * ny; @@ -707,15 +674,15 @@ control.prototype.automaticRoute = function (destX, destY) { if (core.isset(route[destX + fw * destY])) break; } if (!core.isset(route[destX + fw * destY])) { - return false; + return []; } var nowX = destX, nowY = destY; while (nowX != startX || nowY != startY) { var dir = route[nowX + fw * nowY]; ans.push({'direction': dir, 'x': nowX, 'y': nowY}); - nowX -= scan[dir].x; - nowY -= scan[dir].y; + nowX -= core.utils.scan[dir].x; + nowY -= core.utils.scan[dir].y; } ans.reverse(); @@ -724,7 +691,7 @@ control.prototype.automaticRoute = function (destX, destY) { ////// 显示离散的寻路点 ////// control.prototype.fillPosWithPoint = function (pos) { - core.fillRect('route', pos.x*32+12+core.bigmap.offsetX,pos.y*32+12+core.bigmap.offsetY,8,8, '#bfbfbf'); + core.fillRect('ui', pos.x*32+12,pos.y*32+12,8,8, '#bfbfbf'); } ////// 设置勇士的自动行走路线 ////// @@ -746,12 +713,6 @@ control.prototype.setHeroMoveInterval = function (direction, x, y, callback) { return; } core.status.heroMoving=1; - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; var toAdd = 1; if (core.status.replay.speed>3) @@ -764,8 +725,8 @@ control.prototype.setHeroMoveInterval = function (direction, x, y, callback) { core.interval.heroMoveInterval = window.setInterval(function () { core.status.heroMoving+=toAdd; if (core.status.heroMoving>=8) { - core.setHeroLoc('x', x+scan[direction].x, true); - core.setHeroLoc('y', y+scan[direction].y, true); + core.setHeroLoc('x', x+core.utils.scan[direction].x, true); + core.setHeroLoc('y', y+core.utils.scan[direction].y, true); core.control.updateFollowers(); core.moveOneStep(); core.clearMap('hero'); @@ -781,23 +742,17 @@ control.prototype.setHeroMoveInterval = function (direction, x, y, callback) { control.prototype.moveAction = function (callback) { if (core.interval.openDoorAnimate!=null) return; // 开门判断 if (core.status.heroMoving>0) return; - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; var direction = core.getHeroLoc('direction'); var x = core.getHeroLoc('x'); var y = core.getHeroLoc('y'); - var noPass = core.noPass(x + scan[direction].x, y + scan[direction].y), canMove = core.canMoveHero(); + var noPass = core.noPass(x + core.utils.scan[direction].x, y + core.utils.scan[direction].y), canMove = core.canMoveHero(); if (noPass || !canMove) { if (core.status.event.id!='ski') core.status.route.push(direction); core.status.automaticRoute.moveStepBeforeStop = []; core.status.automaticRoute.lastDirection = core.getHeroLoc('direction'); if (canMove) // 非箭头:触发 - core.trigger(x + scan[direction].x, y + scan[direction].y); + core.trigger(x + core.utils.scan[direction].x, y + core.utils.scan[direction].y); core.drawHero(direction, x, y); if (core.status.automaticRoute.moveStepBeforeStop.length==0) { @@ -853,7 +808,6 @@ control.prototype.turnHero = function(direction) { if (core.isset(direction)) { core.setHeroLoc('direction', direction); core.drawHero(); - core.clearMap('route'); core.status.route.push("turn:"+direction); return; } @@ -862,7 +816,6 @@ control.prototype.turnHero = function(direction) { else if (core.status.hero.loc.direction == 'down') core.status.hero.loc.direction = 'left'; else if (core.status.hero.loc.direction == 'left') core.status.hero.loc.direction = 'up'; core.drawHero(); - core.clearMap('route'); core.status.route.push("turn"); } @@ -881,14 +834,8 @@ control.prototype.moveHero = function (direction, callback) { if (core.hasFlag('debug') && core.status.ctrlDown) { if (core.status.heroMoving!=0) return; // 检测是否穿出去 - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; direction = core.getHeroLoc('direction'); - var nx = core.getHeroLoc('x') + scan[direction].x, ny=core.getHeroLoc('y') + scan[direction].y; + var nx = core.getHeroLoc('x') + core.utils.scan[direction].x, ny=core.getHeroLoc('y') + core.utils.scan[direction].y; if (nx<0 || nx>=core.bigmap.width || ny<0 || ny>=core.bigmap.height) return; core.status.heroMoving=-1; @@ -938,12 +885,6 @@ control.prototype.eventMoveHero = function(steps, time, callback) { }); var step=0; - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; var animate=window.setInterval(function() { var x=core.getHeroLoc('x'), y=core.getHeroLoc('y'); @@ -965,8 +906,8 @@ control.prototype.eventMoveHero = function(steps, time, callback) { } if (step == 8) { step = 0; - core.setHeroLoc('x', x + scan[direction].x, true); - core.setHeroLoc('y', y + scan[direction].y, true); + core.setHeroLoc('x', x + core.utils.scan[direction].x, true); + core.setHeroLoc('y', y + core.utils.scan[direction].y, true); core.control.updateFollowers(); moveSteps.shift(); } @@ -1092,6 +1033,8 @@ control.prototype.updateViewport = function() { core.bigmap.canvas.forEach(function(cn){ core.control.setGameCanvasTranslate(cn,-core.bigmap.offsetX,-core.bigmap.offsetY); }); + // ------ 路线 + core.relocateCanvas('route', core.status.automaticRoute.offsetX - core.bigmap.offsetX, core.status.automaticRoute.offsetY - core.bigmap.offsetY); } ////// 绘制勇士 ////// @@ -1099,19 +1042,12 @@ control.prototype.drawHero = function (direction, x, y, status, offset) { if (!core.isPlaying()) return; - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; - if (!core.isset(x)) x = core.getHeroLoc('x'); if (!core.isset(y)) y = core.getHeroLoc('y'); status = status || 'stop'; direction = direction || core.getHeroLoc('direction'); offset = offset || 0; - var way = scan[direction]; + var way = core.utils.scan[direction]; var offsetX = way.x*offset; var offsetY = way.y*offset; var dx=offsetX==0?0:offsetX/Math.abs(offsetX), dy=offsetY==0?0:offsetY/Math.abs(offsetY); @@ -1146,8 +1082,8 @@ control.prototype.drawHero = function (direction, x, y, status, offset) { "img": core.material.images.images[t.img], "height": core.material.images.images[t.img].height/4, "heroIcon": heroIconArr[t.direction], - "posx": 32*t.x - core.bigmap.offsetX + (t.stop?0:scan[t.direction].x*offset), - "posy": 32*t.y - core.bigmap.offsetY + (t.stop?0:scan[t.direction].y*offset), + "posx": 32*t.x - core.bigmap.offsetX + (t.stop?0:core.utils.scan[t.direction].x*offset), + "posy": 32*t.y - core.bigmap.offsetY + (t.stop?0:core.utils.scan[t.direction].y*offset), "status": t.stop?"stop":status, "index": index++ }); @@ -1184,24 +1120,12 @@ control.prototype.getHeroLoc = function (itemName) { ////// 获得勇士面对位置的x坐标 ////// control.prototype.nextX = function(n) { - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; - return core.getHeroLoc('x')+scan[core.getHeroLoc('direction')].x*(n||1); + return core.getHeroLoc('x')+core.utils.scan[core.getHeroLoc('direction')].x*(n||1); } ////// 获得勇士面对位置的y坐标 ////// control.prototype.nextY = function (n) { - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; - return core.getHeroLoc('y')+scan[core.getHeroLoc('direction')].y*(n||1); + return core.getHeroLoc('y')+core.utils.scan[core.getHeroLoc('direction')].y*(n||1); } ////// 聚集跟随者 ////// @@ -1219,16 +1143,10 @@ control.prototype.gatherFollowers = function () { ////// 更新跟随者坐标 ////// control.prototype.updateFollowers = function () { if (!core.isset(core.status.hero.followers) || core.status.hero.followers.length==0) return; - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; core.status.hero.followers.forEach(function (t) { if (!t.stop) { - t.x += scan[t.direction].x; - t.y += scan[t.direction].y; + t.x += core.utils.scan[t.direction].x; + t.y += core.utils.scan[t.direction].y; } }) @@ -1275,14 +1193,8 @@ control.prototype.checkBlock = function () { // 检查阻击事件 var snipe = []; if (!core.hasFlag("no_snipe")) { - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - } - for (var direction in scan) { - var nx = x+scan[direction].x, ny=y+scan[direction].y; + for (var direction in core.utils.scan) { + var nx = x+core.utils.scan[direction].x, ny=y+core.utils.scan[direction].y; if (nx<0 || nx>=core.bigmap.width || ny<0 || ny>=core.bigmap.height) continue; var id=core.status.checkBlock.map[nx+core.bigmap.width*ny]; if (core.isset(id)) { @@ -1330,7 +1242,7 @@ control.prototype.checkBlock = function () { } snipe = snipe.filter(function (t) { var x=t.x, y=t.y, direction = t.direction; - var nx = x+scan[direction].x, ny=y+scan[direction].y; + var nx = x+core.utils.scan[direction].x, ny=y+core.utils.scan[direction].y; return nx>=0 && nx=0 && ny=core.bigmap.width||ny<0||ny>=core.bigmap.height) return; diff --git a/libs/maps.js b/libs/maps.js index b7f62b88..e4149a23 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -296,13 +296,7 @@ maps.prototype.canMoveHero = function(x,y,direction,floorId) { if (!check(core.getBlock(x,y,floorId),"cannotOut") || !check(getNumber(floorId,"bg",x,y),"cannotOut") || !check(getNumber(floorId,"fg",x,y),"cannotOut")) return false; - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; - var nx = x+scan[direction].x, ny = y+scan[direction].y; + var nx = x+core.utils.scan[direction].x, ny = y+core.utils.scan[direction].y; // 检查目标点的cannotIn if (!check(core.getBlock(nx,ny,floorId),"cannotIn") || !check(getNumber(floorId,"bg",nx,ny),"cannotIn") || !check(getNumber(floorId,"fg",nx,ny),"cannotIn")) return false; @@ -482,7 +476,6 @@ maps.prototype.drawMap = function (floorId, callback) { return; } core.clearMap('all'); - core.removeGlobalAnimate(null, null, true); var drawBg = function(){ var width = core.floors[floorId].width || 13; @@ -896,12 +889,6 @@ maps.prototype.moveBlock = function(x,y,steps,time,keep,callback) { }); var nowX=32*x, nowY=32*y, step=0; - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - }; var animateValue = block.event.animate || 1, animateCurrent = isTileset?bx:0, animateTime = 0; var blockCanvas = this.__initBlockCanvas(block, height, x, y); @@ -954,8 +941,8 @@ maps.prototype.moveBlock = function(x,y,steps,time,keep,callback) { } } step++; - nowX+=scan[direction].x*2; - nowY+=scan[direction].y*2; + nowX+=core.utils.scan[direction].x*2; + nowY+=core.utils.scan[direction].y*2; // 移动 core.maps.__moveBlockCanvas(image, animateCurrent, by, height, nowX, nowY, opacity, headCanvas, bodyCanvas, damageCanvas); if (step==16) { @@ -1377,34 +1364,22 @@ maps.prototype.drawAnimate = function (name, x, y, callback) { return; } - clearInterval(core.interval.animateInterval); - // 开始绘制 var animate = core.material.animates[name], centerX = 32*x+16, centerY = 32*y+16; // 播放音效 core.playSound(animate.se); - // 异步绘制:使用requestAnimationFrame进行绘制 - if (!core.isset(callback)) { - core.status.animateObjs.push({"animate": animate, "centerX": centerX, "centerY": centerY, "index": 0}); - return; - } + var animateId = parseInt(Math.random() * 100000000); + core.status.animateObjs.push({ + "animate": animate, + "centerX": centerX, + "centerY": centerY, + "index": 0, + "id": animateId, + "callback": callback + }); - var index=0; - core.clearMap('animate'); - core.maps.drawAnimateFrame(animate, centerX, centerY, index++); - - core.interval.animateInterval = setInterval(function (t) { - if (index == animate.frames.length) { - clearInterval(core.interval.animateInterval); - core.clearMap('animate'); - core.setAlpha('animate', 1); - if (core.isset(callback)) callback(); - return; - } - core.clearMap('animate'); - core.maps.drawAnimateFrame(animate, centerX, centerY, index++); - }, 50); + core.animateFrame.asyncId[animateId] = true; } maps.prototype.setFloorImage = function (type, loc, floorId, callback) { diff --git a/libs/ui.js b/libs/ui.js index 575dbf24..7a632dc9 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -29,11 +29,10 @@ ui.prototype.getContextByName = function (name) { ui.prototype.clearMap = function (name, x, y, width, height) { if (name == 'all') { for (var m in core.canvas) { - // 不擦除curtain层 - if (m=='curtain') continue; core.canvas[m].clearRect(0, 0, core.bigmap.width*32, core.bigmap.height*32); } core.dom.gif.innerHTML = ""; + core.removeGlobalAnimate(0,0,true); } else { var ctx = this.getContextByName(name); @@ -1817,8 +1816,7 @@ ui.prototype.drawMaps = function (index, x, y) { core.status.event.data = null; core.clearLastEvent(); - core.clearMap('animate'); - core.fillRect('animate', 0, 0, 416, 416, 'rgba(0,0,0,0.4)'); + core.fillRect('ui', 0, 0, 416, 416, 'rgba(0,0,0,0.4)'); core.strokeRect('ui', 66, 2, 284, 60, "#FFD700", 4); core.strokeRect('ui', 2, 66, 60, 284); @@ -1858,8 +1856,6 @@ ui.prototype.drawMaps = function (index, x, y) { return; } - core.clearMap('animate'); - var damage = (core.status.event.data||{}).damage, paint = (core.status.event.data||{}).paint; var all = (core.status.event.data||{}).all; if (core.isset(index.damage)) damage=index.damage; @@ -1885,8 +1881,7 @@ ui.prototype.drawMaps = function (index, x, y) { core.status.event.data = {"index": index, "x": x, "y": y, "damage": damage, "paint": paint, "all": all}; clearTimeout(core.interval.tipAnimate); - core.clearMap('ui'); - core.setAlpha('ui', 1); + core.clearLastEvent(); this.drawThumbnail(floorId, 'ui', core.status.maps[floorId].blocks, 0, 0, 416, x, y); // 绘图 @@ -2723,18 +2718,16 @@ ui.prototype.drawPaint = function () { core.status.event.data = {"x": null, "y": null, "erase": false}; core.clearLastEvent(); - core.clearMap('route'); - - core.setAlpha('route', 1); + core.createCanvas('paint', -core.bigmap.offsetX, -core.bigmap.offsetY, 32*core.bigmap.width, 32*core.bigmap.height, 95); // 将已有的内容绘制到route上 var value = core.paint[core.status.floorId]; if (core.isset(value)) value = LZString.decompress(value).split(","); core.utils.decodeCanvas(value, 32*core.bigmap.width, 32*core.bigmap.height); - core.canvas.route.drawImage(core.bigmap.tempCanvas.canvas, 0, 0); + core.dymCanvas.paint.drawImage(core.bigmap.tempCanvas.canvas, 0, 0); - core.setLineWidth('route', 3); - core.setStrokeStyle('route', '#FF0000'); + core.setLineWidth('paint', 3); + core.setStrokeStyle('paint', '#FF0000'); core.statusBar.image.shop.style.opacity = 0; diff --git a/libs/utils.js b/libs/utils.js index 5a356344..63e91eeb 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -7,6 +7,12 @@ utils.js 工具类 function utils() { this.init(); + this.scan = { + 'up': {'x': 0, 'y': -1}, + 'left': {'x': -1, 'y': 0}, + 'down': {'x': 0, 'y': 1}, + 'right': {'x': 1, 'y': 0} + }; } utils.prototype.init = function () { diff --git a/project/functions.js b/project/functions.js index 6bcaa815..ecf7e223 100644 --- a/project/functions.js +++ b/project/functions.js @@ -58,9 +58,9 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = var replaying = core.status.replay.replaying; core.stopReplay(); core.waitHeroToStop(function() { - core.removeGlobalAnimate(0,0,true); - core.clearMap('all'); core.clearMap('curtain'); // 清空全地图 - core.deleteAllCanvas(); + core.clearMap('all'); // 清空全地图 + core.deleteAllCanvas(); // 删除所有创建的画布 + core.dom.gif2.innerHTML = ""; // 请注意: // 成绩统计时是按照hp进行上传并排名,因此光在这里改${status:hp}是无效的 // 如需按照其他的的分数统计方式,请先将hp设置为你的得分 @@ -84,9 +84,62 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = core.events.gameOver(null, replaying); }); }) +}, + "changingFloor": function (floorId, heroLoc, fromLoad) { + // 正在切换楼层过程中执行的操作;此函数的执行时间是“屏幕完全变黑“的那一刻 + // floorId为要切换到的楼层ID;heroLoc表示勇士切换到的位置;fromLoad表示是否是从读档造成的切换 + + // ---------- 此时还没有进行切换,当前floorId还是原来的 ---------- // + var currentId = core.status.floorId || null; // 获得当前的floorId,可能为null + // 可以对currentId进行判定,比如删除某些自定义图层等 + // if (currentId == 'MT0') { + // core.deleteAllCanvas(); + // } + + // 重置画布尺寸 + core.maps.resizeMap(floorId); + // 检查重生怪并重置 + if (!fromLoad) { + core.status.maps[floorId].blocks.forEach(function(block) { + if (block.disable && core.isset(block.event) && block.event.cls.indexOf('enemy')==0 && + core.enemys.hasSpecial(core.material.enemys[block.event.id].special, 23)) { + block.disable = false; + } + }); + } + // 设置勇士的位置 + core.status.hero.loc = heroLoc; + + // ---------- 重绘新地图;这一步将会设置core.status.floorId ---------- // + core.drawMap(floorId); + + // 切换楼层BGM + if (core.isset(core.status.maps[floorId].bgm)) { + var bgm = core.status.maps[floorId].bgm; + if (bgm instanceof Array) bgm = bgm[0]; + core.playBgm(bgm); + } + // 更改画面色调 + var color = core.getFlag('__color__', null); + if (!core.isset(color) && core.isset(core.status.maps[floorId].color)) + color = core.status.maps[floorId].color; + if (core.isset(color)) { + core.fillRect('curtain',0,0,416,416,core.arrayToRGBA(color)); + core.status.curtainColor = color; + } + // 更改天气 + var weather = core.getFlag('__weather__', null); + if (!core.isset(weather) && core.isset(core.status.maps[floorId].weather)) + weather = core.status.maps[floorId].weather; + if (core.isset(weather)) + core.setWeather(weather[0], weather[1]); + else core.setWeather(); + + // ...可以新增一些其他内容,比如创建个画布在右上角显示什么内容等等 + }, "afterChangeFloor": function (floorId, fromLoad) { - // 转换楼层结束的事件 + // 转换楼层结束的事件;此函数会在整个楼层切换完全结束后再执行 // floorId是切换到的楼层;fromLoad若为true则代表是从读档行为造成的楼层切换 // 每次抵达楼层时执行的事件 @@ -1114,14 +1167,9 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = }, "drawAbout": function() { // 绘制“关于”界面 - if (!core.isPlaying()) { - core.status.event = {'id': null, 'data': null}; - core.dom.startPanel.style.display = 'none'; - } - core.lockControl(); + core.ui.closePanel(); core.status.event.id = 'about'; - core.clearMap('ui'); var left = 48, top = 36, right = 416 - 2 * left, bottom = 416 - 2 * top; core.setAlpha('ui', 0.85); @@ -1210,7 +1258,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = this.drawLight = function (color, lights, lightDec) { // 清空色调层;也可以修改成其它层比如animate/weather层,或者用自己创建的canvas var canvasName = 'curtain'; - var ctx = core.ui.getContextByName(canvasName); + var ctx = core.getContextByName(canvasName); if (ctx == null) return; ctx.mozImageSmoothingEnabled = false; diff --git a/styles.css b/styles.css index 8609eedb..5d6e9c08 100644 --- a/styles.css +++ b/styles.css @@ -286,14 +286,6 @@ p#name { z-index: 70; } -#weather { - z-index: 80; -} - -#route { - z-index: 95; -} - #curtain { z-index: 100; }