autotileEdges
This commit is contained in:
parent
2a98e74847
commit
43a1876ae9
@ -387,22 +387,24 @@ actions.prototype.onmove = function (loc) {
|
||||
|
||||
var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size);
|
||||
|
||||
var pos={'x':x,'y':y};
|
||||
var pos0=core.status.stepPostfix[core.status.stepPostfix.length-1];
|
||||
var directionDistance=[pos.y-pos0.y,pos0.x-pos.x,pos0.y-pos.y,pos.x-pos0.x];
|
||||
var max=0,index=4;
|
||||
for(var ii=0;ii<4;ii++){
|
||||
if(directionDistance[ii]>max){
|
||||
index=ii;
|
||||
max=directionDistance[ii];
|
||||
if ((core.status.stepPostfix||[]).length>0) {
|
||||
var pos={'x':x,'y':y};
|
||||
var pos0=core.status.stepPostfix[core.status.stepPostfix.length-1];
|
||||
var directionDistance=[pos.y-pos0.y,pos0.x-pos.x,pos0.y-pos.y,pos.x-pos0.x];
|
||||
var max=0,index=4;
|
||||
for(var ii=0;ii<4;ii++){
|
||||
if(directionDistance[ii]>max){
|
||||
index=ii;
|
||||
max=directionDistance[ii];
|
||||
}
|
||||
}
|
||||
pos=[{'x':0,'y':1},{'x':-1,'y':0},{'x':0,'y':-1},{'x':1,'y':0},false][index]
|
||||
if(pos){
|
||||
pos.x+=pos0.x;
|
||||
pos.y+=pos0.y;
|
||||
core.status.stepPostfix.push(pos);
|
||||
core.fillPosWithPoint(pos);
|
||||
}
|
||||
}
|
||||
pos=[{'x':0,'y':1},{'x':-1,'y':0},{'x':0,'y':-1},{'x':1,'y':0},false][index]
|
||||
if(pos){
|
||||
pos.x+=pos0.x;
|
||||
pos.y+=pos0.y;
|
||||
core.status.stepPostfix.push(pos);
|
||||
core.fillPosWithPoint(pos);
|
||||
}
|
||||
}
|
||||
|
||||
@ -422,7 +424,7 @@ actions.prototype.onup = function () {
|
||||
core.interval.onDownInterval = null;
|
||||
|
||||
// core.status.holdingPath=0;
|
||||
if(core.status.stepPostfix.length>0){
|
||||
if ((core.status.stepPostfix||[]).length>0) {
|
||||
var stepPostfix = [];
|
||||
var direction={'0':{'1':'down','-1':'up'},'-1':{'0':'left'},'1':{'0':'right'}};
|
||||
for(var ii=1;ii<core.status.stepPostfix.length;ii++){
|
||||
|
||||
@ -377,10 +377,10 @@ control.prototype.resetStatus = function(hero, hard, floorId, route, maps, value
|
||||
|
||||
// 清除游戏数据
|
||||
core.clearStatus();
|
||||
core.status.played = true;
|
||||
|
||||
// 初始化status
|
||||
core.status = core.clone(core.initStatus);
|
||||
core.status.played = true;
|
||||
// 初始化maps
|
||||
core.status.floorId = floorId;
|
||||
core.status.maps = core.clone(maps);
|
||||
|
||||
@ -40,6 +40,10 @@ loader.prototype.load = function (callback) {
|
||||
// 加载autotile
|
||||
core.material.images.autotile = {};
|
||||
core.loader.loadImages(Object.keys(core.material.icons.autotile), core.material.images.autotile, function () {
|
||||
|
||||
setTimeout(function () {
|
||||
core.maps.makeAutotileEdges();
|
||||
});
|
||||
|
||||
// 加载tilesets
|
||||
core.material.images.tilesets = {};
|
||||
|
||||
31
libs/maps.js
31
libs/maps.js
@ -627,7 +627,7 @@ maps.prototype.drawAutotile = function(ctx, mapArr, block, size, left, top, stat
|
||||
}
|
||||
var getAutotileAroundId = function(currId, x, y) {
|
||||
if(x<0 || y<0 || x>=mapArr[0].length || y>=mapArr.length) return 1;
|
||||
else return mapArr[y][x]==currId ? 1:0;
|
||||
else return core.material.autotileEdges[currId].indexOf(mapArr[y][x])>=0;
|
||||
}
|
||||
var checkAround = function(x, y){ // 得到周围四个32*32块(周围每块都包含当前块的1/4,不清楚的话画下图你就明白)的数组索引
|
||||
var currId = mapArr[y][x];
|
||||
@ -681,6 +681,35 @@ maps.prototype.drawAutotile = function(ctx, mapArr, block, size, left, top, stat
|
||||
}
|
||||
}
|
||||
|
||||
////// 为autotile判定边界 //////
|
||||
maps.prototype.makeAutotileEdges = function () {
|
||||
var autotileIds = Object.keys(core.material.images.autotile);
|
||||
core.material.autotileEdges = {};
|
||||
|
||||
var canvas = document.createElement("canvas"), ctx = canvas.getContext('2d');
|
||||
canvas.width = canvas.height = 32;
|
||||
|
||||
autotileIds.forEach(function (t) {
|
||||
var n = core.maps.getNumberById(t);
|
||||
core.material.autotileEdges[n] = [n];
|
||||
|
||||
ctx.clearRect(0,0,32,32);
|
||||
ctx.drawImage(core.material.images.autotile[t], 0, 0, 32, 32, 0, 0, 32, 32);
|
||||
var data = canvas.toDataURL("image/png");
|
||||
|
||||
autotileIds.forEach(function (t2) {
|
||||
if (t==t2) return;
|
||||
var n2 = core.maps.getNumberById(t2);
|
||||
|
||||
ctx.clearRect(0,0,32,32);
|
||||
ctx.drawImage(core.material.images.autotile[t2], 32, 0, 32, 32, 0, 0, 32, 32);
|
||||
if (data == canvas.toDataURL("image/png")) {
|
||||
core.material.autotileEdges[n].push(n2);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
////// 某个点是否不可通行 //////
|
||||
maps.prototype.noPassExists = function (x, y, floorId) {
|
||||
var block = core.getBlock(x,y,floorId);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user