core: BFS add arrow block

This commit is contained in:
echo 2017-12-17 22:34:30 +08:00
parent c32ed6b5aa
commit 8ae9697c5e
5 changed files with 42 additions and 43 deletions

View File

@ -3,7 +3,6 @@
## 简介 ## 简介
HTML5 canvas制作的魔塔样板支持全平台游戏 HTML5 canvas制作的魔塔样板支持全平台游戏
**即使完全不会编程的用户,按照模板和说明文档也能很快做出一个魔塔游戏!** **即使完全不会编程的用户,按照模板和说明文档也能很快做出一个魔塔游戏!**
* [Demo / 样板效果](http://ckcz123.com/games/template/) * [Demo / 样板效果](http://ckcz123.com/games/template/)

View File

@ -904,14 +904,15 @@ core.prototype.automaticRoute = function (destX, destY) {
if (deep!==nowDeep) {queue.push(f);continue;} if (deep!==nowDeep) {queue.push(f);continue;}
f=f%169; f=f%169;
var nowX = parseInt(f / 13), nowY = f % 13; var nowX = parseInt(f / 13), nowY = f % 13;
var nowIsArrow = false, nowId, nowBlock = core.getBlock(nowX,nowY);
if (nowBlock!=null){
nowId = nowBlock.block.event.id;
nowIsArrow = nowId.slice(0, 5).toLowerCase() == 'arrow';
}
for (var direction in scan) { for (var direction in scan) {
var nowArrow, nowId, nowBlock = core.getBlock(nowX,nowX); if(nowIsArrow){
if (nowBlock!=null){ var nowArrow = nowId.slice(5).toLowerCase();
nowId = nowBlock.block.event.id; if (direction != nowArrow) continue;
nowArrow = nowId.slice(5).toLowerCase();
var isArrow = nowId.slice(0, 5).toLowerCase() == 'arrow';
if (isArrow && direction != nowArrow) continue;
} }
var nx = nowX + scan[direction].x; var nx = nowX + scan[direction].x;
@ -919,35 +920,38 @@ core.prototype.automaticRoute = function (destX, destY) {
if (nx<0 || nx>12 || ny<0 || ny>12) continue; if (nx<0 || nx>12 || ny<0 || ny>12) continue;
var nextId, nextArrow, nextBlock = core.getBlock(nx,ny);
if (nextBlock!=null){
nextId = nextBlock.block.event.id;
nextArrow = nextId.slice(5).toLowerCase();
var isArrow = nextId.slice(0, 5).toLowerCase() == 'arrow';
if (isArrow && (scan[direction].x + scan[nextArrow].x) == 0 && (scan[direction].y + scan[nextArrow].y) == 0 ) continue;
}
var nid = 13 * nx + ny; var nid = 13 * nx + ny;
if (core.isset(route[nid])) continue; if (core.isset(route[nid])) continue;
var deepAdd=1;
var nextId, nextBlock = core.getBlock(nx,ny);
if (nextBlock!=null){
nextId = nextBlock.block.event.id;console.log(nextId);
// 遇到单向箭头处理
var isArrow = nextId.slice(0, 5).toLowerCase() == 'arrow';
if(isArrow){
var nextArrow = nextId.slice(5).toLowerCase();
if ( (scan[direction].x + scan[nextArrow].x) == 0 && (scan[direction].y + scan[nextArrow].y) == 0 ) continue;
}
// 绕过亮灯(因为只有一次通行机会很宝贵)
if(nextId == "light") deepAdd=50;
// 绕过路障
if (nextId.substring(nextId.length-3)=="Net") deepAdd=100;
// 绕过血瓶
if (!core.flags.potionWhileRouting && nextId.substring(nextId.length-6)=="Potion") deepAdd=20;
// 绕过可能的夹击点
if (nextBlock.block.event.trigger == 'checkBlock') deepAdd=200;
}
if (nx == destX && ny == destY) { if (nx == destX && ny == destY) {
route[nid] = direction; route[nid] = direction;
break; break;
} }
if (core.noPassExists(nx, ny)) if (core.noPassExists(nx, ny))
continue; continue;
var deepAdd=1;
var block = core.getBlock(nx,ny);
if (block!=null) {
var id = block.block.event.id;
// 绕过路障
if (id.substring(id.length-3)=="Net") deepAdd=100;
// 绕过血瓶
if (!core.flags.potionWhileRouting && id.substring(id.length-6)=="Potion") deepAdd=20;
// 绕过可能的夹击点
if (block.block.event.trigger == 'checkBlock') deepAdd=200;
}
route[nid] = direction; route[nid] = direction;
queue.push(169*(nowDeep+deepAdd)+nid); queue.push(169*(nowDeep+deepAdd)+nid);
} }

View File

@ -9,7 +9,7 @@ main.floors.sample1 = {
"canUseQuickShop": true, // 该层是否允许使用快捷商店 "canUseQuickShop": true, // 该层是否允许使用快捷商店
"map": [ // 地图数据需要是13x13建议使用地图生成器来生成 "map": [ // 地图数据需要是13x13建议使用地图生成器来生成
[7, 131, 8, 2, 9, 130, 10, 2, 166, 165, 132, 165, 166], [7, 131, 8, 2, 9, 130, 10, 2, 166, 165, 132, 165, 166],
[0, 0, 0, 0, 0, 0, 0, 2, 165, 164, 0, 162, 165], [0, 0, 0, 0, 0, 0, 0, 2, 165, 164, 0, 162, 165],
[2, 2, 2, 2, 121, 2, 2, 2, 0, 0, 229, 0, 0], [2, 2, 2, 2, 121, 2, 2, 2, 0, 0, 229, 0, 0],
[43, 33, 44, 1, 0, 0, 0, 2, 165, 161, 0, 163, 165], [43, 33, 44, 1, 0, 0, 0, 2, 165, 161, 0, 163, 165],
[21, 22, 21, 1, 0, 0, 0, 2, 166, 165, 0, 165, 166], [21, 22, 21, 1, 0, 0, 0, 2, 166, 165, 0, 165, 166],
@ -17,8 +17,8 @@ main.floors.sample1 = {
[0, 246, 0, 1, 0, 0, 0, 2, 2, 221, 0, 221, 2], [0, 246, 0, 1, 0, 0, 0, 2, 2, 221, 0, 221, 2],
[246, 0, 246, 1, 0, 0, 0, 121, 85, 0, 0, 0, 2], [246, 0, 246, 1, 0, 0, 0, 121, 85, 0, 0, 0, 2],
[1, 246, 1, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2], [1, 246, 1, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 164, 0, 0, 163, 0, 0],
[1, 1, 1, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 0, 3, 0, 0, 0, 162, 0, 161, 0],
[1, 0, 123, 1, 0, 3, 124, 0, 121, 0, 122, 0, 126], [1, 0, 123, 1, 0, 3, 124, 0, 121, 0, 122, 0, 126],
[1, 0, 0, 1, 88, 3, 86, 0, 0, 0, 0, 0, 0], [1, 0, 0, 1, 88, 3, 86, 0, 0, 0, 0, 0, 0],
], ],

View File

@ -30,10 +30,10 @@ icons.prototype.init = function () {
'blueShop-right': 16, 'blueShop-right': 16,
'pinkShop-left': 17, 'pinkShop-left': 17,
'pinkShop-right': 18, 'pinkShop-right': 18,
'up': 19, 'arrowUp': 19,
'down': 20, 'arrowDown': 20,
'left': 21, 'arrowLeft': 21,
'right': 22, 'arrowRight': 22,
'light': 23, 'light': 23,
'darkLight': 24 'darkLight': 24
}, },

View File

@ -78,13 +78,9 @@ maps.prototype.getBlock = function (x, y, id) {
if (id == 12) tmp.event = {'cls': 'animates', 'id': 'poisonNet', 'noPass': false, 'trigger': 'passNet'}; // 毒网 if (id == 12) tmp.event = {'cls': 'animates', 'id': 'poisonNet', 'noPass': false, 'trigger': 'passNet'}; // 毒网
if (id == 13) tmp.event = {'cls': 'animates', 'id': 'weakNet', 'noPass': false, 'trigger': 'passNet'}; // 衰网 if (id == 13) tmp.event = {'cls': 'animates', 'id': 'weakNet', 'noPass': false, 'trigger': 'passNet'}; // 衰网
if (id == 14) tmp.event = {'cls': 'animates', 'id': 'curseNet', 'noPass': false, 'trigger': 'passNet'}; // 咒网 if (id == 14) tmp.event = {'cls': 'animates', 'id': 'curseNet', 'noPass': false, 'trigger': 'passNet'}; // 咒网
<<<<<<< HEAD
=======
if (id == 20) tmp.event = {'cls': 'autotile', 'id': 'autotile', 'noPass': true}; if (id == 20) tmp.event = {'cls': 'autotile', 'id': 'autotile', 'noPass': true};
>>>>>>> 0de35b6258ac07977783fbb03f6a2d491faf4cf1
// 21-80 物品 // 21-80 物品
if (id == 21) tmp.event = {'cls': 'items', 'id': 'yellowKey'}; // 黄钥匙 if (id == 21) tmp.event = {'cls': 'items', 'id': 'yellowKey'}; // 黄钥匙
if (id == 22) tmp.event = {'cls': 'items', 'id': 'blueKey'}; // 蓝钥匙 if (id == 22) tmp.event = {'cls': 'items', 'id': 'blueKey'}; // 蓝钥匙
@ -164,10 +160,10 @@ maps.prototype.getBlock = function (x, y, id) {
if (id == 132) tmp.event = {'cls': 'npcs', 'id': 'princess'}; if (id == 132) tmp.event = {'cls': 'npcs', 'id': 'princess'};
// 161-200 其他(单向箭头、灯、箱子等等) // 161-200 其他(单向箭头、灯、箱子等等)
if (id == 161) tmp.event = {'cls': 'terrains', 'id': 'up'}; // 单向上箭头 if (id == 161) tmp.event = {'cls': 'terrains', 'id': 'arrowUp', 'noPass': false}; // 单向上箭头
if (id == 162) tmp.event = {'cls': 'terrains', 'id': 'down'}; // 单向下箭头 if (id == 162) tmp.event = {'cls': 'terrains', 'id': 'arrowDown', 'noPass': false}; // 单向下箭头
if (id == 163) tmp.event = {'cls': 'terrains', 'id': 'left'}; // 单向左箭头 if (id == 163) tmp.event = {'cls': 'terrains', 'id': 'arrowLeft', 'noPass': false}; // 单向左箭头
if (id == 164) tmp.event = {'cls': 'terrains', 'id': 'right'}; // 单向右箭头 if (id == 164) tmp.event = {'cls': 'terrains', 'id': 'arrowRight', 'noPass': false}; // 单向右箭头
if (id == 165) tmp.event = {'cls': 'terrains', 'id': 'light', 'trigger': 'changeLight', 'noPass': false}; // 灯 if (id == 165) tmp.event = {'cls': 'terrains', 'id': 'light', 'trigger': 'changeLight', 'noPass': false}; // 灯
if (id == 166) tmp.event = {'cls': 'terrains', 'id': 'darkLight', 'noPass': true}; // 暗灯 if (id == 166) tmp.event = {'cls': 'terrains', 'id': 'darkLight', 'noPass': true}; // 暗灯