updated 添加布景更新方法,当玩家与NPC相遇时暂停布景
This commit is contained in:
parent
53f69650e8
commit
8848cbf001
6
game.js
6
game.js
@ -200,6 +200,7 @@ function Game(id,options){
|
|||||||
var fn = function(){
|
var fn = function(){
|
||||||
_context.clearRect(0,0,_.width,_.height); //清除画布
|
_context.clearRect(0,0,_.width,_.height); //清除画布
|
||||||
f++;
|
f++;
|
||||||
|
stage.update();
|
||||||
if(stage.map){
|
if(stage.map){
|
||||||
stage.map.update();
|
stage.map.update();
|
||||||
stage.map.draw(_context);
|
stage.map.draw(_context);
|
||||||
@ -241,9 +242,10 @@ function Game(id,options){
|
|||||||
return item;
|
return item;
|
||||||
};
|
};
|
||||||
//获取对象列表
|
//获取对象列表
|
||||||
Stage.prototype.getItemsByType = function(type){
|
Stage.prototype.getItemsByType = function(){
|
||||||
|
var types = Array.prototype.slice.call(arguments,0);
|
||||||
var items = this.items.filter(function(item){
|
var items = this.items.filter(function(item){
|
||||||
if(item.type==type){
|
if(types.indexOf(item.type)>-1){
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
18
index.js
18
index.js
@ -104,7 +104,21 @@
|
|||||||
(function(){
|
(function(){
|
||||||
var stage = game.createStage({
|
var stage = game.createStage({
|
||||||
update:function(){
|
update:function(){
|
||||||
|
if(this.map){
|
||||||
|
var stage = this;
|
||||||
|
var items = this.getItemsByType(1,2);
|
||||||
|
var hash = {}; //当前对象位置分布
|
||||||
|
items.forEach(function(item){
|
||||||
|
var key = 'x'+item.coord.x+'y'+item.coord.y; //坐标的标识
|
||||||
|
if(hash[key]){
|
||||||
|
if(hash[key]!=item.type){ //如果NPC与玩家相遇
|
||||||
|
stage.status = 2;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
hash[key] = item.type;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//绘制地图
|
//绘制地图
|
||||||
@ -358,5 +372,5 @@
|
|||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
game.init();
|
game.init();
|
||||||
game.nextStage(); //测试游戏主布景
|
game.nextStage(); //*测试*游戏主布景,完成后需关闭
|
||||||
})();
|
})();
|
Loading…
x
Reference in New Issue
Block a user