Flash AS 3 熊猫推箱子源程序

阅读更多


Flash AS 3 熊猫推箱子源程序_第1张图片
 Flash AS 3 熊猫推箱子源程序

 

今天忽然找到以前做给心爱的人的推箱子游戏,呵呵,发给大家玩玩,素材除了熊猫是自己做图画的(可能与网上某些熊猫有些相似,),其他素材都是网上搜集的.

 

全代码:(因为是很久以前做的,没有注释)

 

stop();
var xiongmao1_x:int;
var xiongmao1_y:int;
var mao_b1:int;
var mao_a1:int;
var boxIndexs:Array=new Array();
var boxList:Array = new Array();
var zhongdian_x:int;
var zhongdian_y:int;
boxList[0] = new Array();
boxList[0][0] = new Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2);
boxList[0][1] = new Array(2, 2, 4, 4, 4, 4, 4, 4, 4, 2, 2);
boxList[0][2] = new Array(2, 2, 4, 0, 6, 5, 5, 5, 4, 2, 2);
boxList[0][3] = new Array(2, 2, 4, 0, 0, 0, 4, 4, 4, 4, 2);
boxList[0][4] = new Array(2, 4, 4, 4, 3, 0, 0, 0, 0, 4, 2);
boxList[0][5] = new Array(2, 4, 0, 0, 0, 4, 3, 4, 0, 4, 2);
boxList[0][6] = new Array(2, 4, 0, 3, 0, 4, 0, 0, 0, 4, 2);
boxList[0][7] = new Array(2, 4, 0, 0, 0, 4, 4, 4, 4, 4, 2);
boxList[0][8] = new Array(2, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2);
boxList[0][9] = new Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2);


for (var i:int=0; i<20; i++) {
	for (var j:int=0; j<15; j++) {

		var diban1:diban=new diban();
		diban1.width=35;
		diban1.height=35;
		diban1.x=i*36+0;
		diban1.y=j*36+0;
		this.addChild(diban1);

	}
}

for (var a:int=0; a<10; a++) {
	for (var b:int=0; b<12; b++) {



		var face1:int=boxList[0][a][b];
		var thisM1:yuanjian=new yuanjian();
		thisM1.gotoAndStop(face1);
		thisM1.x=b*36+72;
		thisM1.y=a*36+36;

		//var r:uint=Math.floor(Math.random()*boxList.length);
		//thisM1.cardface=boxList[r];
		//boxList.splice(r,1);
		//thisM1.gotoAndStop(thisM1.cardface+2);
		this.addChild(thisM1);
		if (boxList[0][a][b]==3) {

			boxIndexs.push(this.getChildIndex(thisM1));
			//trace(this.getChildIndex(thisM1));

		}
		if (boxList[0][a][b]==6) {
			setXiongmao(b,a);

			//var xiongmao1:xiongmao=new xiongmao();
			//
			//                        this.addChild(xiongmao1);
			//                        xiongmao1.scaleX =0.25;
			//                        xiongmao1.scaleY =0.20;
			//xiongmao1.x=b*36+72;
			//xiongmao1.y=a*36+36;
		}
		if (boxList[0][a][b]==5) {
			zhongdian_x=b;
			zhongdian_y=a;


		}
		//cardsLeft++;

	}
}
function setXiongmao(x1:int,y1:int):void {
	mao_b1=x1;
	mao_a1=y1;
	xiongmao1_x=x1*36+72;
	xiongmao1_y=y1*36+36;



}

var xiongmao1:xiongmao=new xiongmao();

this.addChild(xiongmao1);
xiongmao1.scaleX =0.25;
xiongmao1.scaleY =0.20;

xiongmao1.x=xiongmao1_x;
xiongmao1.y=xiongmao1_y;

stage.addEventListener(KeyboardEvent.KEY_UP, iskeyDown);

function iskeyDown(event:KeyboardEvent):void {

	/* 
	if(xiongmao1.hitTestObject(thisM1))
	{
	trace("hit");
	xiongmao1.x=xiongmao1_x;
	xiongmao1.y=xiongmao1_y;
	}*/
	/*else
	{*/
	switch (event.keyCode) {
		case 37 :
			//this.getChildAt(boxIndexs[0]).x-=36; 

			//trace(boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36-1]);

			if (boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36-1]==0||boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36-1]==5) {
				//如果熊猫的左边为0,或者左边为5,则左移36;




				boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36]=0;
				boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36-1]=6;
				xiongmao1.x-=36;
			} else if (boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36-2]==0&&boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36-1]==3) {
				//如果熊猫的左边为3(箱子存在),同时熊猫左边第二格为空,则熊猫左移36,箱子也左移36;

				boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36]=0;
				//boxList[0][(xiongmao1.y-36)/36+1][(xiongmao1.x-72)/36]=6;
				xiongmao1.x-=36;

				for (var boxIndex4:int=0; boxIndex4<3; boxIndex4++) {
					/*trace(xiongmao1.y);
					trace(this.getChildAt(boxIndexs[boxIndex]).y+36);*/
					/*trace(xiongmao1.x);
					trace(this.getChildAt(boxIndexs[boxIndex]).x);*/
					if (this.getChildAt(boxIndexs[boxIndex4]).x==xiongmao1.x&&this.getChildAt(boxIndexs[boxIndex4]).y==xiongmao1.y) {
						this.getChildAt(boxIndexs[boxIndex4]).x-=36;
						boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36]=6;
						boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36-1]=3;

					}
				}
			}
			break;

		case 38 :
			//trace(boxList[0][mao_a1][mao_b1]);
			if (boxList[0][(xiongmao1.y-36)/36-1][(xiongmao1.x-72)/36]==0||boxList[0][(xiongmao1.y-36)/36-1][(xiongmao1.x-72)/36]==5) {
				boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36]=0;
				boxList[0][(xiongmao1.y-36)/36-1][(xiongmao1.x-72)/36]=6;
				xiongmao1.y-=36;
			} else if (boxList[0][(xiongmao1.y-36)/36-2][(xiongmao1.x-72)/36]==0&&boxList[0][(xiongmao1.y-36)/36-1][(xiongmao1.x-72)/36]==3) {

				boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36]=0;
				//boxList[0][(xiongmao1.y-36)/36+1][(xiongmao1.x-72)/36]=6;
				xiongmao1.y-=36;

				for (var boxIndex3:int=0; boxIndex3<3; boxIndex3++) {
					/*trace(xiongmao1.y);
					trace(this.getChildAt(boxIndexs[boxIndex]).y+36);*/
					/*trace(xiongmao1.x);
					trace(this.getChildAt(boxIndexs[boxIndex]).x);*/
					if (this.getChildAt(boxIndexs[boxIndex3]).x==xiongmao1.x&&this.getChildAt(boxIndexs[boxIndex3]).y==xiongmao1.y) {
						this.getChildAt(boxIndexs[boxIndex3]).y-=36;
						boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36]=6;
						boxList[0][(xiongmao1.y-36)/36-1][(xiongmao1.x-72)/36]=3;


					}
				}
			}
			break;
		case 39 :

			//trace(boxList[0][mao_a1][mao_b1-1]);
			if (boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36+1]==0||boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36+1]==5) {

				boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36]=0;
				boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36+1]=6;
				xiongmao1.x+=36;
			} else if (boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36+2]==0&&boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36+1]==3) {

				boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36]=0;
				//boxList[0][(xiongmao1.y-36)/36+1][(xiongmao1.x-72)/36]=6;
				xiongmao1.x+=36;

				for (var boxIndex:int=0; boxIndex<3; boxIndex++) {
					/*trace(xiongmao1.y);
					trace(this.getChildAt(boxIndexs[boxIndex]).y+36);*/
					/*trace(xiongmao1.x);
					trace(this.getChildAt(boxIndexs[boxIndex]).x);*/
					if (this.getChildAt(boxIndexs[boxIndex]).x==xiongmao1.x&&this.getChildAt(boxIndexs[boxIndex]).y==xiongmao1.y) {
						this.getChildAt(boxIndexs[boxIndex]).x+=36;
						boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36]=6;
						boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36+1]=3;

					}
				}
			} else if (boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36+2]==5&&boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36+1]==3) {

				boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36]=0;
				//boxList[0][(xiongmao1.y-36)/36+1][(xiongmao1.x-72)/36]=6;
				xiongmao1.x+=36;

				for (var boxIndex1_2:int=0; boxIndex1_2<3; boxIndex1_2++) {
					/*trace(xiongmao1.y);
					trace(this.getChildAt(boxIndexs[boxIndex]).y+36);*/
					/*trace(xiongmao1.x);
					trace(this.getChildAt(boxIndexs[boxIndex]).x);*/
					if (this.getChildAt(boxIndexs[boxIndex1_2]).x==xiongmao1.x&&this.getChildAt(boxIndexs[boxIndex1_2]).y==xiongmao1.y) {
						this.getChildAt(boxIndexs[boxIndex1_2]).x+=36;
						boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36]=6;
						boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36+1]=3;

					}
				}
			}
			if (boxList[0][2][5]==3&&boxList[0][2][6]==3&&boxList[0][2][7]==3) {
				this.gotoAndStop(2);
			}
			//trace(zhongdian_x);
			//trace(zhongdian_y);
			break;
		case 40 :
			//trace(boxList[0][mao_a1][mao_b1-1]);



			if (boxList[0][(xiongmao1.y-36)/36+1][(xiongmao1.x-72)/36]==0||boxList[0][(xiongmao1.y-36)/36+1][(xiongmao1.x-72)/36]==5) {
				boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36]=0;
				boxList[0][(xiongmao1.y-36)/36+1][(xiongmao1.x-72)/36]=6;
				xiongmao1.y+=36;
			} else if (boxList[0][(xiongmao1.y-36)/36+2][(xiongmao1.x-72)/36]==0&&boxList[0][(xiongmao1.y-36)/36+1][(xiongmao1.x-72)/36]==3) {

				boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36]=0;
				//boxList[0][(xiongmao1.y-36)/36+1][(xiongmao1.x-72)/36]=6;
				xiongmao1.y+=36;

				for (var boxIndex2:int=0; boxIndex2<3; boxIndex2++) {
					/*trace(xiongmao1.y);
					trace(this.getChildAt(boxIndexs[boxIndex]).y+36);*/
					/*trace(xiongmao1.x);
					trace(this.getChildAt(boxIndexs[boxIndex]).x);*/
					if (this.getChildAt(boxIndexs[boxIndex2]).x==xiongmao1.x&&this.getChildAt(boxIndexs[boxIndex2]).y==xiongmao1.y) {
						this.getChildAt(boxIndexs[boxIndex2]).y+=36;
						boxList[0][(xiongmao1.y-36)/36][(xiongmao1.x-72)/36]=6;
						boxList[0][(xiongmao1.y-36)/36+1][(xiongmao1.x-72)/36]=3;

					}
				}
			}
			break;
	}
}

 

 

 

  • Flash AS 3 熊猫推箱子源程序_第2张图片
  • 大小: 105.4 KB
  • 推箱子斯斯版.rar (72.6 KB)
  • 下载次数: 132
  • 查看图片附件

你可能感兴趣的:(Flash,Flex,游戏,编程,J#)