Merge pull request #132 from ckcz123/v2.0

V2.0
This commit is contained in:
Zhang Chen 2018-05-25 23:00:01 +08:00 committed by GitHub
commit a05a0a382f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 28 deletions

View File

@ -141,9 +141,11 @@ core.js实际上是所有API的入口路由核心API的实现在其他
core.nextX()
获得勇士面向的下一个位置的x坐标
core.nextY()
获得勇士面向的下一个位置的y坐标
core.openDoor(id, x, y, needKey, callback) [异步]
尝试开门操作。id为目标点的IDx和y为坐标needKey表示是否需要使用钥匙callback为开门完毕后的回调函数。
例如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)
尝试使用某个道具。itemId为道具IDcallback为成功或失败后的回调。
@ -270,10 +276,6 @@ core.restart() [异步]
返回标题界面。
core.updateFg()
更新全地图显伤。包括怪物显伤、临界显示和领域显伤等。
========== core.actions.XXX 和游戏控制相关的函数 ==========
actions.js主要用来进行用户交互行为的处理。
所有用户行为,比如按键、点击、滑动等等,都会被此文件接收并进行操作。
@ -389,6 +391,7 @@ floorId为楼层ID可忽略为当前楼层。
core.maps.canMoveDirectly(destX, destY)
判断当前能否瞬间移动到某个点。
该函数如果返回0则不可瞬间移动大于0则可以瞬间移动且返回值是跨度即少走的步数
core.maps.removeBlockById(index, floorId)

View File

@ -63,6 +63,7 @@ control.prototype.setRequestAnimationFrame = function () {
if (core.isPlaying() && core.isset(core.status) && core.isset(core.status.hero)
&& core.isset(core.status.hero.statistics)) {
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;
}
@ -266,6 +267,7 @@ control.prototype.resetStatus = function(hero, hard, floorId, route, maps) {
if (!core.isset(core.status.hero.statistics))
core.status.hero.statistics = {
'totalTime': totalTime,
'currTime': 0,
'hp': 0,
'battleDamage': 0,
'poisonDamage': 0,
@ -2317,6 +2319,8 @@ control.prototype.updateStatusBar = function () {
var statusList = ['hpmax', 'hp', 'atk', 'def', 'mdef', 'money', 'experience'];
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));
});

View File

@ -687,6 +687,11 @@ core.prototype.removeBlockByIds = function (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.maps.addGlobalAnimate(block);

View File

@ -187,6 +187,7 @@ events.prototype.gameOver = function (ending, fromReplay) {
formData.append('experience', core.status.hero.experience);
formData.append('steps', core.status.hero.steps);
formData.append('seed', core.getFlag('seed'));
formData.append('totalTime', Math.floor(core.status.hero.statistics.totalTime));
formData.append('route', core.encodeRoute(core.status.route));
if (main.isCompetition)
@ -396,24 +397,7 @@ events.prototype.doAction = function() {
x=core.calValue(data.loc[0]);
y=core.calValue(data.loc[1]);
}
var floorId = data.floorId||core.status.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);
}
}
core.setBlock(data.number, x, y, data.floorId);
this.doAction();
break;
}
@ -872,10 +856,16 @@ events.prototype.openDoor = function (id, x, y, needKey, callback) {
core.stopAutomaticRoute();
var speed=30;
var doorId = id;
if (!(doorId.substring(doorId.length-4)=="Door")) {
if (doorId.length<4 || doorId.substring(doorId.length-4)!="Door") {
doorId=doorId+"Door";
speed=70;
}
// 不存在门
if (!core.isset(core.material.icons.animates[doorId])) {
if (core.isset(callback)) callback();
return;
}
var key = id.replace("Door", "Key");
if (needKey && (key=="specialKey" || core.isset(core.material.items[key]))) {
var key = id.replace("Door", "Key");

View File

@ -255,16 +255,18 @@ maps.prototype.canMoveHero = function(x,y,direction,floorId) {
////// 能否瞬间移动 //////
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');
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)
return -1;
return 0;
// BFS
var visited=[], queue=[];
@ -283,7 +285,7 @@ maps.prototype.canMoveDirectly = function (destX,destY) {
queue.push(13*nx+ny);
}
}
return -1;
return 0;
}
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) {
if (main.mode=='editor' && main.editor.disableGlobalAnimate) return;