Astar 学习

Astar寻路教程

http://www.cnblogs.com/thunder123/archive/2010/08/18/1802199.html

学习代码[持续添加] :



<style type="text/css">
#area{border: dashed 1px #999; overflow: hidden; position: relative;}
.item{border-right: dashed 1px #999;border-bottom: dashed 1px #999; position: absolute;}


</style>
<div id="area">

</div>
<script type="text/javascript">
var Map={
width : 940,
height : 600,
map : {},//map10 : {xc:0, yc:0, len:0, map:[]}

makeDB : function(length){//按length为边长建立索引数据表
var xc = parseInt((this.width - 1) / length) + 1;
var yc = parseInt((this.height - 1) / length) + 1;
var map = [];
for(var i=0;i<xc;i++){
if(!map[i]) map[i]=[];
for(var j=0;j<yc;j++){
map[i][j]=0;
}
}
this.map['map'+length]={xc:map.length, yc:map[0].length, len:length, map:map};
},
drawDB : function(db){
var html='';
for(var i=0;i<db.xc;i++){
for(var j=0;j<db.yc;j++){
html += '<div id="b-' + i + '-' + j + '" class="item" style="height:' + db.len + 'px;width:' + db.len + 'px;left:' + (db.len*i) + 'px;top:' + (db.len*j) + 'px"></div>';
}
}
$('#area').html(html);
},
init : function(xc, yc){
//set map size
$('#area').css({width : this.width, height : this.height});

//create db
this.makeDB(10);
this.makeDB(50);
this.makeDB(100);

//drawDB
//this.drawDB(this.map.map10);
//this.drawDB(this.map.map50);
this.drawDB(this.map.map100);
}
}

Map.init();


var Astar = {

}
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值