var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = { "init": function () { console.log("插件编写测试"); // 可以写一些直接执行的代码 // 在这里写的代码将会在【资源加载前】被执行,此时图片等资源尚未被加载。 // 请勿在这里对包括bgm,图片等资源进行操作。 this._afterLoadResources = function () { // 本函数将在所有资源加载完毕后,游戏开启前被执行 // 可以在这个函数里面对资源进行一些操作,比如切分图片等。 // 这是一个将assets.png拆分成若干个32x32像素的小图片并保存的样例。 // var arr = core.splitImage("assets.png", 32, 32); // for (var i = 0; i < arr.length; i++) { // core.material.images.images["asset"+i+".png"] = arr[i]; // } } // 可以在任何地方(如afterXXX或自定义脚本事件)调用函数,方法为 core.plugin.xxx(); // 从V2.6开始,插件中用this.XXX方式定义的函数也会被转发到core中,详见文档-脚本-函数的转发。 }, "drawLight": function () { // 绘制灯光/漆黑层效果。调用方式 core.plugin.drawLight(...) // 【参数说明】 // name:必填,要绘制到的画布名;可以是一个系统画布,或者是个自定义画布;如果不存在则创建 // color:可选,只能是一个0~1之间的数,为不透明度的值。不填则默认为0.9。 // lights:可选,一个数组,定义了每个独立的灯光。 // 其中每一项是三元组 [x,y,r] x和y分别为该灯光的横纵坐标,r为该灯光的半径。 // lightDec:可选,0到1之间,光从多少百分比才开始衰减(在此范围内保持全亮),不设置默认为0。 // 比如lightDec为0.5代表,每个灯光部分内圈50%的范围全亮,50%以后才开始快速衰减。 // 【调用样例】 // core.plugin.drawLight('curtain'); // 在curtain层绘制全图不透明度0.9,等价于更改画面色调为[0,0,0,0.9]。 // core.plugin.drawLight('ui', 0.95, [[25,11,46]]); // 在ui层绘制全图不透明度0.95,其中在(25,11)点存在一个半径为46的灯光效果。 // core.plugin.drawLight('test', 0.2, [[25,11,46,0.1]]); // 创建一个test图层,不透明度0.2,其中在(25,11)点存在一个半径为46的灯光效果,灯光中心不透明度0.1。 // core.plugin.drawLight('test2', 0.9, [[25,11,46],[105,121,88],[301,221,106]]); // 创建test2图层,且存在三个灯光效果,分别是中心(25,11)半径46,中心(105,121)半径88,中心(301,221)半径106。 // core.plugin.drawLight('xxx', 0.3, [[25,11,46],[105,121,88,0.2]], 0.4); // 存在两个灯光效果,它们在内圈40%范围内保持全亮,且40%后才开始衰减。 this.drawLight = function (name, color, lights, lightDec) { // 清空色调层;也可以修改成其它层比如animate/weather层,或者用自己创建的canvas var ctx = core.getContextByName(name); if (ctx == null) { if (typeof name == 'string') ctx = core.createCanvas(name, 0, 0, core.__PIXELS__, core.__PIXELS__, 98); else return; } ctx.mozImageSmoothingEnabled = false; ctx.webkitImageSmoothingEnabled = false; ctx.msImageSmoothingEnabled = false; ctx.imageSmoothingEnabled = false; core.clearMap(name); // 绘制色调层,默认不透明度 if (color == null) color = 0.9; ctx.fillStyle = "rgba(0,0,0," + color + ")"; ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height); lightDec = core.clamp(lightDec, 0, 1); // 绘制每个灯光效果 ctx.globalCompositeOperation = 'destination-out'; lights.forEach(function (light) { // 坐标,半径,中心不透明度 var x = light[0], y = light[1], r = light[2]; // 计算衰减距离 var decDistance = parseInt(r * lightDec); // 正方形区域的直径和左上角坐标 var grd = ctx.createRadialGradient(x, y, decDistance, x, y, r); grd.addColorStop(0, "rgba(0,0,0,1)"); grd.addColorStop(1, "rgba(0,0,0,0)"); ctx.beginPath(); ctx.fillStyle = grd; ctx.arc(x, y, r, 0, 2 * Math.PI); ctx.fill(); }); 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)); } }