暂停状态修改,及死亡动画添加
This commit is contained in:
		
							parent
							
								
									e3c2d5c269
								
							
						
					
					
						commit
						7941696e44
					
				
							
								
								
									
										12
									
								
								game.js
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								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:[],						//图片资源
 | 
			
		||||
@ -212,10 +213,13 @@ 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;		//计数器
 | 
			
		||||
						if(item.timeout){
 | 
			
		||||
							item.timeout--;
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
					if(stage.status==1&&item.status==1){  	//对象及布景状态都处于正常状态下
 | 
			
		||||
						if(item.location){
 | 
			
		||||
							item.coord = item.location.position2coord(item.x,item.y);
 | 
			
		||||
						}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								index.js
									
									
									
									
									
								
							@ -105,16 +105,21 @@
 | 
			
		||||
		var stage = game.createStage({
 | 
			
		||||
			update:function(){
 | 
			
		||||
				var stage = this;
 | 
			
		||||
				var player = this.getItemsByType(1)[0];
 | 
			
		||||
				var items = this.getItemsByType(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;
 | 
			
		||||
						}
 | 
			
		||||
					});
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
		//绘制地图
 | 
			
		||||
		var map = stage.createMap({
 | 
			
		||||
@ -249,11 +254,17 @@
 | 
			
		||||
			draw:function(context){
 | 
			
		||||
				context.fillStyle = '#FC3';
 | 
			
		||||
				context.beginPath();
 | 
			
		||||
				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{
 | 
			
		||||
					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();
 | 
			
		||||
				context.fill();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user