From 7941696e4443a28552bf5fe55622037bd8fe3b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B5=A9=E4=B9=90?= Date: Sun, 10 Jan 2016 22:16:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=81=9C=E7=8A=B6=E6=80=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=EF=BC=8C=E5=8F=8A=E6=AD=BB=E4=BA=A1=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 18 +++++++++++------- index.js | 35 +++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/game.js b/game.js index 7595950..10e01d6 100644 --- a/game.js +++ b/game.js @@ -30,7 +30,7 @@ function Game(id,options){ height:20, //高 type:0, //对象类型,0表示普通对象(不与地图绑定),1表示玩家控制对象,2表示程序控制对象 color:'#F00', //标识颜色 - status:1, //对象状态,1表示正常,0表示隐藏,2表示暂停 + status:1, //对象状态,0表示隐藏,1表示正常,2表示暂停 orientation:0, //当前定位方向,0表示右,1表示下,2表示左,3表示上 speed:0, //移动速度 //地图相关 @@ -42,7 +42,8 @@ function Game(id,options){ stage:null, //绑定对象与所属布景绑定 index:0, //对象索引 frames:1, //速度等级,内部计算器times多少帧变化一次 - times:0, //计数 + times:0, //刷新画布计数(用于循环动画状态判断) + timeout:0, //倒计时(用于过程动画状态判断) control:{}, //控制缓存,到达定位点时处理 update:function(){}, //更新参数信息 draw:function(){} //绘制 @@ -184,7 +185,7 @@ function Game(id,options){ var Stage = function(options){ options = options||{}; var settings = { - status:1, //布景状态,1表示正常,0表示非活动 + status:1, //布景状态,0表示未激活,1表示正常,2表示暂停,3表示结束 maps:[], //地图队列 audio:[], //音频资源 images:[], //图片资源 @@ -211,11 +212,14 @@ function Game(id,options){ }); } if(stage.items.length){ - stage.items.forEach(function(item,index){ - if(stage.status!=2&&item.status!=2){ //对象及布景状态不为暂停 - if(!(f%item.frames)){ - item.times = f/item.frames; //计数器 + stage.items.forEach(function(item,index){ + if(!(f%item.frames)){ + item.times = f/item.frames; //计数器 + if(item.timeout){ + item.timeout--; } + } + if(stage.status==1&&item.status==1){ //对象及布景状态都处于正常状态下 if(item.location){ item.coord = item.location.position2coord(item.x,item.y); } diff --git a/index.js b/index.js index f991872..eb71222 100644 --- a/index.js +++ b/index.js @@ -105,15 +105,20 @@ var stage = game.createStage({ update:function(){ var stage = this; - var player = this.getItemsByType(1)[0]; - var items = this.getItemsByType(2); - items.forEach(function(item){ - var dx = item.x-player.x; - var dy = item.y-player.y; - if(dx*dx+dy*dy<750){ - stage.status = 2; - } - }); + if(stage.status==1){ + var player = stage.getItemsByType(1)[0]; + var items = stage.getItemsByType(2); + items.forEach(function(item){ + var dx = item.x-player.x; + var dy = item.y-player.y; + if(dx*dx+dy*dy<750){ + stage.status = 2; + player.status = 3; + player.frames = 1; + player.timeout = 50; + } + }); + } } }); //绘制地图 @@ -249,10 +254,16 @@ draw:function(context){ context.fillStyle = '#FC3'; context.beginPath(); - 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); + if(this.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{ - context.arc(this.x,this.y,this.width/2,(.5*this.orientation+.01)*Math.PI,(.5*this.orientation-.01)*Math.PI,false); + if(this.timeout) { + context.arc(this.x,this.y,this.width/2,(.5*this.orientation+1-.02*this.timeout)*Math.PI,(.5*this.orientation-1+.02*this.timeout)*Math.PI,false); + } } context.lineTo(this.x,this.y); context.closePath();