commit
a05a0a382f
11
docs/api.md
11
docs/api.md
@ -141,9 +141,11 @@ core.js实际上是所有API的入口(路由),核心API的实现在其他
|
|||||||
core.nextX()
|
core.nextX()
|
||||||
获得勇士面向的下一个位置的x坐标
|
获得勇士面向的下一个位置的x坐标
|
||||||
|
|
||||||
|
|
||||||
core.nextY()
|
core.nextY()
|
||||||
获得勇士面向的下一个位置的y坐标
|
获得勇士面向的下一个位置的y坐标
|
||||||
|
|
||||||
|
|
||||||
core.openDoor(id, x, y, needKey, callback) [异步]
|
core.openDoor(id, x, y, needKey, callback) [异步]
|
||||||
尝试开门操作。id为目标点的ID,x和y为坐标,needKey表示是否需要使用钥匙,callback为开门完毕后的回调函数。
|
尝试开门操作。id为目标点的ID,x和y为坐标,needKey表示是否需要使用钥匙,callback为开门完毕后的回调函数。
|
||||||
例如:core.openDoor('yellowDoor', 10, 3, false, function() {console.log("1")})
|
例如:core.openDoor('yellowDoor', 10, 3, false, function() {console.log("1")})
|
||||||
@ -208,6 +210,10 @@ core.removeBlock(x, y, floorId)
|
|||||||
否则将该点设置为禁用,以供以后可能的启用事件。
|
否则将该点设置为禁用,以供以后可能的启用事件。
|
||||||
|
|
||||||
|
|
||||||
|
core.setBlock(number, x, y, floorId)
|
||||||
|
改变图块。number为要改变到的图块数字,x和y为坐标,floorId为楼层ID,可忽略表示当前楼层。
|
||||||
|
|
||||||
|
|
||||||
core.useItem(itemId, callback)
|
core.useItem(itemId, callback)
|
||||||
尝试使用某个道具。itemId为道具ID,callback为成功或失败后的回调。
|
尝试使用某个道具。itemId为道具ID,callback为成功或失败后的回调。
|
||||||
|
|
||||||
@ -270,10 +276,6 @@ core.restart() [异步]
|
|||||||
返回标题界面。
|
返回标题界面。
|
||||||
|
|
||||||
|
|
||||||
core.updateFg()
|
|
||||||
更新全地图显伤。包括怪物显伤、临界显示和领域显伤等。
|
|
||||||
|
|
||||||
|
|
||||||
========== core.actions.XXX 和游戏控制相关的函数 ==========
|
========== core.actions.XXX 和游戏控制相关的函数 ==========
|
||||||
actions.js主要用来进行用户交互行为的处理。
|
actions.js主要用来进行用户交互行为的处理。
|
||||||
所有用户行为,比如按键、点击、滑动等等,都会被此文件接收并进行操作。
|
所有用户行为,比如按键、点击、滑动等等,都会被此文件接收并进行操作。
|
||||||
@ -389,6 +391,7 @@ floorId为楼层ID,可忽略为当前楼层。
|
|||||||
|
|
||||||
core.maps.canMoveDirectly(destX, destY)
|
core.maps.canMoveDirectly(destX, destY)
|
||||||
判断当前能否瞬间移动到某个点。
|
判断当前能否瞬间移动到某个点。
|
||||||
|
该函数如果返回0则不可瞬间移动,大于0则可以瞬间移动,且返回值是跨度(即少走的步数)。
|
||||||
|
|
||||||
|
|
||||||
core.maps.removeBlockById(index, floorId)
|
core.maps.removeBlockById(index, floorId)
|
||||||
|
|||||||
@ -63,6 +63,7 @@ control.prototype.setRequestAnimationFrame = function () {
|
|||||||
if (core.isPlaying() && core.isset(core.status) && core.isset(core.status.hero)
|
if (core.isPlaying() && core.isset(core.status) && core.isset(core.status.hero)
|
||||||
&& core.isset(core.status.hero.statistics)) {
|
&& core.isset(core.status.hero.statistics)) {
|
||||||
core.status.hero.statistics.totalTime += timestamp-(core.status.hero.statistics.start||timestamp);
|
core.status.hero.statistics.totalTime += timestamp-(core.status.hero.statistics.start||timestamp);
|
||||||
|
core.status.hero.statistics.currTime += timestamp-(core.status.hero.statistics.start||timestamp);
|
||||||
core.status.hero.statistics.start=timestamp;
|
core.status.hero.statistics.start=timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,6 +267,7 @@ control.prototype.resetStatus = function(hero, hard, floorId, route, maps) {
|
|||||||
if (!core.isset(core.status.hero.statistics))
|
if (!core.isset(core.status.hero.statistics))
|
||||||
core.status.hero.statistics = {
|
core.status.hero.statistics = {
|
||||||
'totalTime': totalTime,
|
'totalTime': totalTime,
|
||||||
|
'currTime': 0,
|
||||||
'hp': 0,
|
'hp': 0,
|
||||||
'battleDamage': 0,
|
'battleDamage': 0,
|
||||||
'poisonDamage': 0,
|
'poisonDamage': 0,
|
||||||
@ -2317,6 +2319,8 @@ control.prototype.updateStatusBar = function () {
|
|||||||
|
|
||||||
var statusList = ['hpmax', 'hp', 'atk', 'def', 'mdef', 'money', 'experience'];
|
var statusList = ['hpmax', 'hp', 'atk', 'def', 'mdef', 'money', 'experience'];
|
||||||
statusList.forEach(function (item) {
|
statusList.forEach(function (item) {
|
||||||
|
if (core.isset(core.status.hero[item]))
|
||||||
|
core.status.hero[item] = Math.floor(core.status.hero[item]);
|
||||||
core.statusBar[item].innerHTML = core.formatBigNumber(core.getStatus(item));
|
core.statusBar[item].innerHTML = core.formatBigNumber(core.getStatus(item));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -687,6 +687,11 @@ core.prototype.removeBlockByIds = function (floorId, ids) {
|
|||||||
core.maps.removeBlockByIds(floorId, ids);
|
core.maps.removeBlockByIds(floorId, ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////// 改变图块 //////
|
||||||
|
core.prototype.setBlock = function (number, x, y, floorId) {
|
||||||
|
core.maps.setBlock(number, x, y, floorId);
|
||||||
|
}
|
||||||
|
|
||||||
////// 添加一个全局动画 //////
|
////// 添加一个全局动画 //////
|
||||||
core.prototype.addGlobalAnimate = function (block) {
|
core.prototype.addGlobalAnimate = function (block) {
|
||||||
core.maps.addGlobalAnimate(block);
|
core.maps.addGlobalAnimate(block);
|
||||||
|
|||||||
@ -187,6 +187,7 @@ events.prototype.gameOver = function (ending, fromReplay) {
|
|||||||
formData.append('experience', core.status.hero.experience);
|
formData.append('experience', core.status.hero.experience);
|
||||||
formData.append('steps', core.status.hero.steps);
|
formData.append('steps', core.status.hero.steps);
|
||||||
formData.append('seed', core.getFlag('seed'));
|
formData.append('seed', core.getFlag('seed'));
|
||||||
|
formData.append('totalTime', Math.floor(core.status.hero.statistics.totalTime));
|
||||||
formData.append('route', core.encodeRoute(core.status.route));
|
formData.append('route', core.encodeRoute(core.status.route));
|
||||||
|
|
||||||
if (main.isCompetition)
|
if (main.isCompetition)
|
||||||
@ -396,24 +397,7 @@ events.prototype.doAction = function() {
|
|||||||
x=core.calValue(data.loc[0]);
|
x=core.calValue(data.loc[0]);
|
||||||
y=core.calValue(data.loc[1]);
|
y=core.calValue(data.loc[1]);
|
||||||
}
|
}
|
||||||
var floorId = data.floorId||core.status.floorId;
|
core.setBlock(data.number, x, y, data.floorId);
|
||||||
var originBlock=core.getBlock(x,y,floorId,false);
|
|
||||||
var block = core.maps.initBlock(x,y,data.number);
|
|
||||||
core.maps.addInfo(block);
|
|
||||||
core.maps.addEvent(block,x,y,core.floors[floorId].events[x+","+y]);
|
|
||||||
core.maps.addChangeFloor(block,x,y,core.floors[floorId].changeFloor[x+","+y]);
|
|
||||||
if (core.isset(block.event)) {
|
|
||||||
if (originBlock==null) {
|
|
||||||
core.status.maps[floorId].blocks.push(block);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
originBlock.block.id = data.number;
|
|
||||||
originBlock.block.event = block.event;
|
|
||||||
}
|
|
||||||
if (floorId==core.status.floorId) {
|
|
||||||
core.drawMap(floorId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.doAction();
|
this.doAction();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -872,10 +856,16 @@ events.prototype.openDoor = function (id, x, y, needKey, callback) {
|
|||||||
core.stopAutomaticRoute();
|
core.stopAutomaticRoute();
|
||||||
var speed=30;
|
var speed=30;
|
||||||
var doorId = id;
|
var doorId = id;
|
||||||
if (!(doorId.substring(doorId.length-4)=="Door")) {
|
if (doorId.length<4 || doorId.substring(doorId.length-4)!="Door") {
|
||||||
doorId=doorId+"Door";
|
doorId=doorId+"Door";
|
||||||
speed=70;
|
speed=70;
|
||||||
}
|
}
|
||||||
|
// 不存在门
|
||||||
|
if (!core.isset(core.material.icons.animates[doorId])) {
|
||||||
|
if (core.isset(callback)) callback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var key = id.replace("Door", "Key");
|
var key = id.replace("Door", "Key");
|
||||||
if (needKey && (key=="specialKey" || core.isset(core.material.items[key]))) {
|
if (needKey && (key=="specialKey" || core.isset(core.material.items[key]))) {
|
||||||
var key = id.replace("Door", "Key");
|
var key = id.replace("Door", "Key");
|
||||||
|
|||||||
36
libs/maps.js
36
libs/maps.js
@ -255,16 +255,18 @@ maps.prototype.canMoveHero = function(x,y,direction,floorId) {
|
|||||||
|
|
||||||
////// 能否瞬间移动 //////
|
////// 能否瞬间移动 //////
|
||||||
maps.prototype.canMoveDirectly = function (destX,destY) {
|
maps.prototype.canMoveDirectly = function (destX,destY) {
|
||||||
if (!core.flags.enableMoveDirectly) return -1;
|
|
||||||
|
// 不可瞬间移动请返回0
|
||||||
|
if (!core.flags.enableMoveDirectly) return 0;
|
||||||
|
|
||||||
// 中毒状态:不能
|
// 中毒状态:不能
|
||||||
if (core.hasFlag('poison')) return -1;
|
if (core.hasFlag('poison')) return 0;
|
||||||
|
|
||||||
var fromX = core.getHeroLoc('x'), fromY = core.getHeroLoc('y');
|
var fromX = core.getHeroLoc('x'), fromY = core.getHeroLoc('y');
|
||||||
if (fromX==destX&&fromY==destY) return -1;
|
if (fromX==destX&&fromY==destY) return 0;
|
||||||
|
|
||||||
if (core.getBlock(fromX,fromY)!=null||core.status.checkBlock.damage[13*fromX+fromY]>0)
|
if (core.getBlock(fromX,fromY)!=null||core.status.checkBlock.damage[13*fromX+fromY]>0)
|
||||||
return -1;
|
return 0;
|
||||||
|
|
||||||
// BFS
|
// BFS
|
||||||
var visited=[], queue=[];
|
var visited=[], queue=[];
|
||||||
@ -283,7 +285,7 @@ maps.prototype.canMoveDirectly = function (destX,destY) {
|
|||||||
queue.push(13*nx+ny);
|
queue.push(13*nx+ny);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
maps.prototype.drawBlock = function (block, animate, dx, dy) {
|
maps.prototype.drawBlock = function (block, animate, dx, dy) {
|
||||||
@ -774,6 +776,30 @@ maps.prototype.removeBlockByIds = function (floorId, ids) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////// 改变图块 //////
|
||||||
|
maps.prototype.setBlock = function (number, x, y, floorId) {
|
||||||
|
floorId = floorId || core.status.floorId;
|
||||||
|
if (!core.isset(number) || !core.isset(x) || !core.isset(y)) return;
|
||||||
|
|
||||||
|
var originBlock=core.getBlock(x,y,floorId,false);
|
||||||
|
var block = core.maps.initBlock(x,y,number);
|
||||||
|
core.maps.addInfo(block);
|
||||||
|
core.maps.addEvent(block,x,y,core.floors[floorId].events[x+","+y]);
|
||||||
|
core.maps.addChangeFloor(block,x,y,core.floors[floorId].changeFloor[x+","+y]);
|
||||||
|
if (core.isset(block.event)) {
|
||||||
|
if (originBlock==null) {
|
||||||
|
core.status.maps[floorId].blocks.push(block);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
originBlock.block.id = data.number;
|
||||||
|
originBlock.block.event = block.event;
|
||||||
|
}
|
||||||
|
if (floorId==core.status.floorId) {
|
||||||
|
core.drawMap(floorId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////// 添加一个全局动画 //////
|
////// 添加一个全局动画 //////
|
||||||
maps.prototype.addGlobalAnimate = function (b) {
|
maps.prototype.addGlobalAnimate = function (b) {
|
||||||
if (main.mode=='editor' && main.editor.disableGlobalAnimate) return;
|
if (main.mode=='editor' && main.editor.disableGlobalAnimate) return;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user