From 8ae9697c5ed59471f1bed668b538cf74f5edfbac Mon Sep 17 00:00:00 2001 From: echo Date: Sun, 17 Dec 2017 22:34:30 +0800 Subject: [PATCH] core: BFS add arrow block --- README.md | 1 - libs/core.js | 58 ++++++++++++++++++++++-------------------- libs/floors/sample1.js | 6 ++--- libs/icons.js | 8 +++--- libs/maps.js | 12 +++------ 5 files changed, 42 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index ba7776ea..9fdc6774 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ ## 简介 HTML5 canvas制作的魔塔样板,支持全平台游戏! - **即使完全不会编程的用户,按照模板和说明文档也能很快做出一个魔塔游戏!** * [Demo / 样板效果](http://ckcz123.com/games/template/) diff --git a/libs/core.js b/libs/core.js index a781d388..4f904d86 100644 --- a/libs/core.js +++ b/libs/core.js @@ -904,14 +904,15 @@ core.prototype.automaticRoute = function (destX, destY) { if (deep!==nowDeep) {queue.push(f);continue;} f=f%169; 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) { - var nowArrow, nowId, nowBlock = core.getBlock(nowX,nowX); - if (nowBlock!=null){ - nowId = nowBlock.block.event.id; - nowArrow = nowId.slice(5).toLowerCase(); - var isArrow = nowId.slice(0, 5).toLowerCase() == 'arrow'; - if (isArrow && direction != nowArrow) continue; + if(nowIsArrow){ + var nowArrow = nowId.slice(5).toLowerCase(); + if (direction != nowArrow) continue; } 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; - 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; 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) { route[nid] = direction; break; } if (core.noPassExists(nx, ny)) 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; queue.push(169*(nowDeep+deepAdd)+nid); } diff --git a/libs/floors/sample1.js b/libs/floors/sample1.js index 4104b7b1..afb288c3 100644 --- a/libs/floors/sample1.js +++ b/libs/floors/sample1.js @@ -9,7 +9,7 @@ main.floors.sample1 = { "canUseQuickShop": true, // 该层是否允许使用快捷商店 "map": [ // 地图数据,需要是13x13,建议使用地图生成器来生成 [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], [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], @@ -17,8 +17,8 @@ main.floors.sample1 = { [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], [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], - [1, 1, 1, 1, 0, 3, 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, 162, 0, 161, 0], [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], ], diff --git a/libs/icons.js b/libs/icons.js index f35d9b86..63004e1f 100644 --- a/libs/icons.js +++ b/libs/icons.js @@ -30,10 +30,10 @@ icons.prototype.init = function () { 'blueShop-right': 16, 'pinkShop-left': 17, 'pinkShop-right': 18, - 'up': 19, - 'down': 20, - 'left': 21, - 'right': 22, + 'arrowUp': 19, + 'arrowDown': 20, + 'arrowLeft': 21, + 'arrowRight': 22, 'light': 23, 'darkLight': 24 }, diff --git a/libs/maps.js b/libs/maps.js index 45063126..48e35c02 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -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 == 13) tmp.event = {'cls': 'animates', 'id': 'weakNet', '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}; ->>>>>>> 0de35b6258ac07977783fbb03f6a2d491faf4cf1 // 21-80 物品 if (id == 21) tmp.event = {'cls': 'items', 'id': 'yellowKey'}; // 黄钥匙 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'}; // 161-200 其他(单向箭头、灯、箱子等等) - if (id == 161) tmp.event = {'cls': 'terrains', 'id': 'up'}; // 单向上箭头 - if (id == 162) tmp.event = {'cls': 'terrains', 'id': 'down'}; // 单向下箭头 - if (id == 163) tmp.event = {'cls': 'terrains', 'id': 'left'}; // 单向左箭头 - if (id == 164) tmp.event = {'cls': 'terrains', 'id': 'right'}; // 单向右箭头 + if (id == 161) tmp.event = {'cls': 'terrains', 'id': 'arrowUp', 'noPass': false}; // 单向上箭头 + if (id == 162) tmp.event = {'cls': 'terrains', 'id': 'arrowDown', 'noPass': false}; // 单向下箭头 + if (id == 163) tmp.event = {'cls': 'terrains', 'id': 'arrowLeft', 'noPass': false}; // 单向左箭头 + 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 == 166) tmp.event = {'cls': 'terrains', 'id': 'darkLight', 'noPass': true}; // 暗灯