updated 布景事件绑定统一
This commit is contained in:
parent
8f7ce44514
commit
53f69650e8
3
game.js
3
game.js
@ -185,7 +185,8 @@ function Game(id,options){
|
|||||||
map:null, //布景地图对象
|
map:null, //布景地图对象
|
||||||
audio:[], //音频资源
|
audio:[], //音频资源
|
||||||
images:[], //图片资源
|
images:[], //图片资源
|
||||||
items:[] //对象队列
|
items:[], //对象队列
|
||||||
|
update:function(){} //嗅探,处理布局下不同对象的相对关系
|
||||||
};
|
};
|
||||||
for(var i in settings){
|
for(var i in settings){
|
||||||
this[i] = options[i]||settings[i];
|
this[i] = options[i]||settings[i];
|
||||||
|
39
index.js
39
index.js
@ -1,12 +1,5 @@
|
|||||||
//主程序,业务逻辑
|
//主程序,业务逻辑
|
||||||
(function(){
|
(function(){
|
||||||
//处理映射关系
|
|
||||||
var _ORIENTATION = { //方向
|
|
||||||
'39':0, //右
|
|
||||||
'40':1, //下
|
|
||||||
'37':2, //左
|
|
||||||
'38':3, //上
|
|
||||||
},
|
|
||||||
_DATA = [ //地图数据
|
_DATA = [ //地图数据
|
||||||
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
|
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
|
||||||
[1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1],
|
[1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1],
|
||||||
@ -109,13 +102,9 @@
|
|||||||
})();
|
})();
|
||||||
//游戏主程序
|
//游戏主程序
|
||||||
(function(){
|
(function(){
|
||||||
var stage = game.createStage();
|
var stage = game.createStage({
|
||||||
stage.bind('keydown',function(e){
|
update:function(){
|
||||||
switch(e.keyCode){
|
|
||||||
case 13:
|
|
||||||
case 32:
|
|
||||||
this.status = this.status==2?1:2;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//绘制地图
|
//绘制地图
|
||||||
@ -262,6 +251,7 @@
|
|||||||
context.fill();
|
context.fill();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
//NPC
|
||||||
for(var i=0;i<4;i++){
|
for(var i=0;i<4;i++){
|
||||||
var pos = map.coord2position(12+i,14);
|
var pos = map.coord2position(12+i,14);
|
||||||
stage.createItem({
|
stage.createItem({
|
||||||
@ -345,9 +335,26 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
//布景事件绑定
|
||||||
stage.bind('keydown',function(e){
|
stage.bind('keydown',function(e){
|
||||||
player.control = {orientation:_ORIENTATION[e.keyCode]};
|
switch(e.keyCode){
|
||||||
|
case 13: //回车
|
||||||
|
case 32: //空格
|
||||||
|
this.status = this.status==2?1:2;
|
||||||
|
break;
|
||||||
|
case 39: //右
|
||||||
|
player.control = {orientation:0};
|
||||||
|
break;
|
||||||
|
case 40: //下
|
||||||
|
player.control = {orientation:1};
|
||||||
|
break;
|
||||||
|
case 37: //左
|
||||||
|
player.control = {orientation:2};
|
||||||
|
break;
|
||||||
|
case 38: //上
|
||||||
|
player.control = {orientation:3};
|
||||||
|
break;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
game.init();
|
game.init();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user