From b19b3c04a8b96fcf19d5c95ae7b1205259e9548a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B5=A9=E4=B9=90?= Date: Mon, 11 Jan 2016 22:34:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=9F=E5=91=BD=E5=80=BC?= =?UTF-8?q?=E8=AE=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 2 +- index.js | 30 +++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/game.js b/game.js index a913b63..803c821 100644 --- a/game.js +++ b/game.js @@ -186,7 +186,7 @@ function Game(id,params){ var Stage = function(params){ this._params = params||{}; this._settings = { - status:1, //布景状态,0表示未激活,1表示正常,2表示暂停,3表示结束 + status:1, //布景状态,0表示未激活,1表示正常,2表示暂停,3表示中断或异常,4表示结束 maps:[], //地图队列 audio:[], //音频资源 images:[], //图片资源 diff --git a/index.js b/index.js index a4f90de..fb407b8 100644 --- a/index.js +++ b/index.js @@ -36,6 +36,7 @@ _COS = [1,0,-1,0], _SIN = [0,1,0,-1], _COLOR = ['#F00','#F60','#3C6','#69F'], + _LIFE = 3, _SCORE = 0; //得分 var game = new Game('canvas'); @@ -116,8 +117,9 @@ stage.timeout = 30; } }); - }else if(stage.status=3){ + }else if(stage.status==3){ if(!stage.timeout){ + _LIFE&&_LIFE--; stage.reset(); } } @@ -125,7 +127,7 @@ }); //绘制地图 var map = stage.createMap({ - x:50, + x:60, y:10, data:JSON.parse(JSON.stringify(_DATA)), draw:function(context){ @@ -221,7 +223,7 @@ } }); var goods = stage.createMap({ - x:50, + x:60, y:10, data:JSON.parse(JSON.stringify(_DATA)), draw:function(context){ @@ -238,8 +240,8 @@ }); //得分 stage.createItem({ - x:680, - y:84, + x:690, + y:120, draw:function(context){ context.font = 'bold 28px Helvetica'; context.textAlign = 'left'; @@ -253,6 +255,24 @@ context.fillText(_SCORE,this.x+12,this.y); } }); + //生命值 + stage.createItem({ + x:705, + y:520, + width:30, + height:30, + draw:function(context){ + for(var i=0;i<_LIFE;i++){ + var x=this.x+36*i,y=this.y; + context.fillStyle = '#FC3'; + context.beginPath(); + context.arc(x,y,this.width/2,.15*Math.PI,-.15*Math.PI,false); + context.lineTo(x,y); + context.closePath(); + context.fill(); + } + } + }); //主角 var player = stage.createItem({ width:30,