From 4aa1c1b30f3693b1b62e9aa98463d506b4a9bcc4 Mon Sep 17 00:00:00 2001 From: mumuy Date: Mon, 15 Jan 2018 11:59:17 +0800 Subject: [PATCH] =?UTF-8?q?updated=20=E6=B7=BB=E5=8A=A0=E5=A4=9A=E5=85=B3?= =?UTF-8?q?=E5=8D=A1=E6=94=AF=E6=8C=81=EF=BC=884=E5=85=B3=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- game.js | 6 +- index.js | 970 +++++++++++++++++++++++++++++++----------------------- 3 files changed, 568 insertions(+), 412 deletions(-) diff --git a/README.md b/README.md index 59b49f7..34d804d 100644 --- a/README.md +++ b/README.md @@ -12,5 +12,5 @@ - [x] NPC根据玩家坐标实时自动寻径 - [x] 吃豆积分系统 - [x] 能量豆功能 -- [ ] 特殊物品记分 -- [ ] 多关卡 +- [x] 多关卡 +- [ ] 特殊物品记分 \ No newline at end of file diff --git a/game.js b/game.js index 06f333c..9670c24 100644 --- a/game.js +++ b/game.js @@ -237,7 +237,7 @@ function Game(id,params){ this._params = params||{}; this._settings = { index:0, //布景索引 - status:0, //布景状态,0表示未激活/结束,1表示正常,2表示暂停,3表示临时,4表示异常 + status:0, //布景状态,0表示未激活/结束,1表示正常,2表示暂停,3表示临时状态 maps:[], //地图队列 audio:[], //音频资源 images:[], //图片资源 @@ -412,6 +412,10 @@ function Game(id,params){ throw new Error('unfound new stage.'); } }; + //获取布景列表 + this.getStages = function(){ + return _stages; + }; //初始化游戏引擎 this.init = function(){ _index = 0; diff --git a/index.js b/index.js index db7326d..ef30754 100644 --- a/index.js +++ b/index.js @@ -1,49 +1,180 @@ //主程序,业务逻辑 (function(){ - var _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,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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,0,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,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], - [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], - [1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1], - [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], - [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], - [1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1], - [1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1], - [1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1], - [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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] - ], - _GOODS = { //能量豆 - '1,3':1, - '26,3':1, - '1,23':1, - '26,23':1 - }, + var _COIGIG = [ //关卡 + { //第1关 + 'map':[ //地图数据 + [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,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], + [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], + [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1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,0,1,1,1,1,1,0,1,1,1,1,0,1], + [1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1], + [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], + [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], + [1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1], + [1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1], + [1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1], + [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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] + ], + 'wall_color':'#09f', + 'goods':{ //能量豆 + '1,3':1, + '26,3':1, + '1,23':1, + '26,23':1 + } + }, + { //第2关 + 'map':[ //地图数据 + [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,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1], + [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], + [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], + [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], + [1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1], + [1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1], + [1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,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1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], + [1,0,1,1,1,1,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,1,1,1,1,0,1], + [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], + [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], + [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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] + ], + 'wall_color':'#FF5983', + 'goods':{ //能量豆 + '1,2':1, + '26,2':1, + '1,27':1, + '26,27':1 + } + }, + { //第3关 + 'map':[ //地图数据 + [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,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1], + [1,0,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,0,1], + [1,0,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,0,1], + [1,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,1], + [1,0,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,0,1], + [1,0,0,0,0,1,1,0,1,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,0,0,0,1], + [1,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,1,1], + [1,1,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,1], + [0,0,0,0,0,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,0,0,0,0,0], + [1,0,1,1,0,1,1,1,1,0,1,1,1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,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], + [1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,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] + ], + 'wall_color':'#E08031', + 'goods':{ //能量豆 + '1,2':1, + '26,2':1, + '1,23':1, + '26,23':1 + } + }, + { //第4关 + 'map':[ //地图数据 + [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,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1], + [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], + [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], + [1,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,1], + [1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1], + [1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1], + [0,0,0,0,0,0,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,0,0], + [1,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,1,1,0,1,1,0,1,1,0,1,1,1], + [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], + [1,0,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,0,0,1], + [1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1], + [1,0,1,1,1,1,0,1,1,0,1,1,1,2,2,1,1,1,0,1,1,0,1,1,1,1,0,1], + [1,0,0,0,0,0,0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,1,1] + ], + 'wall_color':'#37C6C0', + 'goods':{ //能量豆 + '1,3':1, + '26,3':1, + '1,28':1, + '26,28':1 + } + }, + ]; + _COLOR = ['#F00','#F93','#0CF','#F9C'], //NPC颜色 _COS = [1,0,-1,0], _SIN = [0,1,0,-1], - _COLOR = ['#F00','#F93','#0CF','#F9C'],//红,橙, - _LIFE = 3, - _SCORE = 0; //得分 + _LIFE = 5, //玩家生命值 + _SCORE = 0; //玩家得分 var game = new Game('canvas'); //启动页 @@ -107,410 +238,431 @@ })(); //游戏主程序 (function(){ - var stage,map,beans,player,times; - stage = game.createStage({ - update:function(){ - var stage = this; - if(stage.status==1){ //场景正常运行 - items.forEach(function(item){ - if(map&&!map.get(item.coord.x,item.coord.y)&&!map.get(player.coord.x,player.coord.y)){ - var dx = item.x-player.x; - var dy = item.y-player.y; - if(dx*dx+dy*dy<750&&item.status!=4){ //物体检测 - if(item.status==3){ - item.status = 4; - _SCORE += 10; - }else{ - stage.status = 3; - stage.timeout = 30; + _COIGIG.forEach(function(config,index){ + var stage,map,beans,items,player,times; + stage = game.createStage({ + update:function(){ + var stage = this; + if(stage.status==1){ //场景正常运行 + items.forEach(function(item){ + if(map&&!map.get(item.coord.x,item.coord.y)&&!map.get(player.coord.x,player.coord.y)){ + var dx = item.x-player.x; + var dy = item.y-player.y; + if(dx*dx+dy*dy<750&&item.status!=4){ //物体检测 + if(item.status==3){ + item.status = 4; + _SCORE += 10; + }else{ + stage.status = 3; + stage.timeout = 30; + } } } + }); + if(JSON.stringify(beans.data).indexOf(0)<0){ //当没有物品的时候,进入下一关 + setTimeout(function(){ + game.nextStage(); + },1500); } - }); - if(JSON.stringify(beans.data).indexOf(0)<0){ //当没有物品的时候,进入结束画面 - game.nextStage(); - } - }else if(stage.status==3){ //场景临时状态 - if(!stage.timeout){ - _LIFE--; - if(_LIFE){ - stage.resetItems(); - }else{ - game.nextStage(); - return false; - } - } - } - } - }); - //绘制地图 - map = stage.createMap({ - x:60, - y:10, - data:_DATA, - cache:true, - draw:function(context){ - context.lineWidth = 2; - for(var j=0; j-1){ - context.strokeStyle=value==2?"#FFF":"#09C"; - var pos = this.coord2position(i,j); - switch(code.join('')){ - case '1100': - context.beginPath(); - context.arc(pos.x+this.size/2,pos.y+this.size/2,this.size/2,Math.PI,1.5*Math.PI,false); - context.stroke(); - context.closePath(); - break; - case '0110': - context.beginPath(); - context.arc(pos.x-this.size/2,pos.y+this.size/2,this.size/2,1.5*Math.PI,2*Math.PI,false); - context.stroke(); - context.closePath(); - break; - case '0011': - context.beginPath(); - context.arc(pos.x-this.size/2,pos.y-this.size/2,this.size/2,0,.5*Math.PI,false); - context.stroke(); - context.closePath(); - break; - case '1001': - context.beginPath(); - context.arc(pos.x+this.size/2,pos.y-this.size/2,this.size/2,.5*Math.PI,1*Math.PI,false); - context.stroke(); - context.closePath(); - break; - default: - var dist = this.size/2; - code.forEach(function(v,index){ - if(v){ - context.beginPath(); - context.moveTo(pos.x,pos.y); - context.lineTo(pos.x-_COS[index]*dist,pos.y-_SIN[index]*dist); - context.stroke(); - context.closePath(); - } - }); - } - } - } - } - } - } - }); - //物品地图 - beans = stage.createMap({ - x:60, - y:10, - data:_DATA, - frames:8, - draw:function(context){ - for(var j=0; j-1){ + context.strokeStyle=value==2?"#FFF":config['wall_color']; + var pos = this.coord2position(i,j); + switch(code.join('')){ + case '1100': + context.beginPath(); + context.arc(pos.x+this.size/2,pos.y+this.size/2,this.size/2,Math.PI,1.5*Math.PI,false); + context.stroke(); + context.closePath(); + break; + case '0110': + context.beginPath(); + context.arc(pos.x-this.size/2,pos.y+this.size/2,this.size/2,1.5*Math.PI,2*Math.PI,false); + context.stroke(); + context.closePath(); + break; + case '0011': + context.beginPath(); + context.arc(pos.x-this.size/2,pos.y-this.size/2,this.size/2,0,.5*Math.PI,false); + context.stroke(); + context.closePath(); + break; + case '1001': + context.beginPath(); + context.arc(pos.x+this.size/2,pos.y-this.size/2,this.size/2,.5*Math.PI,1*Math.PI,false); + context.stroke(); + context.closePath(); + break; + default: + var dist = this.size/2; + code.forEach(function(v,index){ + if(v){ + context.beginPath(); + context.moveTo(pos.x,pos.y); + context.lineTo(pos.x-_COS[index]*dist,pos.y-_SIN[index]*dist); + context.stroke(); + context.closePath(); + } + }); + } + } + } + } + } } - } - }); - //生命值 - stage.createItem({ - x:705, - y:540, - width:30, - height:30, - draw:function(context){ - for(var i=0;i<_LIFE-1;i++){ - var x=this.x+40*i,y=this.y; - context.fillStyle = '#FFE600'; - context.beginPath(); - context.arc(x,y,this.width/2,.15*Math.PI,-.15*Math.PI,false); - context.lineTo(x,y); - context.closePath(); - context.fill(); + }); + //物品地图 + beans = stage.createMap({ + x:60, + y:10, + data:config['map'], + frames:8, + draw:function(context){ + for(var j=0; jthis.coord.x){ + this.orientation = 0; + }else if(this.vector.xthis.coord.y){ + this.orientation = 1; + }else if(this.vector.ythis.coord.x){ - this.orientation = 0; - }else if(this.vector.xthis.coord.y){ - this.orientation = 1; - }else if(this.vector.y80||this.times%2?true:false; - } - if(this.status!=4){ - context.fillStyle = isSick?'#BABABA':this.color; - context.beginPath(); - context.arc(this.x,this.y,this.width*.5,0,Math.PI,true); - switch(this.times%2){ - case 0: - context.lineTo(this.x-this.width*.5,this.y+this.height*.4); - context.quadraticCurveTo(this.x-this.width*.4,this.y+this.height*.5,this.x-this.width*.2,this.y+this.height*.3); - context.quadraticCurveTo(this.x,this.y+this.height*.5,this.x+this.width*.2,this.y+this.height*.3); - context.quadraticCurveTo(this.x+this.width*.4,this.y+this.height*.5,this.x+this.width*.5,this.y+this.height*.4); - break; - case 1: - context.lineTo(this.x-this.width*.5,this.y+this.height*.3); - context.quadraticCurveTo(this.x-this.width*.25,this.y+this.height*.5,this.x,this.y+this.height*.3); - context.quadraticCurveTo(this.x+this.width*.25,this.y+this.height*.5,this.x+this.width*.5,this.y+this.height*.3); - break; - } - context.fill(); - context.closePath(); - } - context.fillStyle = '#FFF'; - if(isSick){ - context.beginPath(); - context.arc(this.x-this.width*.15,this.y-this.height*.21,this.width*.08,0,2*Math.PI,false); - context.arc(this.x+this.width*.15,this.y-this.height*.21,this.width*.08,0,2*Math.PI,false); - context.fill(); - context.closePath(); - }else{ - context.beginPath(); - context.arc(this.x-this.width*.15,this.y-this.height*.21,this.width*.12,0,2*Math.PI,false); - context.arc(this.x+this.width*.15,this.y-this.height*.21,this.width*.12,0,2*Math.PI,false); - context.fill(); - context.closePath(); - context.fillStyle = '#000'; - context.beginPath(); - context.arc(this.x-this.width*(.15-.04*_COS[this.orientation]),this.y-this.height*(.21-.04*_SIN[this.orientation]),this.width*.07,0,2*Math.PI,false); - context.arc(this.x+this.width*(.15+.04*_COS[this.orientation]),this.y-this.height*(.21-.04*_SIN[this.orientation]),this.width*.07,0,2*Math.PI,false); - context.fill(); - context.closePath(); - } - } - }); - } - items = stage.getItemsByType(2); - //主角 - player = stage.createItem({ - width:30, - height:30, - type:1, - location:map, - coord:{x:13.5,y:23}, - orientation:2, - speed:2, - frames:10, - update:function(){ - var coord = this.coord; - if(!coord.offset){ - if(this.control.orientation!='undefined'){ - if(!map.get(coord.x+_COS[this.control.orientation],coord.y+_SIN[this.control.orientation])){ - this.orientation = this.control.orientation; - } - } - this.control = {}; - var value = map.get(coord.x+_COS[this.orientation],coord.y+_SIN[this.orientation]); - if(value==0){ this.x += this.speed*_COS[this.orientation]; this.y += this.speed*_SIN[this.orientation]; - }else if(value<0){ - this.x -= map.size*(map.x_length-1)*_COS[this.orientation]; - this.y -= map.size*(map.y_length-1)*_SIN[this.orientation]; - } - }else{ - if(!beans.get(this.coord.x,this.coord.y)){ //吃豆 - _SCORE++; - beans.set(this.coord.x,this.coord.y,1); - if(_GOODS[this.coord.x+','+this.coord.y]){ //吃到能量豆 - items.forEach(function(item){ - if(item.status==1||item.status==3){ //如果NPC为正常状态,则置为临时状态 - item.timeout = 450; - item.status = 3; - } - }); + }, + draw:function(context){ + var isSick = false; + if(this.status==3){ + isSick = this.timeout>80||this.times%2?true:false; + } + if(this.status!=4){ + context.fillStyle = isSick?'#BABABA':this.color; + context.beginPath(); + context.arc(this.x,this.y,this.width*.5,0,Math.PI,true); + switch(this.times%2){ + case 0: + context.lineTo(this.x-this.width*.5,this.y+this.height*.4); + context.quadraticCurveTo(this.x-this.width*.4,this.y+this.height*.5,this.x-this.width*.2,this.y+this.height*.3); + context.quadraticCurveTo(this.x,this.y+this.height*.5,this.x+this.width*.2,this.y+this.height*.3); + context.quadraticCurveTo(this.x+this.width*.4,this.y+this.height*.5,this.x+this.width*.5,this.y+this.height*.4); + break; + case 1: + context.lineTo(this.x-this.width*.5,this.y+this.height*.3); + context.quadraticCurveTo(this.x-this.width*.25,this.y+this.height*.5,this.x,this.y+this.height*.3); + context.quadraticCurveTo(this.x+this.width*.25,this.y+this.height*.5,this.x+this.width*.5,this.y+this.height*.3); + break; + } + context.fill(); + context.closePath(); + } + context.fillStyle = '#FFF'; + if(isSick){ + context.beginPath(); + context.arc(this.x-this.width*.15,this.y-this.height*.21,this.width*.08,0,2*Math.PI,false); + context.arc(this.x+this.width*.15,this.y-this.height*.21,this.width*.08,0,2*Math.PI,false); + context.fill(); + context.closePath(); + }else{ + context.beginPath(); + context.arc(this.x-this.width*.15,this.y-this.height*.21,this.width*.12,0,2*Math.PI,false); + context.arc(this.x+this.width*.15,this.y-this.height*.21,this.width*.12,0,2*Math.PI,false); + context.fill(); + context.closePath(); + context.fillStyle = '#000'; + context.beginPath(); + context.arc(this.x-this.width*(.15-.04*_COS[this.orientation]),this.y-this.height*(.21-.04*_SIN[this.orientation]),this.width*.07,0,2*Math.PI,false); + context.arc(this.x+this.width*(.15+.04*_COS[this.orientation]),this.y-this.height*(.21-.04*_SIN[this.orientation]),this.width*.07,0,2*Math.PI,false); + context.fill(); + context.closePath(); } } - this.x += this.speed*_COS[this.orientation]; - this.y += this.speed*_SIN[this.orientation]; - } - }, - draw:function(context){ - context.fillStyle = '#FFE600'; - context.beginPath(); - if(stage.status!=3){ //玩家正常状态 - if(this.times%2){ - context.arc(this.x,this.y,this.width/2,(.5*this.orientation+.20)*Math.PI,(.5*this.orientation-.20)*Math.PI,false); + }); + } + items = stage.getItemsByType(2); + //主角 + player = stage.createItem({ + width:30, + height:30, + type:1, + location:map, + coord:{x:13.5,y:23}, + orientation:2, + speed:2, + frames:10, + update:function(){ + var coord = this.coord; + if(!coord.offset){ + if(this.control.orientation!='undefined'){ + if(!map.get(coord.x+_COS[this.control.orientation],coord.y+_SIN[this.control.orientation])){ + this.orientation = this.control.orientation; + } + } + this.control = {}; + var value = map.get(coord.x+_COS[this.orientation],coord.y+_SIN[this.orientation]); + if(value==0){ + this.x += this.speed*_COS[this.orientation]; + this.y += this.speed*_SIN[this.orientation]; + }else if(value<0){ + this.x -= map.size*(map.x_length-1)*_COS[this.orientation]; + this.y -= map.size*(map.y_length-1)*_SIN[this.orientation]; + } }else{ - context.arc(this.x,this.y,this.width/2,(.5*this.orientation+.01)*Math.PI,(.5*this.orientation-.01)*Math.PI,false); + if(!beans.get(this.coord.x,this.coord.y)){ //吃豆 + _SCORE++; + beans.set(this.coord.x,this.coord.y,1); + if(config['goods'][this.coord.x+','+this.coord.y]){ //吃到能量豆 + items.forEach(function(item){ + if(item.status==1||item.status==3){ //如果NPC为正常状态,则置为临时状态 + item.timeout = 450; + item.status = 3; + } + }); + } + } + this.x += this.speed*_COS[this.orientation]; + this.y += this.speed*_SIN[this.orientation]; } - }else{ //玩家被吃 - if(stage.timeout) { - context.arc(this.x,this.y,this.width/2,(.5*this.orientation+1-.02*stage.timeout)*Math.PI,(.5*this.orientation-1+.02*stage.timeout)*Math.PI,false); + }, + draw:function(context){ + context.fillStyle = '#FFE600'; + context.beginPath(); + if(stage.status!=3){ //玩家正常状态 + if(this.times%2){ + context.arc(this.x,this.y,this.width/2,(.5*this.orientation+.20)*Math.PI,(.5*this.orientation-.20)*Math.PI,false); + }else{ + context.arc(this.x,this.y,this.width/2,(.5*this.orientation+.01)*Math.PI,(.5*this.orientation-.01)*Math.PI,false); + } + }else{ //玩家被吃 + if(stage.timeout) { + context.arc(this.x,this.y,this.width/2,(.5*this.orientation+1-.02*stage.timeout)*Math.PI,(.5*this.orientation-1+.02*stage.timeout)*Math.PI,false); + } } + context.lineTo(this.x,this.y); + context.closePath(); + context.fill(); } - context.lineTo(this.x,this.y); - context.closePath(); - context.fill(); - } - }); - //事件绑定 - stage.bind('keydown',function(e){ - 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; - } + }); + //事件绑定 + stage.bind('keydown',function(e){ + 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; + } + }); }); })(); //结束画面 @@ -525,7 +677,7 @@ context.font = 'bold 48px Helvetica'; context.textAlign = 'center'; context.textBaseline = 'middle'; - context.fillText('GAME OVER',this.x,this.y); + context.fillText(_LIFE?'YOU WIN!':'GAME OVER',this.x,this.y); } }); //记分 @@ -546,7 +698,7 @@ case 13: //回车 case 32: //空格 _SCORE = 0; - _LIFE = 3; + _LIFE = 5; var st = game.setStage(1); st.reset(); break;