updated 添加地图穿越效果
This commit is contained in:
		
							parent
							
								
									2b8b237a56
								
							
						
					
					
						commit
						f01db8304a
					
				
							
								
								
									
										6
									
								
								game.js
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								game.js
									
									
									
									
									
								
							@ -69,6 +69,9 @@ function Game(id,options){
 | 
				
			|||||||
			y:0,		
 | 
								y:0,		
 | 
				
			||||||
			size:20,					//地图单元的宽度
 | 
								size:20,					//地图单元的宽度
 | 
				
			||||||
			data:[],					//地图数据
 | 
								data:[],					//地图数据
 | 
				
			||||||
 | 
								stage:null,					//布景
 | 
				
			||||||
 | 
								x_length:0,					//二维数组x轴长度
 | 
				
			||||||
 | 
								y_length:0,					//二维数组y轴长度
 | 
				
			||||||
			update:function(){},		//更新地图数据
 | 
								update:function(){},		//更新地图数据
 | 
				
			||||||
			draw:function(){},			//绘制地图
 | 
								draw:function(){},			//绘制地图
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
@ -159,8 +162,11 @@ function Game(id,options){
 | 
				
			|||||||
	//添加地图
 | 
						//添加地图
 | 
				
			||||||
	Stage.prototype.createMap = function(options){
 | 
						Stage.prototype.createMap = function(options){
 | 
				
			||||||
		var map = new Map(options);
 | 
							var map = new Map(options);
 | 
				
			||||||
 | 
							//动态属性
 | 
				
			||||||
		this.map = map;
 | 
							this.map = map;
 | 
				
			||||||
		map.stage = this;
 | 
							map.stage = this;
 | 
				
			||||||
 | 
							map.y_length = map.data.length;
 | 
				
			||||||
 | 
							map.x_length = map.data[0].length;
 | 
				
			||||||
		return map;
 | 
							return map;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	//绑定事件
 | 
						//绑定事件
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										79
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										79
									
								
								index.js
									
									
									
									
									
								
							@ -121,8 +121,8 @@
 | 
				
			|||||||
			draw:function(context){
 | 
								draw:function(context){
 | 
				
			||||||
				var y_length = this.data.length;
 | 
									var y_length = this.data.length;
 | 
				
			||||||
				var x_length = this.data[0].length;
 | 
									var x_length = this.data[0].length;
 | 
				
			||||||
				for(var j=0; j<y_length; j++){
 | 
									for(var j=0; j<this.y_length; j++){
 | 
				
			||||||
					for(var i=0; i<x_length; i++){
 | 
										for(var i=0; i<this.x_length; i++){
 | 
				
			||||||
						context.lineWidth = 2;
 | 
											context.lineWidth = 2;
 | 
				
			||||||
						context.strokeStyle="#09C";
 | 
											context.strokeStyle="#09C";
 | 
				
			||||||
						if(this.get(i,j)){
 | 
											if(this.get(i,j)){
 | 
				
			||||||
@ -222,8 +222,8 @@
 | 
				
			|||||||
			speed:10,
 | 
								speed:10,
 | 
				
			||||||
			update:function(){
 | 
								update:function(){
 | 
				
			||||||
				var coord = map.position2coord(this.x,this.y);
 | 
									var coord = map.position2coord(this.x,this.y);
 | 
				
			||||||
				var inPlace = !coord.offset;
 | 
									var steps = 2;
 | 
				
			||||||
				if(inPlace){
 | 
									if(!coord.offset){
 | 
				
			||||||
					if(typeof this.control.orientation!='undefined'){
 | 
										if(typeof this.control.orientation!='undefined'){
 | 
				
			||||||
						switch(this.control.orientation){
 | 
											switch(this.control.orientation){
 | 
				
			||||||
							case 0:
 | 
												case 0:
 | 
				
			||||||
@ -249,28 +249,55 @@
 | 
				
			|||||||
						}						
 | 
											}						
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					this.control = {};
 | 
										this.control = {};
 | 
				
			||||||
				}
 | 
										switch(this.orientation){
 | 
				
			||||||
				switch(this.orientation){
 | 
											case 0:
 | 
				
			||||||
					case 0:
 | 
												var value = map.get(coord.x,coord.y-1);
 | 
				
			||||||
						if(!(map.get(coord.x,coord.y-1)&&inPlace)){
 | 
												if(value==0){
 | 
				
			||||||
							this.y-=1;
 | 
													this.y-=steps;
 | 
				
			||||||
						}
 | 
												}else if(value<0){
 | 
				
			||||||
						break;
 | 
													this.y += map.size*(map.y_length-1);
 | 
				
			||||||
					case 1:
 | 
												}
 | 
				
			||||||
						if(!(map.get(coord.x+1,coord.y)&&inPlace)){
 | 
												break;
 | 
				
			||||||
							this.x+=1;
 | 
											case 1:
 | 
				
			||||||
						}
 | 
												var value = map.get(coord.x+1,coord.y);
 | 
				
			||||||
						break;
 | 
												if(value==0){
 | 
				
			||||||
					case 2:
 | 
													this.x+=steps;
 | 
				
			||||||
						if(!(map.get(coord.x,coord.y+1)&&inPlace)){
 | 
												}else if(value<0){
 | 
				
			||||||
							this.y+=1;
 | 
													this.x -= map.size*(map.x_length-1);
 | 
				
			||||||
						}
 | 
												}
 | 
				
			||||||
						break;
 | 
												break;
 | 
				
			||||||
					case 3:
 | 
											case 2:
 | 
				
			||||||
						if(!(map.get(coord.x-1,coord.y)&&inPlace)){
 | 
												var value = map.get(coord.x,coord.y+1);
 | 
				
			||||||
							this.x-=1;
 | 
												if(value==0){
 | 
				
			||||||
						}
 | 
													this.y+=steps;
 | 
				
			||||||
						break;
 | 
												}else if(value<0){
 | 
				
			||||||
 | 
													this.y -= map.size*(map.y_length-1);
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
 | 
												break;
 | 
				
			||||||
 | 
											case 3:
 | 
				
			||||||
 | 
												var value = map.get(coord.x-1,coord.y);
 | 
				
			||||||
 | 
												if(value==0){
 | 
				
			||||||
 | 
													this.x-=steps;
 | 
				
			||||||
 | 
												}else if(value<0){
 | 
				
			||||||
 | 
													this.x += map.size*(map.x_length-1);
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
 | 
												break;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}else{
 | 
				
			||||||
 | 
										switch(this.orientation){
 | 
				
			||||||
 | 
											case 0:
 | 
				
			||||||
 | 
													this.y-=steps;
 | 
				
			||||||
 | 
												break;
 | 
				
			||||||
 | 
											case 1:
 | 
				
			||||||
 | 
													this.x+=steps;
 | 
				
			||||||
 | 
												break;
 | 
				
			||||||
 | 
											case 2:
 | 
				
			||||||
 | 
													this.y+=steps;
 | 
				
			||||||
 | 
												break;
 | 
				
			||||||
 | 
											case 3:
 | 
				
			||||||
 | 
													this.x-=steps;
 | 
				
			||||||
 | 
												break;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			draw:function(context){
 | 
								draw:function(context){
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user