From 37d5ddd3f1e73161c817dafc1e9148762af92fa0 Mon Sep 17 00:00:00 2001 From: user670 <22617255+user670@users.noreply.github.com> Date: Mon, 8 Apr 2019 19:52:16 +0800 Subject: [PATCH 1/4] Update api.md fix copy paste fail --- _docs/api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_docs/api.md b/_docs/api.md index a61be655..54e8b916 100644 --- a/_docs/api.md +++ b/_docs/api.md @@ -199,7 +199,7 @@ core.onkeyDown(e) core.onkeyUp(e) 当放开某个键时的操作,e为KeyboardEvent。 -请勿直接覆盖或调用此函数,如有需要请注册一个"onkeyDown"的交互函数。 +请勿直接覆盖或调用此函数,如有需要请注册一个"onkeyUp"的交互函数。 core.pressKey(keyCode) From 69b52acb463672ba2299df9069134e262bfcb804 Mon Sep 17 00:00:00 2001 From: dljgs1 <906348668@qq.com> Date: Wed, 17 Apr 2019 19:54:22 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=B7=9F=E9=9A=8F=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/ui.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/ui.js b/libs/ui.js index 6764fda6..0ec48f66 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -403,9 +403,9 @@ ui.prototype._getPosition = function (content) { py = core.status.event.data.y; } content = content.replace("\b", "\\b") - .replace(/\\b\[(up|center|down|hero|null)(,(hero|null|\d+,\d+))?]/g, function (s0, s1, s2, s3) { + .replace(/\\b\[(up|center|down|hero|null)(,(hero|null|\d+,\d+|\d+))?]/g, function (s0, s1, s2, s3) { pos = s1; - if (s3 == 'hero' || s1=='hero') { + if (s3 == 'hero' || s1=='hero' && !s3) { px = core.status.hero.loc.x; py = core.status.hero.loc.y; } @@ -414,8 +414,14 @@ ui.prototype._getPosition = function (content) { } else if (s3) { var str = s3.split(','); - px = parseInt(str[0]); - py = parseInt(str[1]); + if(str.length==1){ + var follower = (core.status.hero.followers||{})[parseInt(str[0])-1]||{}; + px = follower.x || null; + py = follower.y || null; + }else{ + px = parseInt(str[0]); + py = parseInt(str[1]); + } } if(pos=='hero' || pos=='null'){ pos = py==null?'center':(py>=core.__HALF_SIZE__? 'up':'down'); From 3b7f3471b411a18cb74d8d784386ef8fb4a6e34f Mon Sep 17 00:00:00 2001 From: Zhang Chen Date: Wed, 17 Apr 2019 22:56:42 +0800 Subject: [PATCH 3/4] =?UTF-8?q?Revert=20"=E8=B7=9F=E9=9A=8F=E8=80=85?= =?UTF-8?q?=E7=9A=84=E5=AF=B9=E8=AF=9D=E6=A1=86"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/ui.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/libs/ui.js b/libs/ui.js index e6e9baf7..e689ef59 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -403,9 +403,9 @@ ui.prototype._getPosition = function (content) { py = core.status.event.data.y; } content = content.replace("\b", "\\b") - .replace(/\\b\[(up|center|down|hero|null)(,(hero|null|\d+,\d+|\d+))?]/g, function (s0, s1, s2, s3) { + .replace(/\\b\[(up|center|down|hero|null)(,(hero|null|\d+,\d+))?]/g, function (s0, s1, s2, s3) { pos = s1; - if (s3 == 'hero' || s1=='hero' && !s3) { + if (s3 == 'hero' || s1=='hero') { px = core.status.hero.loc.x; py = core.status.hero.loc.y; } @@ -414,14 +414,8 @@ ui.prototype._getPosition = function (content) { } else if (s3) { var str = s3.split(','); - if(str.length==1){ - var follower = (core.status.hero.followers||{})[parseInt(str[0])-1]||{}; - px = follower.x || null; - py = follower.y || null; - }else{ - px = parseInt(str[0]); - py = parseInt(str[1]); - } + px = parseInt(str[0]); + py = parseInt(str[1]); } if(pos=='hero' || pos=='null'){ pos = py==null?'center':(py>=core.__HALF_SIZE__? 'up':'down'); From 20d047bb1810e8db968398b7dd216075ff026089 Mon Sep 17 00:00:00 2001 From: fux4 Date: Wed, 23 Oct 2019 13:01:40 +0800 Subject: [PATCH 4/4] plugin - smoothCamera --- project/plugins.js | 145 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/project/plugins.js b/project/plugins.js index d09e9944..9f68186a 100644 --- a/project/plugins.js +++ b/project/plugins.js @@ -84,5 +84,150 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = ctx.globalCompositeOperation = 'source-over'; // 可以在任何地方(如afterXXX或自定义脚本事件)调用函数,方法为 core.plugin.xxx(); } +}, + "smoothCamera": function () { + + this.Camera = function () { + + // 下面这个变量决定本插件的开关 + // 你可以在游戏中使用core.setFlag('smoothCamera',false)来关闭本插件的功能 + // 同时也可以core.setFlag('smoothCamera',true)重新开启 + // 本插件默认开启 + // + this.__switchName = 'smoothCamera'; + + // 初始化成员变量 + this._cameraNeedRefresh = true; + this._nowOffsetX = 0; + this._nowOffsetY = 0; + this._targetOffsetX = 0; + this._targetOffsetY = 0; + this._currentFloorId = null; + + // 重置镜头,在楼层变更时使用 + this.resetCamera = function () { + this._targetOffsetX = core.bigmap.offsetX; + this._targetOffsetY = core.bigmap.offsetY; + this._nowOffsetX = this._targetOffsetX; + this._nowOffsetY = this._targetOffsetY; + this._cameraNeedRefresh = true; + }; + + // 设置焦点坐标,目前没有用 + this.setTarget = function (x, y) { + this._targetOffsetX = x; + this._targetOffsetY = y; + }; + + // 请求镜头更新 + this.requestCameraUpdate = function () { + this._cameraNeedRefresh = true; + }; + + // 更新焦点坐标,目前仅根据大地图偏移决定 + this.updateTargetPosition = function () { + this._targetOffsetX = core.bigmap.offsetX; + this._targetOffsetY = core.bigmap.offsetY; + }; + + // 更新额外的刷新条件,即镜头未指向焦点时 + this.updateRefreshFlag = function () { + if (this._nowOffsetX != this._targetOffsetX || this._nowOffsetY != this._targetOffsetY) { + this._cameraNeedRefresh = true; + } + }; + + // 判断是否禁止了弹性滚动 + this.canDirectMove = function () { + return !core.getFlag(this.__switchName, true); + }; + + // 更新镜头坐标 + this.updateCameraPosition = function () { + if (this._cameraNeedRefresh) { + this._cameraNeedRefresh = false; + var disX = this._targetOffsetX - this._nowOffsetX; + var disY = this._targetOffsetY - this._nowOffsetY; + if (Math.abs(disX) <= 2 && Math.abs(disY) <= 2 || this.canDirectMove()) { + this._nowOffsetX = this._targetOffsetX; + this._nowOffsetY = this._targetOffsetY; + } else { + this._nowOffsetX += disX / 10; + this._nowOffsetY += disY / 10; + } + var x = -Math.floor(this._nowOffsetX); + var y = -Math.floor(this._nowOffsetY); + core.bigmap.canvas.forEach(function (cn) { + core.control.setGameCanvasTranslate(cn, x, y); + }); + core.relocateCanvas('route', core.status.automaticRoute.offsetX + x, core.status.automaticRoute.offsetY + y); + core.setGameCanvasTranslate('hero', x + this._targetOffsetX, y + this._targetOffsetY); + } + }; + + // 更新逻辑主体 + this.update = function () { + this.updateTargetPosition(); + this.updateRefreshFlag(); + this.updateCameraPosition(); + }; + }; + + // 其实只注释了最后一行,只能这样了 + control.drawHero = function (status, offset) { + if (!core.isPlaying() || !core.status.floorId || core.status.gameOver) return; + var x = core.getHeroLoc('x'), + y = core.getHeroLoc('y'), + direction = core.getHeroLoc('direction'); + status = status || 'stop'; + offset = offset || 0; + var way = core.utils.scan[direction]; + var dx = way.x, + dy = way.y, + offsetX = dx * offset, + offsetY = dy * offset; + core.bigmap.offsetX = core.clamp((x - core.__HALF_SIZE__) * 32 + offsetX, 0, 32 * core.bigmap.width - core.__PIXELS__); + core.bigmap.offsetY = core.clamp((y - core.__HALF_SIZE__) * 32 + offsetY, 0, 32 * core.bigmap.height - core.__PIXELS__); + core.clearAutomaticRouteNode(x + dx, y + dy); + core.clearMap('hero'); + + if (!core.hasFlag('hideHero')) { + this._drawHero_getDrawObjs(direction, x, y, status, offset).forEach(function (block) { + core.drawImage('hero', block.img, block.heroIcon[block.status] * block.width, + block.heroIcon.loc * block.height, block.width, block.height, + block.posx + (32 - block.width) / 2, block.posy + 32 - block.height, block.width, block.height); + }); + } + + core.control.updateViewport(); + //core.setGameCanvasTranslate('hero', 0, 0); + }; + + // 复写转发 + core.drawHero = function (status, offset) { + return core.control.drawHero(status, offset); + }; + + // 创建摄像机对象 + this.camera = new this.Camera(); + + // 帧事件 更新摄像机 + this.updateCameraEx = function () { + this.camera.update(); + }; + + // 代理原本的镜头事件 + control.updateViewport = function () { + core.plugin.camera.requestCameraUpdate(); + }; + + // 更变楼层的行为追加,重置镜头 + events.prototype.changingFloor = function (floorId, heroLoc, fromLoad) { + this.eventdata.changingFloor(floorId, heroLoc, fromLoad); + core.plugin.camera.resetCamera(); + }; + + // 注册帧事件 + core.registerAnimationFrame('smoothCameraFlash', true, this.updateCameraEx.bind(this)); } } \ No newline at end of file